-
-
Notifications
You must be signed in to change notification settings - Fork 332
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 test to account-dialog.component #2254
Conversation
This is my first open source contribution, and I'm still pretty new to testing with Angular. This is a pretty simple first test I implemented, kind of just want to see how the process of getting a PR approved goes and see where I could improve. |
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.
Hey, thanks for the changes!
Testing angular components (how the UI elements interact) isn't always easy/straighforward in my experience. However in Altair, we have a component testing library that builds on top of angular testing APIs and tries to make the testing process a bit easier. As much as possible, we should be using this API (in combination with jest assertions of course) instead of the default angular one.
Note: this library only applies when testing UI components. For all other things like business logic, services, pipes, etc. you should be able to test with simple jest
For testing the openBillingPage()
, you'd want to jest.mock
the apiClient
and then check that the apiClient.getBillingUrl()
has been called
jest.spyOn(component.handleLoginChange, 'emit'); | ||
|
||
component.submitLogin(); | ||
|
||
expect(component.handleLoginChange.emit).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.
instead of using jest.spyOn
, we could trigger the click event on the submit button (or submit event on the form) and check that the handleLoginChange
event was emitted. For example,
altair/packages/altair-app/src/app/components/query-collections/query-collections.component.spec.ts
Lines 206 to 222 in 00353c9
wrapper.setProps({ | |
collections: [ | |
{ | |
id: 1, | |
title: 'Collection 1', | |
queries: [] | |
}, | |
], | |
}); | |
await wrapper.nextTick(); | |
const sortOption = wrapper.find('nz-dropdown-menu li'); | |
sortOption.emit('click'); | |
expect(wrapper.emitted('sortCollectionsChange')).toBeTruthy(); |
…e handleLoginChange event was emitted.
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.
Looking good!
Fixes
Part of #1717
Checks
yarn test-build
Changes proposed in this pull request:
This PR adds a test around the functionality of account-dialog.component: