From 49e771b2525c99ceaaebb77db656d6fbf801c4dd Mon Sep 17 00:00:00 2001 From: kurilova Date: Tue, 16 Apr 2024 07:03:39 +0000 Subject: [PATCH 1/3] Fix tests --- modules/ui/src/app/app.component.spec.ts | 1 + .../device-item/device-item.component.spec.ts | 9 +++++- .../device-repository.component.spec.ts | 7 +++- .../pages/testrun/progress.component.spec.ts | 4 +++ .../app/pages/testrun/testrun.store.spec.ts | 32 +++++++++++++------ 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/modules/ui/src/app/app.component.spec.ts b/modules/ui/src/app/app.component.spec.ts index d3a778a73..c5618e86f 100644 --- a/modules/ui/src/app/app.component.spec.ts +++ b/modules/ui/src/app/app.component.spec.ts @@ -355,6 +355,7 @@ describe('AppComponent', () => { }); it('should not focus navigation button on tab press if menu button was not clicked', () => { + document.body.focus(); focusNavigation = false; const menuBtn = compiled.querySelector( '.app-toolbar-button-menu' diff --git a/modules/ui/src/app/components/device-item/device-item.component.spec.ts b/modules/ui/src/app/components/device-item/device-item.component.spec.ts index b7dd90524..9319bb0ef 100644 --- a/modules/ui/src/app/components/device-item/device-item.component.spec.ts +++ b/modules/ui/src/app/components/device-item/device-item.component.spec.ts @@ -18,6 +18,8 @@ import { Device, DeviceView } from '../../model/device'; import { DeviceItemComponent } from './device-item.component'; import { DeviceRepositoryModule } from '../../pages/devices/device-repository.module'; +import { MatIconTestingModule } from '@angular/material/icon/testing'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; describe('DeviceItemComponent', () => { let component: DeviceItemComponent; @@ -26,7 +28,12 @@ describe('DeviceItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [DeviceRepositoryModule, DeviceItemComponent], + imports: [ + DeviceRepositoryModule, + DeviceItemComponent, + MatIconTestingModule, + BrowserAnimationsModule, + ], }); fixture = TestBed.createComponent(DeviceItemComponent); component = fixture.componentInstance; diff --git a/modules/ui/src/app/pages/devices/device-repository.component.spec.ts b/modules/ui/src/app/pages/devices/device-repository.component.spec.ts index dc6279081..30c84b660 100644 --- a/modules/ui/src/app/pages/devices/device-repository.component.spec.ts +++ b/modules/ui/src/app/pages/devices/device-repository.component.spec.ts @@ -30,6 +30,7 @@ import { DeleteFormComponent } from '../../components/delete-form/delete-form.co import SpyObj = jasmine.SpyObj; import { FocusManagerService } from '../../services/focus-manager.service'; import { DevicesStore } from './devices.store'; +import { MatIconTestingModule } from '@angular/material/icon/testing'; describe('DeviceRepositoryComponent', () => { let component: DeviceRepositoryComponent; @@ -50,7 +51,11 @@ describe('DeviceRepositoryComponent', () => { mockDevicesStore.testModules = MOCK_TEST_MODULES; await TestBed.configureTestingModule({ - imports: [DeviceRepositoryModule, BrowserAnimationsModule], + imports: [ + DeviceRepositoryModule, + BrowserAnimationsModule, + MatIconTestingModule, + ], providers: [ { provide: DevicesStore, useValue: mockDevicesStore }, { provide: FocusManagerService, useValue: stateServiceMock }, diff --git a/modules/ui/src/app/pages/testrun/progress.component.spec.ts b/modules/ui/src/app/pages/testrun/progress.component.spec.ts index e373db247..7278a1f77 100644 --- a/modules/ui/src/app/pages/testrun/progress.component.spec.ts +++ b/modules/ui/src/app/pages/testrun/progress.component.spec.ts @@ -56,6 +56,7 @@ import { import { DownloadReportPdfComponent } from '../../components/download-report-pdf/download-report-pdf.component'; import { TestrunStore } from './testrun.store'; import { setTestrunStatus } from '../../store/actions'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; describe('ProgressComponent', () => { let component: ProgressComponent; @@ -70,6 +71,7 @@ describe('ProgressComponent', () => { 'isOpenStartTestrun$', 'isTestrunStarted$', 'fetchSystemStatus', + 'getTestModules', ]); const loaderServiceMock: jasmine.SpyObj = jasmine.createSpyObj( @@ -117,6 +119,7 @@ describe('ProgressComponent', () => { MatDialogModule, SpinnerComponent, DownloadReportPdfComponent, + BrowserAnimationsModule, ], }) .overrideComponent(ProgressComponent, { @@ -237,6 +240,7 @@ describe('ProgressComponent', () => { DownloadReportComponent, SpinnerComponent, DownloadReportPdfComponent, + BrowserAnimationsModule, ], }) .overrideComponent(ProgressComponent, { diff --git a/modules/ui/src/app/pages/testrun/testrun.store.spec.ts b/modules/ui/src/app/pages/testrun/testrun.store.spec.ts index 705e5a7db..53f173e41 100644 --- a/modules/ui/src/app/pages/testrun/testrun.store.spec.ts +++ b/modules/ui/src/app/pages/testrun/testrun.store.spec.ts @@ -61,7 +61,10 @@ describe('TestrunStore', () => { ); beforeEach(() => { - mockService = jasmine.createSpyObj(['stopTestrun', 'fetchSystemStatus']); + mockService = jasmine.createSpyObj('mockService', [ + 'stopTestrun', + 'fetchSystemStatus', + ]); TestBed.configureTestingModule({ providers: [ @@ -85,10 +88,6 @@ describe('TestrunStore', () => { spyOn(store, 'dispatch').and.callFake(() => {}); }); - afterEach(() => { - mockService.fetchSystemStatus.calls.reset(); - }); - it('should be created', () => { expect(testrunStore).toBeTruthy(); }); @@ -143,16 +142,20 @@ describe('TestrunStore', () => { describe('effects', () => { describe('getStatus', () => { - const status = { ...MOCK_PROGRESS_DATA_IN_PROGRESS }; beforeEach(() => { - mockService.fetchSystemStatus.and.returnValue(of(status)); + testrunStore.updateStartInterval(true); + mockService.fetchSystemStatus.and.returnValue( + of({ ...MOCK_PROGRESS_DATA_MONITORING }) + ); }); it('should dispatch action setTestrunStatus', () => { testrunStore.getStatus(); expect(store.dispatch).toHaveBeenCalledWith( - setTestrunStatus({ systemStatus: status }) + setTestrunStatus({ + systemStatus: { ...MOCK_PROGRESS_DATA_MONITORING }, + }) ); }); @@ -166,18 +169,27 @@ describe('TestrunStore', () => { }); describe('pullingSystemStatusData with available status "In Progress"', () => { + beforeEach(() => { + mockService.fetchSystemStatus.and.returnValue( + of({ ...MOCK_PROGRESS_DATA_IN_PROGRESS }) + ); + mockService.fetchSystemStatus.calls.reset(); + }); + it('should call again getSystemStatus', fakeAsync(() => { testrunStore.updateStartInterval(false); + testrunStore.updateCancelling(false); store.overrideSelector( selectSystemStatus, MOCK_PROGRESS_DATA_IN_PROGRESS ); testrunStore.getStatus(); + expect(mockService.fetchSystemStatus).toHaveBeenCalled(); - tick(7000); + tick(5000); - expect(mockService.fetchSystemStatus).toHaveBeenCalledTimes(1); + expect(mockService.fetchSystemStatus).toHaveBeenCalledTimes(2); discardPeriodicTasks(); })); }); From 5378e0bd7f77ab2775e9eae93bc6af1b788f15a7 Mon Sep 17 00:00:00 2001 From: kurilova Date: Tue, 16 Apr 2024 07:56:16 +0000 Subject: [PATCH 2/3] Update node version --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f45851445..533343870 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -76,7 +76,7 @@ jobs: - name: Install Node uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 with: - node-version: 18.13.0 + node-version: 18.18.0 - name: Install Chromium Browser run: sudo apt install chromium-browser - name: Install dependencies @@ -99,7 +99,7 @@ jobs: - name: Install Node uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 with: - node-version: 18.13.0 + node-version: 18.18.0 - name: Install dependencies run: npm install && npm ci working-directory: ./modules/ui From 9ff97a7841b230d68ca44cddb7ce64149a9b35be Mon Sep 17 00:00:00 2001 From: kurilova Date: Tue, 16 Apr 2024 08:02:18 +0000 Subject: [PATCH 3/3] Fix test --- modules/ui/src/app/app.component.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ui/src/app/app.component.spec.ts b/modules/ui/src/app/app.component.spec.ts index c5618e86f..6b5477a48 100644 --- a/modules/ui/src/app/app.component.spec.ts +++ b/modules/ui/src/app/app.component.spec.ts @@ -323,6 +323,7 @@ describe('AppComponent', () => { describe('menu button', () => { beforeEach(() => { + mockFocusManagerService.focusFirstElementInContainer.calls.reset(); store.overrideSelector(selectHasDevices, false); fixture.detectChanges(); }); @@ -355,7 +356,6 @@ describe('AppComponent', () => { }); it('should not focus navigation button on tab press if menu button was not clicked', () => { - document.body.focus(); focusNavigation = false; const menuBtn = compiled.querySelector( '.app-toolbar-button-menu' @@ -363,7 +363,9 @@ describe('AppComponent', () => { menuBtn.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab' })); - expect(document.activeElement).toBe(document.body); + expect( + mockFocusManagerService.focusFirstElementInContainer + ).not.toHaveBeenCalled(); }); });