-
Notifications
You must be signed in to change notification settings - Fork 13
test(dashboard): use title attribute to find expand/collapse button #1342
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
base: main
Are you sure you want to change the base?
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -176,10 +176,10 @@ describe('SiDashboardCardComponent', () => { | |||||
| it('expand and restore on click', () => { | ||||||
| component.enableExpandInteraction = true; | ||||||
| fixture.detectChanges(); | ||||||
| (element.querySelector('si-content-action-bar .dropdown-item') as HTMLElement).click(); | ||||||
| element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')?.click(); | ||||||
| fixture.detectChanges(); | ||||||
| expect(component.card().isExpanded()).toBeTrue(); | ||||||
| (element.querySelector('si-content-action-bar .dropdown-item') as HTMLElement).click(); | ||||||
| element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')?.click(); | ||||||
|
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. For consistency and improved test clarity, please use the non-null assertion operator (
Suggested change
|
||||||
| fixture.detectChanges(); | ||||||
| expect(component.card().isExpanded()).toBeFalse(); | ||||||
| }); | ||||||
|
|
@@ -189,10 +189,10 @@ describe('SiDashboardCardComponent', () => { | |||||
| component.primaryActions = [{ title: 'Action' }]; | ||||||
| fixture.detectChanges(); | ||||||
| // Second element in content action bar is our expand actions | ||||||
| (element.querySelectorAll('si-content-action-bar .dropdown-item')[1] as HTMLElement).click(); | ||||||
| element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')?.click(); | ||||||
|
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. For consistency and improved test clarity, please use the non-null assertion operator (
Suggested change
|
||||||
| fixture.detectChanges(); | ||||||
| expect(component.card().isExpanded()).toBeTrue(); | ||||||
| (element.querySelectorAll('si-content-action-bar .dropdown-item')[1] as HTMLElement).click(); | ||||||
| element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')?.click(); | ||||||
|
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. For consistency and improved test clarity, please use the non-null assertion operator (
Suggested change
|
||||||
| fixture.detectChanges(); | ||||||
| expect(component.card().isExpanded()).toBeFalse(); | ||||||
| }); | ||||||
|
|
@@ -201,10 +201,10 @@ describe('SiDashboardCardComponent', () => { | |||||
| component.enableExpandInteraction = true; | ||||||
| component.secondaryActions = [{ title: 'Action' }]; | ||||||
| fixture.detectChanges(); | ||||||
| (element.querySelector('si-content-action-bar .dropdown-item') as HTMLElement).click(); | ||||||
| element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')?.click(); | ||||||
|
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. For consistency and improved test clarity, please use the non-null assertion operator (
Suggested change
|
||||||
| fixture.detectChanges(); | ||||||
| expect(component.card().isExpanded()).toBeTrue(); | ||||||
| (element.querySelector('si-content-action-bar .dropdown-item') as HTMLElement).click(); | ||||||
| element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')?.click(); | ||||||
|
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. For consistency and improved test clarity, please use the non-null assertion operator (
Suggested change
|
||||||
| fixture.detectChanges(); | ||||||
| expect(component.card().isExpanded()).toBeFalse(); | ||||||
| }); | ||||||
|
|
||||||
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.
While using optional chaining (
?.) prevents a null pointer exception if the element is not found, in a test it's generally better to fail explicitly. If the element isn't found, the click is silently skipped, and the test will fail on a later assertion, which can be misleading. Using a non-null assertion (!) will cause the test to fail immediately with a clearer error if the element is not found. This makes debugging easier.