Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for filterResponses and isUsingResponsesToSelf #13098

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,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';

describe('SingleStatisticsComponent', () => {
Expand All @@ -24,4 +31,67 @@ describe('SingleStatisticsComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

// NEW CODE
describe('filterResponses', () => {
let feedbackResponsesService: FeedbackResponsesService;
beforeEach(() => {
feedbackResponsesService = jest.fn('FeedbackResponsesService',
['isFeedbackResponsesDisplayedOnSection']);
component = new SingleStatisticsComponent(feedbackResponsesService);
});
it('should filter responses correctly', () => {
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',
giverSection: '000',
},
{
isMissingResponse: false,
recipient: 'Someone else',
responseId: '0000',
giver: '0000',
giverTeam: '0000',
giverSection: '000',
},
];

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();

// Check if responsesToUse is filtered correctly
expect(component.responsesToUse).toEqual([
{ isMissingResponse: false, recipient: 'You' },
{ isMissingResponse: false, recipient: 'Someone else' },
]);
});
});
});
Loading