|
@@ -1,10 +1,11 @@
|
|
import { h } from 'preact';
|
|
import { h } from 'preact';
|
|
import * as Api from '../../api';
|
|
import * as Api from '../../api';
|
|
|
|
+import * as Mqtt from '../../api/mqtt';
|
|
import Debug from '../Debug';
|
|
import Debug from '../Debug';
|
|
import { render, screen } from '@testing-library/preact';
|
|
import { render, screen } from '@testing-library/preact';
|
|
|
|
|
|
describe('Debug Route', () => {
|
|
describe('Debug Route', () => {
|
|
- let useStatsMock;
|
|
|
|
|
|
+ let useStatsMock, useMqttMock;
|
|
|
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
jest.spyOn(Api, 'useConfig').mockImplementation(() => ({
|
|
jest.spyOn(Api, 'useConfig').mockImplementation(() => ({
|
|
@@ -16,10 +17,14 @@ describe('Debug Route', () => {
|
|
front: { name: 'front', objects: { track: ['taco', 'cat', 'dog'] } },
|
|
front: { name: 'front', objects: { track: ['taco', 'cat', 'dog'] } },
|
|
side: { name: 'side', objects: { track: ['taco', 'cat', 'dog'] } },
|
|
side: { name: 'side', objects: { track: ['taco', 'cat', 'dog'] } },
|
|
},
|
|
},
|
|
|
|
+ mqtt: {
|
|
|
|
+ stats_interva: 60,
|
|
|
|
+ },
|
|
},
|
|
},
|
|
status: 'loaded',
|
|
status: 'loaded',
|
|
}));
|
|
}));
|
|
- useStatsMock = jest.spyOn(Api, 'useStats').mockImplementation(() => statsMock);
|
|
|
|
|
|
+ useStatsMock = jest.spyOn(Api, 'useStats').mockImplementation(() => ({ data: statsMock }));
|
|
|
|
+ useMqttMock = jest.spyOn(Mqtt, 'useMqtt').mockImplementation(() => ({ value: { payload: null } }));
|
|
});
|
|
});
|
|
|
|
|
|
test('shows an ActivityIndicator if stats are null', async () => {
|
|
test('shows an ActivityIndicator if stats are null', async () => {
|
|
@@ -43,29 +48,31 @@ describe('Debug Route', () => {
|
|
expect(screen.queryByRole('button', { name: 'Copy to Clipboard' })).toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: 'Copy to Clipboard' })).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
|
|
- test('updates the stats on a timeout', async () => {
|
|
|
|
- jest.spyOn(window, 'setTimeout').mockReturnValue(123);
|
|
|
|
- render(<Debug />);
|
|
|
|
- expect(useStatsMock).toHaveBeenCalledWith(null, null);
|
|
|
|
- jest.advanceTimersByTime(1001);
|
|
|
|
- expect(useStatsMock).toHaveBeenCalledWith(null, 123);
|
|
|
|
- expect(useStatsMock).toHaveBeenCalledTimes(2);
|
|
|
|
|
|
+ test('updates the stats from mqtt', async () => {
|
|
|
|
+ const { rerender } = render(<Debug />);
|
|
|
|
+ expect(useMqttMock).toHaveBeenCalledWith('stats');
|
|
|
|
+ useMqttMock.mockReturnValue({
|
|
|
|
+ value: {
|
|
|
|
+ payload: { ...statsMock, detectors: { coral: { ...statsMock.detectors.coral, inference_speed: 42.4242 } } },
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ rerender(<Debug />);
|
|
|
|
+
|
|
|
|
+ expect(screen.queryByText('42.4242')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
const statsMock = {
|
|
const statsMock = {
|
|
- data: {
|
|
|
|
|
|
+ detection_fps: 0.0,
|
|
|
|
+ detectors: { coral: { detection_start: 0.0, inference_speed: 8.94, pid: 52 } },
|
|
|
|
+ front: { camera_fps: 5.0, capture_pid: 64, detection_fps: 0.0, pid: 54, process_fps: 0.0, skipped_fps: 0.0 },
|
|
|
|
+ side: {
|
|
|
|
+ camera_fps: 6.9,
|
|
|
|
+ capture_pid: 71,
|
|
detection_fps: 0.0,
|
|
detection_fps: 0.0,
|
|
- detectors: { coral: { detection_start: 0.0, inference_speed: 8.94, pid: 52 } },
|
|
|
|
- front: { camera_fps: 5.0, capture_pid: 64, detection_fps: 0.0, pid: 54, process_fps: 0.0, skipped_fps: 0.0 },
|
|
|
|
- side: {
|
|
|
|
- camera_fps: 6.9,
|
|
|
|
- capture_pid: 71,
|
|
|
|
- detection_fps: 0.0,
|
|
|
|
- pid: 60,
|
|
|
|
- process_fps: 0.0,
|
|
|
|
- skipped_fps: 0.0,
|
|
|
|
- },
|
|
|
|
- service: { uptime: 34812, version: '0.8.1-d376f6b' },
|
|
|
|
|
|
+ pid: 60,
|
|
|
|
+ process_fps: 0.0,
|
|
|
|
+ skipped_fps: 0.0,
|
|
},
|
|
},
|
|
|
|
+ service: { uptime: 34812, version: '0.8.1-d376f6b' },
|
|
};
|
|
};
|