Skip to content

Commit

Permalink
refactor: changed the way the ratings are presented
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreGamito1 committed Jul 13, 2024
1 parent b056251 commit 6b6bbaa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
12 changes: 10 additions & 2 deletions frontend/src/views/member/InstitutionActivityEnrollmentsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ export default class InstitutionActivityEnrollmentsView extends Vue {
) {
return '';
}
return `${participation.memberReview}\nRating: ${participation.memberRating}/5`;
const stars = this.convertToStars(participation.memberRating);
return `${participation.memberReview}\nRating: ${stars}`;
}
getVolunteerReview(enrollment: Enrollment): string {
let activityId = enrollment.activityId;
Expand All @@ -377,7 +378,14 @@ export default class InstitutionActivityEnrollmentsView extends Vue {
) {
return '';
}
return `${participation.volunteerReview}\nRating: ${participation.volunteerRating}/5`;
const stars = this.convertToStars(participation.volunteerRating);
return `${participation.volunteerReview}\nRating: ${stars}`;
}
convertToStars(rating: number): string {
const fullStars = ''.repeat(Math.floor(rating));
const emptyStars = ''.repeat(Math.floor(5 - rating));
return `${fullStars}${emptyStars} ${rating}/5`;
}
async getActivities() {
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/views/volunteer/VolunteerEnrollmentsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ export default class VolunteerEnrollmentsView extends Vue {
) {
return '';
}
return `${participation.memberReview}\nRating: ${participation.memberRating}/5`;
const stars = this.convertToStars(participation.memberRating);
return `${participation.memberReview}\nRating: ${stars}`;
}
getVolunteerReview(activity: Activity): string {
const participation = this.participations.find(
Expand All @@ -313,9 +314,19 @@ export default class VolunteerEnrollmentsView extends Vue {
) {
return '';
}
return `${participation.volunteerReview}\nRating: ${participation.volunteerRating}/5`;
const stars = this.convertToStars(participation.volunteerRating);
return `${participation.volunteerReview}\nRating: ${stars}`;
}
convertToStars(rating: number): string {
const fullStars = ''.repeat(Math.floor(rating));
const emptyStars = ''.repeat(Math.floor(5 - rating));
return `${fullStars}${emptyStars} ${rating}/5`;
}
async deleteEnrollmentForActivity(activity: Activity) {
const index = this.enrollments.findIndex(
(e: Enrollment) => e.activityId == activity.id,
Expand Down
37 changes: 28 additions & 9 deletions frontend/tests/e2e/specs/participation/participation.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ describe('Participation', () => {
.children()
.eq(2)
.invoke('text')
.should('equal','The volunteer did an okay job\nRating: 3/5');
.should('include', 'The volunteer did an okay job')
.and('include', 'Rating: ')
.and('match', /{3}{2} 3\/5/);



// open edit participation dialog
Expand All @@ -160,9 +163,12 @@ describe('Participation', () => {
cy.get('[data-cy="activityEnrollmentsTable"] tbody tr')
.eq(0)
.children()
.eq(2)
.eq(2) // Assuming this is the correct index for the rating column
.invoke('text')
.should('equal','The volunteer did a good job\nRating: 5/5');
.should('include', 'The volunteer did a good job')
.and('include', 'Rating: ')
.and('match', /{5} 5\/5/);


// verify participation status
cy.get('[data-cy="activityEnrollmentsTable"] tbody tr')
Expand Down Expand Up @@ -197,17 +203,23 @@ describe('Participation', () => {
cy.get('[data-cy="volunteerEnrollmentsTable"] tbody tr')
.eq(0)
.children()
.eq(6)
.eq(6) // Assuming this is the correct index for the rating column
.invoke('text')
.should('equal','The volunteer did a good job\nRating: 5/5');
.should('include', 'The volunteer did a good job')
.and('include', 'Rating: ')
.and('match', /{5} 5\/5/);


// Verify the member review
cy.get('[data-cy="volunteerEnrollmentsTable"] tbody tr')
.eq(0)
.children()
.eq(7)
.invoke('text')
.should('equal','The activity was well organized\nRating: 3/5');
.should('include', 'The activity was well organized')
.and('include', 'Rating: ')
.and('match', /{3}{2} 3\/5/);


cy.logout();

Expand All @@ -234,20 +246,27 @@ describe('Participation', () => {
cy.wait('@enrollments');

// Check if rating was updated
// Update the assertion to match the new format with stars
cy.get('[data-cy="activityEnrollmentsTable"] tbody tr')
.eq(0)
.children()
.eq(2)
.eq(2) // Assuming this is the correct index for the rating column
.invoke('text')
.should('equal','The volunteer did a good job\nRating: 5/5');
.should('include', 'The volunteer did a good job')
.and('include', 'Rating: ')
.and('match', /{5} 5\/5/);


// Verify the member review
cy.get('[data-cy="activityEnrollmentsTable"] tbody tr')
.eq(0)
.children()
.eq(3)
.invoke('text')
.should('equal','The activity was well organized\nRating: 3/5');
.should('include', 'The activity was well organized')
.and('include', 'Rating: ')
.and('match', /{3}{2} 3\/5/);


cy.logout();

Expand Down

0 comments on commit 6b6bbaa

Please sign in to comment.