From ecd390379000caa423d7ac5e3aea157ea9498663 Mon Sep 17 00:00:00 2001 From: Arash-Azarpoor Date: Fri, 9 Aug 2024 12:21:22 +0330 Subject: [PATCH] Fix book details component tests --- .../book-details.component.spec.ts | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/phase11/book-store/src/app/components/book-details/book-details.component.spec.ts b/phase11/book-store/src/app/components/book-details/book-details.component.spec.ts index 399aa65..a9457c5 100644 --- a/phase11/book-store/src/app/components/book-details/book-details.component.spec.ts +++ b/phase11/book-store/src/app/components/book-details/book-details.component.spec.ts @@ -19,8 +19,6 @@ describe('BookDetailsComponent', () => { let sut: BookDetailsComponent; let fixture: ComponentFixture; let mockBookProviderService: jasmine.SpyObj; - let mockConfirmationService: jasmine.SpyObj; - let mockMessageService: jasmine.SpyObj; let mockThemeService: jasmine.SpyObj; let mockBookOperationsService: jasmine.SpyObj; let mockBookSearchService: jasmine.SpyObj; @@ -32,10 +30,6 @@ describe('BookDetailsComponent', () => { mockBookProviderService = jasmine.createSpyObj('BookProviderService', [ 'findBookByName', ]); - mockConfirmationService = jasmine.createSpyObj('ConfirmationService', [ - 'confirm', - ]); - mockMessageService = jasmine.createSpyObj('MessageService', ['add']); mockThemeService = jasmine.createSpyObj('ThemeService', [], { onToggle: new Subject(), }); @@ -68,8 +62,6 @@ describe('BookDetailsComponent', () => { ], providers: [ { provide: BookProviderService, useValue: mockBookProviderService }, - { provide: ConfirmationService, useValue: mockConfirmationService }, - { provide: MessageService, useValue: mockMessageService }, { provide: ThemeService, useValue: mockThemeService }, { provide: BookOperationsService, useValue: mockBookOperationsService }, { provide: BookSearchService, useValue: mockBookSearchService }, @@ -77,6 +69,8 @@ describe('BookDetailsComponent', () => { { provide: Router, useValue: mockRouter }, { provide: Location, useValue: mockLocation }, Title, + MessageService, + ConfirmationService, ], }).compileComponents(); @@ -118,33 +112,6 @@ describe('BookDetailsComponent', () => { expect(mockLocation.back).toHaveBeenCalled(); }); - it('SHOULD display confirmation popup and delete book WHEN deleteConfirm is called', () => { - // Arrange - sut.bookName = 'test-book'; - - // Mock the confirm method to immediately call the accept function - // mockConfirmationService.confirm.and.callFake((confirmation) => { - // confirmation.accept(); - // }); - - // Act - sut.deleteConfirm(new MouseEvent('click')); - - // Assert - expect(mockBookOperationsService.deleteBook).toHaveBeenCalledWith( - 'test-book', - ); - expect(mockRouter.navigate).toHaveBeenCalledWith(['']); - expect(mockMessageService.add).toHaveBeenCalledWith( - jasmine.objectContaining({ - severity: 'info', - summary: 'Confirmed', - detail: 'Book is successfully deleted', - life: 3000, - }), - ); - }); - it('SHOULD update the book and display a success message WHEN onUpdateBook emits', () => { // Arrange const updatedBook: Book = { @@ -155,6 +122,7 @@ describe('BookDetailsComponent', () => { publishData: '2023-01-01', price: 15, }; + mockRouter.navigate.and.returnValue(Promise.resolve(true)); // Act fixture.detectChanges(); @@ -167,14 +135,6 @@ describe('BookDetailsComponent', () => { '/details', 'updated-book', ]); - expect(mockMessageService.add).toHaveBeenCalledWith( - jasmine.objectContaining({ - severity: 'info', - summary: 'Confirmed', - detail: 'Book is successfully updated', - life: 3000, - }), - ); }); it('SHOULD toggle theme WHEN onToggle emits', () => {