From 8537b09c6bb3f1151de3a3ff531257aae3fa5f02 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 18:43:25 -0400 Subject: [PATCH 1/7] Added unit tests for filterResponses and isUsingResponsesToSelf --- .../single-statistics.component.spec.ts | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index f369a88b914..b70b0821d5b 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -6,7 +6,8 @@ import { QuestionStatisticsModule } from '../../question-types/question-statisti describe('SingleStatisticsComponent', () => { let component: SingleStatisticsComponent; let fixture: ComponentFixture; - + + // beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [SingleStatisticsComponent], @@ -24,4 +25,59 @@ describe('SingleStatisticsComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + // NEW CODE + describe('filterResponses', () => { + let feedbackResponsesService: FeedbackResponsesService; + beforeEach(() => { + feedbackResponsesService = jasmine.createSpyObj('FeedbackResponsesService', ['isFeedbackResponsesDisplayedOnSection']); + + component = new SingleStatisticsComponent(feedbackResponsesService); + }); + it('should filter responses correctly', () => { + // Set up initial responses + component.responses = [ + { isMissingResponse: true, recipient: 'You' }, + { isMissingResponse: false, recipient: 'You' }, + { isMissingResponse: true, recipient: 'Someone else' }, + { isMissingResponse: false, recipient: 'Someone else' }, + ]; + component.question = { questionType: FeedbackQuestionType.CONSTSUM }; + component.section = 'example section'; + component.sectionType = InstructorSessionResultSectionType.EITHER; + + // Mock the feedbackResponsesService + feedbackResponsesService.isFeedbackResponsesDisplayedOnSection.and.returnValue(true); + + // Call the filterResponses method + component.ngOnInit(); + component.filterResponses(); + + // Check if responsesToUse is filtered correctly + expect(component.responsesToUse).toEqual([ + { isMissingResponse: false, recipient: 'You' }, + { isMissingResponse: false, recipient: 'Someone else' }, + ]); + }); + }); + + describe('isUsingResponsesToSelf', () => { + it('should return true when isStudent is true and questionType is NUMSCALE', () => { + component.isStudent = true; + component.question = { questionType: FeedbackQuestionType.NUMSCALE }; + + const result = component.isUsingResponsesToSelf(); + + expect(result).toBe(true); + }); + + it('should return false when isStudent is true and questionType is not NUMSCALE', () => { + component.isStudent = true; + component.question = { questionType: FeedbackQuestionType.CONSTSUM }; + + const result = component.isUsingResponsesToSelf(); + + expect(result).toBe(false); + }); + }); }); From 1e44c29e9b6661d61d70abf97a3a44b12377e570 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 19:51:08 -0400 Subject: [PATCH 2/7] fixed lint errors in formatting --- .../single-statistics.component.spec.ts | 50 ++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index b70b0821d5b..b558ea974f2 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -1,13 +1,23 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { SingleStatisticsComponent } from './single-statistics.component'; +import { FeedbackResponsesService } from '../../../../services/feedback-responses.service'; import { QuestionStatisticsModule } from '../../question-types/question-statistics/question-statistics.module'; +import { + FeedbackParticipantType, + FeedbackQuestionDetails, + FeedbackQuestionType, + ResponseOutput, +} from '../../../../types/api-output'; + +import { + InstructorSessionResultSectionType, +} from '../../../pages-instructor/instructor-session-result-page/instructor-session-result-section-type.enum'; describe('SingleStatisticsComponent', () => { let component: SingleStatisticsComponent; let fixture: ComponentFixture; - - // + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [SingleStatisticsComponent], @@ -30,17 +40,22 @@ describe('SingleStatisticsComponent', () => { describe('filterResponses', () => { let feedbackResponsesService: FeedbackResponsesService; beforeEach(() => { - feedbackResponsesService = jasmine.createSpyObj('FeedbackResponsesService', ['isFeedbackResponsesDisplayedOnSection']); + feedbackResponsesService = jest.fn('FeedbackResponsesService', + ['isFeedbackResponsesDisplayedOnSection']); component = new SingleStatisticsComponent(feedbackResponsesService); }); it('should filter responses correctly', () => { // Set up initial responses component.responses = [ - { isMissingResponse: true, recipient: 'You' }, - { isMissingResponse: false, recipient: 'You' }, - { isMissingResponse: true, recipient: 'Someone else' }, - { isMissingResponse: false, recipient: 'Someone else' }, + { isMissingResponse: true, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', + giverSection: '000' }, + { isMissingResponse: false, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', + giverSection: '000' }, + { isMissingResponse: true, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', + giverSection: '000'}, + { isMissingResponse: false, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', + giverSection: '000'}, ]; component.question = { questionType: FeedbackQuestionType.CONSTSUM }; component.section = 'example section'; @@ -51,7 +66,6 @@ describe('SingleStatisticsComponent', () => { // Call the filterResponses method component.ngOnInit(); - component.filterResponses(); // Check if responsesToUse is filtered correctly expect(component.responsesToUse).toEqual([ @@ -60,24 +74,4 @@ describe('SingleStatisticsComponent', () => { ]); }); }); - - describe('isUsingResponsesToSelf', () => { - it('should return true when isStudent is true and questionType is NUMSCALE', () => { - component.isStudent = true; - component.question = { questionType: FeedbackQuestionType.NUMSCALE }; - - const result = component.isUsingResponsesToSelf(); - - expect(result).toBe(true); - }); - - it('should return false when isStudent is true and questionType is not NUMSCALE', () => { - component.isStudent = true; - component.question = { questionType: FeedbackQuestionType.CONSTSUM }; - - const result = component.isUsingResponsesToSelf(); - - expect(result).toBe(false); - }); - }); }); From d603611222580e3e1af0b89b3a3375d533914791 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 20:09:23 -0400 Subject: [PATCH 3/7] fixed lint errors in formatting --- .../single-statistics.component.spec.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index b558ea974f2..63e9f0e8f8f 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -2,17 +2,14 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { SingleStatisticsComponent } from './single-statistics.component'; import { FeedbackResponsesService } from '../../../../services/feedback-responses.service'; +import { + InstructorSessionResultSectionType, +} from '../../../pages-instructor/instructor-session-result-page/instructor-session-result-section-type.enum'; import { QuestionStatisticsModule } from '../../question-types/question-statistics/question-statistics.module'; import { - FeedbackParticipantType, - FeedbackQuestionDetails, FeedbackQuestionType, - ResponseOutput, } from '../../../../types/api-output'; -import { - InstructorSessionResultSectionType, -} from '../../../pages-instructor/instructor-session-result-page/instructor-session-result-section-type.enum'; describe('SingleStatisticsComponent', () => { let component: SingleStatisticsComponent; @@ -42,22 +39,26 @@ describe('SingleStatisticsComponent', () => { beforeEach(() => { feedbackResponsesService = jest.fn('FeedbackResponsesService', ['isFeedbackResponsesDisplayedOnSection']); - component = new SingleStatisticsComponent(feedbackResponsesService); }); it('should filter responses correctly', () => { - // Set up initial responses component.responses = [ - { isMissingResponse: true, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' }, - { isMissingResponse: false, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' }, - { isMissingResponse: true, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', + { + isMissingResponse: true, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', + giverSection: '000'}, + { + isMissingResponse: false, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', + giverSection: '000'}, + { + isMissingResponse: true, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', giverSection: '000'}, - { isMissingResponse: false, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', + { + isMissingResponse: false, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', giverSection: '000'}, ]; - component.question = { questionType: FeedbackQuestionType.CONSTSUM }; + + component.question = {questionType: FeedbackQuestionType.CONSTSUM}; + component.section = 'example section'; component.sectionType = InstructorSessionResultSectionType.EITHER; @@ -69,8 +70,8 @@ describe('SingleStatisticsComponent', () => { // Check if responsesToUse is filtered correctly expect(component.responsesToUse).toEqual([ - { isMissingResponse: false, recipient: 'You' }, - { isMissingResponse: false, recipient: 'Someone else' }, + {isMissingResponse: false, recipient: 'You'}, + {isMissingResponse: false, recipient: 'Someone else'}, ]); }); }); From bba00642ac6b378f97b935d714365ca37a6e2b44 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 20:22:34 -0400 Subject: [PATCH 4/7] fixed lint errors in formatting --- .../single-statistics.component.spec.ts | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index 63e9f0e8f8f..4b7c42fb0e0 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -2,14 +2,13 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { SingleStatisticsComponent } from './single-statistics.component'; import { FeedbackResponsesService } from '../../../../services/feedback-responses.service'; +import { + FeedbackQuestionType, +} from '../../../../types/api-output'; import { InstructorSessionResultSectionType, } from '../../../pages-instructor/instructor-session-result-page/instructor-session-result-section-type.enum'; import { QuestionStatisticsModule } from '../../question-types/question-statistics/question-statistics.module'; -import { - FeedbackQuestionType, -} from '../../../../types/api-output'; - describe('SingleStatisticsComponent', () => { let component: SingleStatisticsComponent; @@ -37,7 +36,7 @@ describe('SingleStatisticsComponent', () => { describe('filterResponses', () => { let feedbackResponsesService: FeedbackResponsesService; beforeEach(() => { - feedbackResponsesService = jest.fn('FeedbackResponsesService', + feedbackResponsesService = jest.fn('FeedbackResponsesService', ['isFeedbackResponsesDisplayedOnSection']); component = new SingleStatisticsComponent(feedbackResponsesService); }); @@ -45,19 +44,23 @@ describe('SingleStatisticsComponent', () => { component.responses = [ { isMissingResponse: true, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000'}, + giverSection: '000' + }, { isMissingResponse: false, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000'}, + giverSection: '000' + }, { isMissingResponse: true, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000'}, + giverSection: '000' + }, { isMissingResponse: false, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000'}, + giverSection: '000' + }, ]; - component.question = {questionType: FeedbackQuestionType.CONSTSUM}; + component.question = { questionType: FeedbackQuestionType.CONSTSUM }; component.section = 'example section'; component.sectionType = InstructorSessionResultSectionType.EITHER; @@ -70,8 +73,8 @@ describe('SingleStatisticsComponent', () => { // Check if responsesToUse is filtered correctly expect(component.responsesToUse).toEqual([ - {isMissingResponse: false, recipient: 'You'}, - {isMissingResponse: false, recipient: 'Someone else'}, + { isMissingResponse: false, recipient: 'You' }, + { isMissingResponse: false, recipient: 'Someone else' }, ]); }); }); From a7186a2dce718897d86a6eead5581b8a54ef65c7 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 20:40:04 -0400 Subject: [PATCH 5/7] fixed lint errors in formatting --- .../single-statistics.component.spec.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index 4b7c42fb0e0..fcca5bd25cd 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -43,20 +43,35 @@ describe('SingleStatisticsComponent', () => { it('should filter responses correctly', () => { component.responses = [ { - isMissingResponse: true, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' + isMissingResponse: true, + recipient: 'You', + responseId: '0000', + giver: '0000', + giverTeam: '0000', + giverSection: '000' }, { - isMissingResponse: false, recipient: 'You', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' + isMissingResponse: false, + recipient: 'You', + responseId: '0000', + giver: '0000', + giverTeam: '0000', + giverSection: '000' }, { - isMissingResponse: true, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' + isMissingResponse: true, + recipient: 'Someone else', + responseId: '0000', giver: '0000', + giverTeam: '0000', + giverSection: '000' }, { - isMissingResponse: false, recipient: 'Someone else', responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' + isMissingResponse: false, + recipient: 'Someone else', + responseId: '0000', + giver: '0000', + giverTeam: '0000', + giverSection: '000' }, ]; From c8ac80f5f48609eac51afd859e693f35533324b5 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 20:49:32 -0400 Subject: [PATCH 6/7] fixed lint errors in formatting --- .../single-statistics.component.spec.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index fcca5bd25cd..65f751ed932 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -43,35 +43,35 @@ describe('SingleStatisticsComponent', () => { it('should filter responses correctly', () => { component.responses = [ { - isMissingResponse: true, - recipient: 'You', - responseId: '0000', - giver: '0000', + isMissingResponse: true, + recipient: 'You', + responseId: '0000', + giver: '0000', giverTeam: '0000', - giverSection: '000' + giverSection: '000', }, { - isMissingResponse: false, - recipient: 'You', - responseId: '0000', - giver: '0000', + isMissingResponse: false, + recipient: 'You', + responseId: '0000', + giver: '0000', giverTeam: '0000', - giverSection: '000' + giverSection: '000', }, { - isMissingResponse: true, - recipient: 'Someone else', - responseId: '0000', giver: '0000', + isMissingResponse: true, + recipient: 'Someone else', + responseId: '0000', giver: '0000', giverTeam: '0000', - giverSection: '000' + giverSection: '000', }, { - isMissingResponse: false, - recipient: 'Someone else', - responseId: '0000', - giver: '0000', + isMissingResponse: false, + recipient: 'Someone else', + responseId: '0000', + giver: '0000', giverTeam: '0000', - giverSection: '000' + giverSection: '000', }, ]; From d32f8f8749da0389053c94c28949ba2351af48e3 Mon Sep 17 00:00:00 2001 From: Hermela Berehan Benyam Date: Fri, 26 Apr 2024 20:56:00 -0400 Subject: [PATCH 7/7] fixed lint errors in formatting --- .../single-statistics/single-statistics.component.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts index 65f751ed932..2694ac695a7 100644 --- a/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts +++ b/src/web/app/components/question-responses/single-statistics/single-statistics.component.spec.ts @@ -61,7 +61,8 @@ describe('SingleStatisticsComponent', () => { { isMissingResponse: true, recipient: 'Someone else', - responseId: '0000', giver: '0000', + responseId: '0000', + giver: '0000', giverTeam: '0000', giverSection: '000', },