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

[#10920] Add snapshot tests for admin search page #10949

Merged

Conversation

jianhandev
Copy link
Contributor

@jianhandev jianhandev commented Feb 7, 2021

Part of #10920

Outline of solution:

  • Added snapshot tests for AdminSearchPageComponent
  • Added positive and negative tests for openCourseJoinEmail and openFeedbackSessionReminderEmail

@jianhandev jianhandev changed the title [#10920] Add snapshot testing for admin search page [#10920] Add snapshot tests for admin search page Feb 7, 2021
@rrtheonlyone rrtheonlyone added the s.ToReview The PR is waiting for review(s) label Feb 7, 2021
@Derek-Hardy Derek-Hardy self-assigned this Feb 8, 2021
@Derek-Hardy Derek-Hardy added s.Ongoing The PR is being worked on by the author(s) and removed s.ToReview The PR is waiting for review(s) labels Feb 13, 2021
@jianhandev jianhandev closed this Feb 28, 2021
@jianhandev jianhandev reopened this Feb 28, 2021
Comment on lines 644 to 655
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();
Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

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/

Copy link
Contributor Author

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 👍

@Derek-Hardy Derek-Hardy added s.ToReview The PR is waiting for review(s) s.Ongoing The PR is being worked on by the author(s) and removed s.Ongoing The PR is being worked on by the author(s) s.ToReview The PR is waiting for review(s) labels Feb 28, 2021
@Derek-Hardy
Copy link
Contributor

Derek-Hardy commented Feb 28, 2021

@jianhandev You seem to have missed the id in html file for the send-course-join-button. Which leads to some test failures.

@jianhandev
Copy link
Contributor Author

jianhandev commented Feb 28, 2021

@jianhandev You seem to have missed the id in html file for the send-course-join-button. Which leads to some test failures.

Thanks for pointing that out! Has updated with whatever that is missing.

@Derek-Hardy Derek-Hardy added s.ToReview The PR is waiting for review(s) and removed s.Ongoing The PR is being worked on by the author(s) labels Feb 28, 2021
Copy link
Contributor

@ChooJeremy ChooJeremy left a 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.

Copy link
Contributor

@madanalogy madanalogy left a 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();
Copy link
Contributor

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?

Copy link
Contributor Author

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');
});
Copy link
Contributor

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.');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@madanalogy madanalogy added s.Ongoing The PR is being worked on by the author(s) and removed s.ToReview The PR is waiting for review(s) labels Mar 4, 2021
@jianhandev jianhandev added s.OnHold The issue/PR's validity has been put on hold pending some other event and removed s.Ongoing The PR is being worked on by the author(s) labels Mar 29, 2021
@jianhandev jianhandev force-pushed the 10920-admin-search-page-test branch from cc3b465 to e31dc1b Compare May 30, 2021 03:23

it('should generate email when send session reminder email button clicked', () => {
const studentResult: StudentAccountSearchResult = {
name: 'Jack Chan',
Copy link
Contributor

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

Copy link
Contributor Author

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) => {
Copy link
Contributor

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

Copy link
Contributor Author

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).

@jianhandev jianhandev added s.ToReview The PR is waiting for review(s) and removed s.Ongoing The PR is being worked on by the author(s) labels Jun 6, 2021
@madanalogy madanalogy requested review from rrtheonlyone and removed request for t-cheepeng and Derek-Hardy June 6, 2021 11:15
@madanalogy madanalogy added s.FinalReview The PR is ready for final review and removed s.ToReview The PR is waiting for review(s) labels Jun 6, 2021
@rrtheonlyone rrtheonlyone merged commit 476193c into TEAMMATES:master Jun 13, 2021
@madanalogy madanalogy added this to the V8.0.0 milestone Jun 14, 2021
@madanalogy madanalogy added c.Task Other non-user-facing works, e.g. refactoring, adding tests s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging and removed s.FinalReview The PR is ready for final review labels Jun 14, 2021
daongochieu2810 pushed a commit to daongochieu2810/teammates that referenced this pull request Jul 5, 2021
…#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>
@jianhandev jianhandev deleted the 10920-admin-search-page-test branch August 4, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c.Task Other non-user-facing works, e.g. refactoring, adding tests s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants