-
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] Added unit tests for SessionEditFormComponent #12627
[#12588] Added unit tests for SessionEditFormComponent #12627
Conversation
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.
some changes,
also minTimeForSubmissionEnd, minDateForSessionVisible, minTimeForSessionVisible, maxDateForSessionVisible, maxTimeForSessionVisible, minDateForResponseVisible, minTimeForResponseVisible are currently not tested as well, do add tests for those
src/web/app/components/session-edit-form/session-edit-form.component.spec.ts
Show resolved
Hide resolved
it('should emit a cancelEditingSession event after modal confimation', async () => { | ||
jest.spyOn((component as any).simpleModalService, 'openConfirmationModal').mockReturnValue(mockModal); | ||
const cancelEditingSessionSpy = jest.spyOn(component.cancelEditingSessionEvent, 'emit'); | ||
component.cancelHandler(); | ||
await mockModal.result; | ||
expect(cancelEditingSessionSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should emit a deleteExistingSession event after modal confimation', async () => { | ||
jest.spyOn((component as any).simpleModalService, 'openConfirmationModal').mockReturnValue(mockModal); | ||
const deleteExistingSessionSpy = jest.spyOn(component.deleteExistingSessionEvent, 'emit'); | ||
component.deleteHandler(); | ||
await mockModal.result; | ||
expect(deleteExistingSessionSpy).toHaveBeenCalled(); | ||
}); |
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.
for these methods, we should be creating a modalSpy and checking if it's called with the appropriate params, you can see admin-notifications-page.component.spec.ts for an example
…nneySiu/teammates into 12588-session-edit-form-tests
Added additional tests |
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.
thanks for adding the new tests, left a few comments!
src/web/app/components/session-edit-form/session-edit-form.component.spec.ts
Show resolved
Hide resolved
import { SessionEditFormComponent } from './session-edit-form.component'; | ||
import { SessionEditFormModule } from './session-edit-form.module'; | ||
|
||
describe('SessionEditFormComponent', () => { | ||
let component: SessionEditFormComponent; | ||
let fixture: ComponentFixture<SessionEditFormComponent>; | ||
let simpleModalService: SimpleModalService; | ||
let service: DateTimeService; |
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.
nit: let's rename this dateTimeService
for better readability
component.model.submissionStartDate = date; | ||
component.model.submissionStartTime = time; | ||
const minTimeForSubmissionEnd = component.minTimeForSubmissionEnd; | ||
expect(minTimeForSubmissionEnd).toStrictEqual(time); |
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.
nit: let's just use component.minTimeForSubmissionEnd here instead of the const
component.model.submissionStartDate = date; | ||
component.model.submissionStartTime = time; | ||
const minTimeForSubmissionEnd = component.minTimeForSubmissionEnd; | ||
expect(minTimeForSubmissionEnd).toStrictEqual(oneHourBeforeNow); |
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.
same here, use component.minTimeForSubmissionEnd
directly, do make the changes for all the others below
+ 'when response visible setting is CUSTOM and submissionStartDate is before customResponseVisibleDate', () => { | ||
component.model.responseVisibleSetting = ResponseVisibleSetting.CUSTOM; | ||
component.model.submissionStartDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone)); |
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.
let's save moment().tz(component.model.timeZone)
into a const here, as unlikely as it may be, there might be a case where the date changes while the test runs and thus it might end up as different days
+ 'when response visible setting is CUSTOM and submissionStartDate is after customResponseVisibleDate', () => { | ||
component.model.responseVisibleSetting = ResponseVisibleSetting.CUSTOM; | ||
component.model.submissionStartDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone).add(1, 'days')); |
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.
same as above here
component.model.responseVisibleSetting = ResponseVisibleSetting.CUSTOM; | ||
component.model.submissionStartTime = | ||
service.getTimeInstance(moment()); | ||
component.model.customResponseVisibleTime = | ||
service.getTimeInstance(moment()); | ||
component.model.submissionStartDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone)); | ||
component.model.customResponseVisibleDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone).add(1, 'days')); |
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.
same here, let's save all the moment() calls into a const instead
component.model.submissionStartTime = | ||
service.getTimeInstance(moment()); | ||
component.model.customResponseVisibleTime = | ||
service.getTimeInstance(moment()); | ||
component.model.submissionStartDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone).add(1, 'days')); | ||
component.model.customResponseVisibleDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone)); | ||
const maxTimeForSessionVisible = component.maxTimeForSessionVisible; |
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.
same as above here
service.getDateInstance(moment().tz(component.model.timeZone)); | ||
component.model.customSessionVisibleDate = | ||
service.getDateInstance(moment().tz(component.model.timeZone)); |
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.
we should make customerSessionVisibleDate different from submissionStartDate here
service.getTimeInstance(moment().tz(component.model.timeZone)); | ||
component.model.customSessionVisibleTime = | ||
service.getTimeInstance(moment().tz(component.model.timeZone)); |
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.
same here, let's make the customSessionVisibleTime different from submissionStartTime
Ready for review |
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.
LGTM! thank you for your work on this!
Folks, This PR seems to be stalling (no activities for the past 7 days). 🐌 😢 |
1 similar comment
Folks, This PR seems to be stalling (no activities for the past 7 days). 🐌 😢 |
Folks, This PR seems to be stalling (no activities for the past 11 days). 🐌 😢 |
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.
LGTM
…MATES#12627) * Added unit tests for session-edit-form-component * Added unit tests for session-edit-form-component * added changes to sessioneditformcomponent tests * fixed indent on seesioneditformcomponent tests * moved test in sessioneditformcomponent * made changes to session edit form tests * fixed issues on session edit form component --------- Co-authored-by: Wei Qing <[email protected]>
Part of #12588
Outline of Solution
Added unit tests for the following methods in SessionEditFormComponent
triggerModelChange,
triggerSubmissionOpeningDateModelChange,
courseIdChangeHandler,
submitFormHandler,
cancelHandler,
deleteHandler,
copyHandler,
copyOthersHandler,
closeEditFormHandler