-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[#12588] Improve test code coverage of core components #13050
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,112 @@ | |
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('sortResponsesBy', () => { | ||
it('should sort by giver team', () => { | ||
component.sortBy = SortBy.GIVER_TEAM; | ||
const responseA: ResponseOutput = { giverTeam: 'Team B' }; | ||
const responseB: ResponseOutput = { giverTeam: 'Team A' }; | ||
|
||
Check failure on line 64 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
const result = component.sortResponsesBy(component.sortBy, SortOrder.ASC)(responseA, responseB); | ||
|
||
Check failure on line 66 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
expect(result).toBeGreaterThan(0); // 'Team B' should come after 'Team A' alphabetically | ||
}); | ||
|
||
Check failure on line 69 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
it('should sort by giver name', () => { | ||
component.sortBy = SortBy.GIVER_NAME; | ||
const responseA: ResponseOutput = { giver: 'Alice' }; | ||
const responseB: ResponseOutput = { giver: 'Bob' }; | ||
|
||
Check failure on line 74 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
const result = component.sortResponsesBy(component.sortBy, SortOrder.ASC)(responseA, responseB); | ||
|
||
Check failure on line 76 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
expect(result).toBeLessThan(0); // 'Alice' should come before 'Bob' alphabetically | ||
}); | ||
|
||
Check failure on line 79 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
it('should sort by recipient team', () => { | ||
component.sortBy = SortBy.RECIPIENT_TEAM; | ||
const responseA: ResponseOutput = { recipientTeam: 'Team B' }; | ||
const responseB: ResponseOutput = { recipientTeam: 'Team A' }; | ||
|
||
Check failure on line 84 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
const result = component.sortResponsesBy(component.sortBy, SortOrder.ASC)(responseA, responseB); | ||
|
||
Check failure on line 86 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
expect(result).toBeGreaterThan(0); // 'Team B' should come after 'Team A' alphabetically | ||
}); | ||
|
||
Check failure on line 89 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
it('should sort by recipient name', () => { | ||
component.sortBy = SortBy.RECIPIENT_NAME; | ||
const responseA: ResponseOutput = { recipient: 'Alice' }; | ||
const responseB: ResponseOutput = { recipient: 'Bob' }; | ||
|
||
Check failure on line 94 in src/web/app/components/question-responses/per-question-view-responses/per-question-view-responses.component.spec.ts
|
||
const result = component.sortResponsesBy(component.sortBy, SortOrder.ASC)(responseA, responseB); | ||
|
||
expect(result).toBeLessThan(0); // 'Alice' should come before 'Bob' alphabetically | ||
}); | ||
}); | ||
|
||
|
||
it('should open modal and set currResponseToAdd when showCommentTableModel is called', () => { | ||
const selectedResponse: ResponseOutput = { /* mock response */ }; | ||
const modalResultPromise = new Promise(resolve => resolve()); | ||
const commentModalRef: NgbModalRef = { | ||
result: modalResultPromise as Promise<any>, | ||
close: jest.fn(), // Mocking close method | ||
dismiss: jest.fn() // Mocking dismiss method | ||
}; | ||
|
||
const ngbModalSpy = spyOn(component.ngbModal, 'open').and.returnValue(commentModalRef); | ||
|
||
component.showCommentTableModel(selectedResponse, 'modal'); // Call the method | ||
|
||
expect(ngbModalSpy).toHaveBeenCalledWith('modal'); // Ensure ngbModal.open was called with 'modal' | ||
expect(component.currResponseToAdd).toEqual(selectedResponse); // Ensure currResponseToAdd is set correctly | ||
|
||
// Simulate modal closing | ||
modalResultPromise.then(() => { | ||
expect(component.currResponseToAdd).toBeUndefined(); // Ensure currResponseToAdd is reset when modal is closed | ||
}); | ||
}); | ||
|
||
describe('filterResponses', () => { | ||
it('should filter out missing responses when indicateMissingResponses is false', () => { | ||
component.indicateMissingResponses = false; | ||
const responseWithMissing: ResponseOutput = { isMissingResponse: true }; | ||
const responseWithoutMissing: ResponseOutput = { isMissingResponse: false }; | ||
component.responses = [responseWithMissing, responseWithoutMissing]; | ||
|
||
component.filterResponses(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private methods cannot be called from your test you can call filterResponses() indirectly with ngOnInit() or ngOnChanges() because they both run this.filterResponses() |
||
|
||
expect(component.responsesToShow.length).toBe(1); | ||
expect(component.responsesToShow).toContain(responseWithoutMissing); | ||
}); | ||
|
||
it('should filter responses based on section', () => { | ||
component.section = 'section1'; // Set the section to filter by | ||
const responseInSection: ResponseOutput = { giverSection: 'section1' }; | ||
const responseNotInSection: ResponseOutput = { giverSection: 'section2' }; | ||
component.responses = [responseInSection, responseNotInSection]; | ||
|
||
component.filterResponses(); | ||
|
||
expect(component.responsesToShow.length).toBe(1); | ||
expect(component.responsesToShow).toContain(responseInSection); | ||
}); | ||
|
||
}); | ||
|
||
it('should skip response when shouldDisplayBasedOnSection is false', () => { | ||
const responseInSection: ResponseOutput = { giverSection: 'section1' }; | ||
const responseNotInSection: ResponseOutput = { giverSection: 'section2' }; | ||
spyOn(feedbackResponsesService, 'isFeedbackResponsesDisplayedOnSection').and.returnValues(true, false); | ||
component.section = 'section1'; // Set the section to filter by | ||
component.responses = [responseInSection, responseNotInSection]; | ||
|
||
component.filterResponses(); | ||
|
||
expect(component.responsesToShow.length).toBe(1); | ||
expect(component.responsesToShow).toContain(responseInSection); | ||
}); | ||
|
||
|
||
const commentOutput: CommentOutput = { | ||
commentGiverName: 'Jennie Kim', | ||
lastEditorName: 'Jennie Kim', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an import for NgbModelRef
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';