-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[#10920] Add snapshot tests for admin search page #10949
[#10920] Add snapshot tests for admin search page #10949
Conversation
src/web/app/pages-admin/admin-search-page/admin-search-page.component.spec.ts
Show resolved
Hide resolved
src/web/app/pages-admin/admin-search-page/admin-search-page.component.spec.ts
Show resolved
Hide resolved
27df5cf
to
56d7c65
Compare
const spyEmailGenerationService: any = spyOn(emailGenerationService, 'getCourseJoinEmail').and.callFake( | ||
(): Observable<Email> => of({ | ||
recipient: 'Jacky Chan', | ||
subject: 'Course join email', | ||
content: 'Course join email content', | ||
}), | ||
); | ||
|
||
const sendButton: any = fixture.debugElement.nativeElement.querySelector('#send-course-join-button'); | ||
sendButton.click(); | ||
|
||
expect(spyEmailGenerationService).toBeCalled(); |
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.
Technically the email object is not returned or stored in the component afterwards. So I'm wondering if I am spying on the email generation service, is it possible to retrieve the email's recipient/subject/content?
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.
True, this indeed relies window.location.href
which is not very straightforward to test...
Any suggestions? @ChooJeremy @t-cheepeng @madanalogy
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.
@jianhandev You could try to inject a window
object into the test suite using a InjectionToken
and test against that.
Some references:
https://angular.io/api/core/InjectionToken
https://jasminexie.github.io/injecting-window-in-an-angular-application/
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 the suggestion! Will seriously look into that 👍
@jianhandev You seem to have missed the |
Thanks for pointing that out! Has updated with whatever that is missing. |
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.
Tests LGTM, other than the issue mentioned on email generation service that uses window.location.href
. Good coverage.
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.
I'm not usually particular about small unintended changes being made but there's really just too many occurrences in this PR.
], | ||
providers: [AccountService, SearchService, StatusMessageService, NgbModal], | ||
}) | ||
.compileComponents(); | ||
.compileComponents(); |
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.
Any particular reason for this extra indent?
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.
I think those were auto-indented by my IDE. It did managed to pass the lint test so I thought it was fine. Nevertheless, I will double check my IDE settings again for indentation. Thanks for pointing out!
}); | ||
(args: string): void => { | ||
expect(args).toEqual('This is the error message'); | ||
}); |
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.
Similarly here
}); | ||
(args: string): void => { | ||
expect(args).toEqual('No results found.'); | ||
}); |
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.
And here
cc3b465
to
e31dc1b
Compare
e31dc1b
to
b99f27d
Compare
|
||
it('should generate email when send session reminder email button clicked', () => { | ||
const studentResult: StudentAccountSearchResult = { | ||
name: 'Jack Chan', |
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.
Could we abstract the StudentAccountSearchResult
objects in this file into a factory function of sorts, and you can populate the necessary fields as parameters. Seems to me like not many fields need to change between test cases. For example,
const initStudentSearchResult = (name, email) => {
return {
// populate data
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.
@madanalogy Thanks for the suggestion, made the changes 👍
const spyStatusMessageService: any = spyOn(statusMessageService, 'showSuccessToast').and.callFake( | ||
(args: string): void => { | ||
const spyStatusMessageService: any = spyOn(statusMessageService, 'showSuccessToast') | ||
.and.callFake((args: string) => { |
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.
Still seems like a bunch of unnecessary changes in this file
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.
The re-indentation was done because it exceeds the line limit, I double-checked my indentation settings in my IDE and seems to be correct also (I'm following what is specified in https://github.com/TEAMMATES/teammates/blob/master/docs/ide-setup.md).
…#10949) * Add frontend tests for admin search page * Add snapshots and add missing ids to admin search page send buttons * Standardize indentation * Refactor student result * Remove positive tests due to incompleteness Co-authored-by: Rahul Rajesh <rahul.rajesh.bhat@gmail.com>
Part of #10920
Outline of solution:
positive andnegative tests foropenCourseJoinEmail
andopenFeedbackSessionReminderEmail