Skip to content

Commit

Permalink
fix SidebarCardLargeComponent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonWehrhahn committed Jan 10, 2025
1 parent 0460f4e commit 1f86b95
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,28 @@ describe('SidebarCardLargeComponent', () => {
});

it('should navigate to the item URL on click', async () => {
const mockFn = jest.fn();
component.emitStoreAndRefresh = mockFn;
jest.spyOn(component, 'emitStoreAndRefresh');
component.itemSelected = true;
fixture.detectChanges();
const itemElement = fixture.nativeElement.querySelector('#test-sidebar-card-large');
itemElement.click();
await fixture.whenStable();
expect(mockFn).toHaveBeenCalledWith('testId');
expect(router.navigateByUrl).toHaveBeenCalled();
const navigationArray = router.navigateByUrl.mock.calls[0][0];
expect(navigationArray).toBe('./testId');
expect(component.emitStoreAndRefresh).toHaveBeenCalledWith('testId');
expect(router.navigate).toHaveBeenCalled();
const navigationArray = router.navigate.mock.calls[1][0];
expect(navigationArray).toStrictEqual(['./testId']);
});

it('should navigate to the when no item was selected before', async () => {
const mockFn = jest.fn();
component.emitStoreAndRefresh = mockFn;
jest.spyOn(component, 'emitStoreAndRefresh');
component.itemSelected = false;
fixture.detectChanges();
const itemElement = fixture.nativeElement.querySelector('#test-sidebar-card-large');
itemElement.click();
await fixture.whenStable();
expect(mockFn).toHaveBeenCalledWith('testId');
expect(router.navigateByUrl).toHaveBeenCalled();
const navigationArray = router.navigateByUrl.mock.calls[0][0];
expect(navigationArray).toBe('./testId');
expect(component.emitStoreAndRefresh).toHaveBeenCalledWith('testId');
expect(router.navigate).toHaveBeenCalled();
const navigationArray = router.navigate.mock.calls[1][0];
expect(navigationArray).toStrictEqual(['', 'testId']);
});
});

0 comments on commit 1f86b95

Please sign in to comment.