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
42 changes: 42 additions & 0 deletions modules/ui/src/app/mocks/reports.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export const HISTORY = [
started: '2023-07-23T10:11:00.123Z',
finished: '2023-07-23T10:17:10.123Z',
},
{
mac_addr: null,
status: 'compliant',
device: {
manufacturer: 'Delta',
model: '03-DIN-SRC',
mac_addr: '01:02:03:04:05:08',
firmware: '1.2.2',
},
report: 'https://api.testrun.io/report.pdf',
started: '2023-06-23T10:11:00.123Z',
finished: '2023-06-23T10:17:10.123Z',
},
] as TestrunStatus[];

export const HISTORY_AFTER_REMOVE = [
Expand All @@ -44,6 +57,19 @@ export const HISTORY_AFTER_REMOVE = [
started: '2023-06-23T10:11:00.123Z',
finished: '2023-06-23T10:17:10.123Z',
},
{
mac_addr: null,
status: 'compliant',
device: {
manufacturer: 'Delta',
model: '03-DIN-SRC',
mac_addr: '01:02:03:04:05:08',
firmware: '1.2.2',
},
report: 'https://api.testrun.io/report.pdf',
started: '2023-06-23T10:11:00.123Z',
finished: '2023-06-23T10:17:10.123Z',
},
];

export const FORMATTED_HISTORY = [
Expand Down Expand Up @@ -79,6 +105,22 @@ export const FORMATTED_HISTORY = [
deviceInfo: 'Delta 03-DIN-SRC',
duration: '06m 10s',
},
{
mac_addr: null,
status: 'compliant',
device: {
manufacturer: 'Delta',
model: '03-DIN-SRC',
mac_addr: '01:02:03:04:05:08',
firmware: '1.2.2',
},
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',
},
];

export const FILTERS = {
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/src/app/model/testrun-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { Device } from './device';

export interface TestrunStatus {
mac_addr: string;
mac_addr: string | null;
status: string;
device: IDevice;
started: string | null;
Expand Down
3 changes: 2 additions & 1 deletion modules/ui/src/app/pages/reports/reports.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ describe('ReportsComponent', () => {
const data = HISTORY[0];
component.removeDevice(data);
expect(mockReportsStore.deleteReport).toHaveBeenCalledWith({
mac_addr: data.device.mac_addr,
mac_addr: data.mac_addr,
deviceMacAddr: data.device.mac_addr,
started: data.started,
});
});
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/app/pages/reports/reports.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class ReportsComponent implements OnInit, OnDestroy {
removeDevice(data: TestrunStatus) {
this.store.deleteReport({
mac_addr: data.mac_addr,
deviceMacAddr: data.device.mac_addr,
started: data.started,
});
this.focusNextButton();
Expand Down
22 changes: 20 additions & 2 deletions modules/ui/src/app/pages/reports/reports.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,33 @@ describe('ReportsStore', () => {
store.refreshState();

reportsStore.deleteReport({
mac_addr: '00:1e:42:35:73:c4',
started: '2023-06-22T10:11:00.123Z',
mac_addr: '01:02:03:04:05:07',
deviceMacAddr: '01:02:03:04:05:07',
started: '2023-07-23T10:11:00.123Z',
});

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

it('should update store after remove with null mac_addr', done => {
mockService.deleteReport.and.returnValue(of(true));
store.overrideSelector(selectReports, [...HISTORY_AFTER_REMOVE]);
store.refreshState();

reportsStore.deleteReport({
mac_addr: null,
deviceMacAddr: '01:02:03:04:05:08',
started: '2023-06-23T10:11:00.123Z',
});

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

describe('updateSort', () => {
Expand Down
31 changes: 19 additions & 12 deletions modules/ui/src/app/pages/reports/reports.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,22 @@ export class ReportsStore extends ComponentStore<ReportsComponentState> {
});

deleteReport = this.effect<{
mac_addr: string;
mac_addr: string | null;
deviceMacAddr: string;
started: string | null;
}>(trigger$ => {
return trigger$.pipe(
exhaustMap(({ mac_addr, started }) => {
return this.testRunService.deleteReport(mac_addr, started || '').pipe(
withLatestFrom(this.history$),
tap(([remove, current]) => {
if (remove) {
this.removeReport(mac_addr, started, current);
}
})
);
exhaustMap(({ mac_addr, deviceMacAddr, started }) => {
return this.testRunService
.deleteReport(mac_addr || deviceMacAddr, started || '')
.pipe(
withLatestFrom(this.history$),
tap(([remove, current]) => {
if (remove) {
this.removeReport(mac_addr, deviceMacAddr, started, current);
}
})
);
})
);
});
Expand Down Expand Up @@ -215,13 +218,17 @@ export class ReportsStore extends ComponentStore<ReportsComponentState> {
});

private removeReport(
mac_addr: string,
mac_addr: string | null,
deviceMacAddr: string,
started: string | null,
current: TestrunStatus[]
) {
const history = [...current];
const idx = history.findIndex(
report => report.mac_addr === mac_addr && report.started === started
report =>
report.mac_addr === mac_addr &&
report.device.mac_addr === deviceMacAddr &&
report.started === started
);
if (typeof idx === 'number') {
history.splice(idx, 1);
Expand Down