Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions modules/ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
selectIsOpenStartTestrun,
selectIsOpenWaitSnackBar,
selectMenuOpened,
selectReports,
selectStatus,
selectSystemStatus,
} from './store/selectors';
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('AppComponent', () => {
'testrunInProgress',
'fetchProfiles',
'fetchCertificates',
'getHistory',
]);

mockService.fetchCertificates.and.returnValue(of([]));
Expand Down Expand Up @@ -159,6 +161,7 @@ describe('AppComponent', () => {
{ selector: selectSystemStatus, value: null },
{ selector: selectIsOpenStartTestrun, value: false },
{ selector: selectIsOpenWaitSnackBar, value: false },
{ selector: selectReports, value: [] },
],
}),
{ provide: FocusManagerService, useValue: mockFocusManagerService },
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class AppComponent {
this.appStore.getDevices();
this.appStore.getRiskProfiles();
this.appStore.getSystemStatus();
this.appStore.getReports();
this.matIconRegistry.addSvgIcon(
'devices',
this.domSanitizer.bypassSecurityTrustResourceUrl(DEVICES_LOGO_URL)
Expand Down
9 changes: 9 additions & 0 deletions modules/ui/src/app/app.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { TestRunService } from './services/test-run.service';
import SpyObj = jasmine.SpyObj;
import { device } from './mocks/device.mock';
import {
fetchReports,
fetchRiskProfiles,
fetchSystemStatus,
setDevices,
Expand Down Expand Up @@ -226,5 +227,13 @@ describe('AppStore', () => {
).toHaveBeenCalled();
}));
});

describe('getReports', () => {
it('should dispatch fetchReports', () => {
appStore.getReports();

expect(store.dispatch).toHaveBeenCalledWith(fetchReports());
});
});
});
});
9 changes: 9 additions & 0 deletions modules/ui/src/app/app.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
setIsOpenStartTestrun,
fetchSystemStatus,
fetchRiskProfiles,
fetchReports,
} from './store/actions';
import { TestrunStatus } from './model/testrun-status';
import { SettingMissedError, SystemInterfaces } from './model/setting';
Expand Down Expand Up @@ -150,6 +151,14 @@ export class AppStore extends ComponentStore<AppComponentState> {
);
});

getReports = this.effect(trigger$ => {
return trigger$.pipe(
tap(() => {
this.store.dispatch(fetchReports());
})
);
});

constructor(
private store: Store<AppState>,
private testRunService: TestRunService,
Expand Down
3 changes: 0 additions & 3 deletions modules/ui/src/app/mocks/reports.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export const HISTORY_AFTER_REMOVE = [
report: 'https://api.testrun.io/report.pdf',
started: '2023-06-23T10:11:00.123Z',
finished: '2023-06-23T10:17:10.123Z',
deviceFirmware: '1.2.2',
deviceInfo: 'Delta 03-DIN-SRC',
duration: '06m 10s',
},
];

Expand Down
2 changes: 1 addition & 1 deletion modules/ui/src/app/mocks/testrun.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const PROGRESS_DATA_RESPONSE = (
status: string,
finished: string | null,
tests: TestsData | IResult[],
report?: string
report: string = ''
) => {
return {
status,
Expand Down
15 changes: 14 additions & 1 deletion modules/ui/src/app/model/testrun-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface TestrunStatus {
started: string | null;
finished: string | null;
tests?: TestsResponse;
report?: string;
report: string;
}

export interface HistoryTestrun extends TestrunStatus {
Expand Down Expand Up @@ -85,6 +85,19 @@ export interface StatusResultClassName {
grey: boolean;
}

export const IDLE_STATUS = {
status: StatusOfTestrun.Idle,
device: {} as IDevice,
started: null,
finished: null,
report: '',
mac_addr: '',
tests: {
total: 0,
results: [],
},
} as TestrunStatus;

export type TestrunStatusKey = keyof typeof StatusOfTestrun;
export type TestrunStatusValue = (typeof StatusOfTestrun)[TestrunStatusKey];
export type TestResultKey = keyof typeof StatusOfTestResult;
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/src/app/pages/reports/reports-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ReportsComponent } from './reportscomponent';
import { ReportsComponent } from './reports.component';

const routes: Routes = [{ path: '', component: ReportsComponent }];

Expand Down
8 changes: 1 addition & 7 deletions modules/ui/src/app/pages/reports/reports.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';

import { ReportsComponent } from './reportscomponent';
import { ReportsComponent } from './reports.component';
import { TestRunService } from '../../services/test-run.service';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ReportsModule } from './reports.module';
Expand Down Expand Up @@ -112,12 +112,6 @@ describe('ReportsComponent', () => {
});

describe('ngOnInit', () => {
it('should set dataSource data', () => {
component.ngOnInit();

expect(mockReportsStore.getHistory).toHaveBeenCalled();
});

it('should update sort', fakeAsync(() => {
const sort = new MatSort();
component.sort = sort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class ReportsComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
this.store.getHistory();
this.store.updateSort(this.sort);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/ui/src/app/pages/reports/reports.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { NgModule } from '@angular/core';
import { CommonModule, DatePipe } from '@angular/common';
import { ReportsComponent } from './reportscomponent';
import { ReportsComponent } from './reports.component';
import { ReportsRoutingModule } from './reports-routing.module';
import { MatTableModule } from '@angular/material/table';
import { MatIconModule } from '@angular/material/icon';
Expand Down
82 changes: 37 additions & 45 deletions modules/ui/src/app/pages/reports/reports.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import { TestRunService } from '../../services/test-run.service';
import SpyObj = jasmine.SpyObj;
import { TestBed } from '@angular/core/testing';
import { skip, take } from 'rxjs';
import { throwError } from 'rxjs/internal/observable/throwError';
import { of } from 'rxjs/internal/observable/of';
import { DATA_SOURCE_INITIAL_VALUE, ReportsStore } from './reports.store';
import { ReportsStore } from './reports.store';
import {
EMPTY_FILTERS,
FILTERS,
Expand All @@ -29,31 +28,39 @@ import {
HISTORY_AFTER_REMOVE,
} from '../../mocks/reports.mock';
import { DatePipe } from '@angular/common';
import { HttpErrorResponse } from '@angular/common/http';
import { MatRow } from '@angular/material/table';
import { MatSort } from '@angular/material/sort';
import { provideMockStore } from '@ngrx/store/testing';
import { selectRiskProfiles } from '../../store/selectors';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { selectReports, selectRiskProfiles } from '../../store/selectors';
import { AppState } from '../../store/state';
import { setReports } from '../../store/actions';

describe('ReportsStore', () => {
let reportsStore: ReportsStore;
let mockService: SpyObj<TestRunService>;
let store: MockStore<AppState>;

beforeEach(() => {
mockService = jasmine.createSpyObj(['getHistory', 'deleteReport']);
mockService = jasmine.createSpyObj(['deleteReport']);

TestBed.configureTestingModule({
providers: [
ReportsStore,
{ provide: TestRunService, useValue: mockService },
provideMockStore({
selectors: [{ selector: selectRiskProfiles, value: [] }],
selectors: [
{ selector: selectRiskProfiles, value: [] },
{ selector: selectReports, value: [] },
],
}),
DatePipe,
],
});

reportsStore = TestBed.inject(ReportsStore);
store = TestBed.inject(MockStore);

spyOn(store, 'dispatch').and.callFake(() => {});
});

it('should be created', () => {
Expand Down Expand Up @@ -110,7 +117,7 @@ describe('ReportsStore', () => {
});

it('should update dataSource', (done: DoneFn) => {
reportsStore.viewModel$.pipe(skip(2), take(1)).subscribe(store => {
reportsStore.viewModel$.pipe(skip(1), take(1)).subscribe(store => {
expect(store.dataSource.data).toEqual(FORMATTED_HISTORY);
expect(store.dataLoaded).toEqual(true);
done();
Expand All @@ -133,7 +140,7 @@ describe('ReportsStore', () => {
'report',
],
chips: ['chips'],
dataSource: DATA_SOURCE_INITIAL_VALUE,
dataSource: store.dataSource,
filterOpened: false,
activeFilter: '',
filteredValues: {
Expand All @@ -142,7 +149,7 @@ describe('ReportsStore', () => {
results: [],
dateRange: '',
},
dataLoaded: false,
dataLoaded: true,
selectedRow: null,
isFiltersEmpty: true,
profiles: [],
Expand All @@ -154,56 +161,41 @@ describe('ReportsStore', () => {

describe('effects', () => {
describe('getHistory', () => {
describe('should update store', () => {
it('with empty value if error happens', done => {
mockService.getHistory.and.returnValue(
throwError(
new HttpErrorResponse({ error: { error: 'error' }, status: 500 })
)
);

reportsStore.viewModel$.pipe(skip(1), take(1)).subscribe(store => {
expect(store.dataSource.data).toEqual([]);
done();
});
it('should update store', done => {
store.overrideSelector(selectReports, [...HISTORY]);
store.refreshState();

reportsStore.getHistory();
reportsStore.viewModel$.pipe(take(1)).subscribe(store => {
expect(store.dataSource.data).toEqual(FORMATTED_HISTORY);
done();
});

it('with value if not null', done => {
mockService.getHistory.and.returnValue(of([...HISTORY]));

reportsStore.viewModel$.pipe(skip(1), take(1)).subscribe(store => {
expect(store.dataSource.data).toEqual(FORMATTED_HISTORY);
done();
});

reportsStore.getHistory();
});
reportsStore.getHistory();
});
});

describe('deleteReport', () => {
it('should update store', done => {
mockService.deleteReport.and.returnValue(of(true));
reportsStore.setHistory([...HISTORY]);

reportsStore.viewModel$.pipe(skip(1), take(1)).subscribe(store => {
expect(store.dataSource.data).toEqual(HISTORY_AFTER_REMOVE);
done();
});
store.overrideSelector(selectReports, [...HISTORY]);
store.refreshState();

reportsStore.deleteReport({
mac_addr: '00:1e:42:35:73:c4',
started: '2023-06-22T10:11:00.123Z',
});

expect(store.dispatch).toHaveBeenCalledWith(
setReports({ reports: HISTORY_AFTER_REMOVE })
);
done();
});
});

describe('updateSort', () => {
it('should update store', done => {
const sort = new MatSort();
reportsStore.setHistory([...HISTORY]);
store.overrideSelector(selectReports, [...HISTORY]);

reportsStore.updateSort(sort);

Expand All @@ -217,7 +209,7 @@ describe('ReportsStore', () => {
describe('setFilteredValuesResults', () => {
it('should update store', done => {
const updatedFilters = { ...FILTERS, ...{ results: ['test2'] } };
reportsStore.setHistory([...HISTORY]);
store.overrideSelector(selectReports, [...HISTORY]);
reportsStore.setFilteredValues({ ...FILTERS });

reportsStore.setFilteredValuesResults(['test2']);
Expand All @@ -235,7 +227,7 @@ describe('ReportsStore', () => {
describe('setFilteredValuesDeviceInfo', () => {
it('should update store', done => {
const updatedFilters = { ...FILTERS, ...{ deviceInfo: 'test2' } };
reportsStore.setHistory([...HISTORY]);
store.overrideSelector(selectReports, [...HISTORY]);
reportsStore.setFilteredValues({ ...FILTERS });

reportsStore.setFilteredValuesDeviceInfo('test2');
Expand All @@ -253,7 +245,7 @@ describe('ReportsStore', () => {
describe('setFilteredValuesDeviceFirmware', () => {
it('should update store', done => {
const updatedFilters = { ...FILTERS, ...{ deviceFirmware: 'test2' } };
reportsStore.setHistory([...HISTORY]);
store.overrideSelector(selectReports, [...HISTORY]);
reportsStore.setFilteredValues({ ...FILTERS });

reportsStore.setFilteredValuesDeviceFirmware('test2');
Expand All @@ -271,7 +263,7 @@ describe('ReportsStore', () => {
describe('setFilteredValuesDateRange', () => {
it('should update store', done => {
const updatedFilters = { ...FILTERS, ...{ dateRange: 'test2' } };
reportsStore.setHistory([...HISTORY]);
store.overrideSelector(selectReports, [...HISTORY]);
reportsStore.setFilteredValues({ ...FILTERS });

reportsStore.setFilteredValuesDateRange('test2');
Expand All @@ -289,7 +281,7 @@ describe('ReportsStore', () => {
describe('setFilteredValues', () => {
it('should update store', done => {
const updatedFilters = { ...EMPTY_FILTERS };
reportsStore.setHistory([...HISTORY]);
store.overrideSelector(selectReports, [...HISTORY]);
reportsStore.setFilteredValues({ ...FILTERS });

reportsStore.setFilteredValues(updatedFilters);
Expand Down
Loading