Skip to content

Commit

Permalink
fix SidebarCardSmallComponent and SidebarCardMediumComponent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonWehrhahn committed Jan 10, 2025
1 parent 620b821 commit f1a2741
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,28 @@ describe('SidebarCardMediumComponent', () => {
});

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-medium');
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-medium');
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']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,28 @@ describe('SidebarCardSmallComponent', () => {
*/

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-small');
itemElement.click();
await fixture.whenStable();
expect(mockFn).toHaveBeenCalledWith('testId');
expect(router.navigateByUrl).toHaveBeenCalled();
const navigationArray = router.navigateByUrl.mock.calls[0][0];
expect(navigationArray).toBe('../communication');
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-small');
itemElement.click();
await fixture.whenStable();
expect(mockFn).toHaveBeenCalledWith('testId');
expect(router.navigateByUrl).toHaveBeenCalled();
const navigationArray = router.navigateByUrl.mock.calls[0][0];
expect(navigationArray).toBe('./communication');
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 f1a2741

Please sign in to comment.