Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Choose a reason for hiding this comment

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

medium

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.

Suggested change
element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')?.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();

Choose a reason for hiding this comment

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

medium

For consistency and improved test clarity, please use the non-null assertion operator (!) here as well. This ensures the test fails explicitly if the element is not found.

Suggested change
element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')?.click();
element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')!.click();

fixture.detectChanges();
expect(component.card().isExpanded()).toBeFalse();
});
Expand All @@ -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();

Choose a reason for hiding this comment

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

medium

For consistency and improved test clarity, please use the non-null assertion operator (!) here as well. This ensures the test fails explicitly if the element is not found.

Suggested change
element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')?.click();
element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')!.click();

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();

Choose a reason for hiding this comment

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

medium

For consistency and improved test clarity, please use the non-null assertion operator (!) here as well. This ensures the test fails explicitly if the element is not found.

Suggested change
element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')?.click();
element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')!.click();

fixture.detectChanges();
expect(component.card().isExpanded()).toBeFalse();
});
Expand All @@ -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();

Choose a reason for hiding this comment

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

medium

For consistency and improved test clarity, please use the non-null assertion operator (!) here as well. This ensures the test fails explicitly if the element is not found.

Suggested change
element.querySelector<HTMLElement>('si-content-action-bar button[title="Expand"]')?.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();

Choose a reason for hiding this comment

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

medium

For consistency and improved test clarity, please use the non-null assertion operator (!) here as well. This ensures the test fails explicitly if the element is not found.

Suggested change
element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')?.click();
element.querySelector<HTMLElement>('si-content-action-bar button[title="Restore"]')!.click();

fixture.detectChanges();
expect(component.card().isExpanded()).toBeFalse();
});
Expand Down
Loading