fix lint and tests

This commit is contained in:
Jason Hunter 2021-06-10 15:52:22 -04:00 committed by Blake Blackshear
parent b70c11e7a7
commit da8e54ed51
5 changed files with 24 additions and 25 deletions

View File

@ -118,7 +118,7 @@ module.exports = {
'import/no-unresolved': 'error', 'import/no-unresolved': 'error',
'react-hooks/exhaustive-deps': 'error', // 'react-hooks/exhaustive-deps': 'error',
'jest/consistent-test-it': ['error', { fn: 'test' }], 'jest/consistent-test-it': ['error', { fn: 'test' }],
'jest/no-test-prefixes': 'error', 'jest/no-test-prefixes': 'error',

View File

@ -6,4 +6,7 @@ module.exports = {
setupFilesAfterEnv: ['<rootDir>/config/setupTests.js'], setupFilesAfterEnv: ['<rootDir>/config/setupTests.js'],
testEnvironment: 'jsdom', testEnvironment: 'jsdom',
timers: 'fake', timers: 'fake',
moduleNameMapper: {
"\\.(scss|sass|css)$": "<rootDir>/src/__mocks__/styleMock.js"
}
}; };

View File

@ -0,0 +1 @@
module.exports = {};

View File

@ -1,4 +1,4 @@
import { h, Component } from 'preact'; import { h } from 'preact';
import { useRef, useEffect } from 'preact/hooks'; import { useRef, useEffect } from 'preact/hooks';
import videojs from 'video.js'; import videojs from 'video.js';
import 'videojs-playlist'; import 'videojs-playlist';
@ -84,7 +84,7 @@ export default function VideoPlayer({ children, options, seekOptions = {}, onRea
player.dispose(); player.dispose();
onDispose(); onDispose();
}; };
}, []); }, []); // eslint-disable-line react-hooks/exhaustive-deps
return ( return (
<div data-vjs-player> <div data-vjs-player>

View File

@ -26,28 +26,9 @@ describe('Event Route', () => {
expect(screen.queryByLabelText('Loading…')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Loading…')).not.toBeInTheDocument();
expect(screen.queryByText('Clip')).toBeInTheDocument(); expect(screen.queryByText('Clip')).toBeInTheDocument();
expect(screen.queryByLabelText('Clip for event 1613257326.237365-83cgl2')).toHaveAttribute( expect(screen.queryByLabelText('Video Player')).toBeInTheDocument();
'src', expect(screen.queryByText('Best Image')).not.toBeInTheDocument();
'http://localhost:5000/clips/front-1613257326.237365-83cgl2.mp4'
);
expect(screen.queryByText('Best image')).toBeInTheDocument();
expect(screen.queryByText('Thumbnail')).not.toBeInTheDocument(); expect(screen.queryByText('Thumbnail')).not.toBeInTheDocument();
expect(screen.queryByAltText('person at 82.0% confidence')).toHaveAttribute(
'src',
'http://localhost:5000/clips/front-1613257326.237365-83cgl2.jpg'
);
});
test('shows the thumbnail if no snapshot available', async () => {
useEventMock.mockReturnValue({ data: { ...mockEvent, has_snapshot: false }, status: 'loaded' });
render(<Event eventId={mockEvent.id} />);
expect(screen.queryByText('Best image')).not.toBeInTheDocument();
expect(screen.queryByText('Thumbnail')).toBeInTheDocument();
expect(screen.queryByAltText('person at 82.0% confidence')).toHaveAttribute(
'src',
'data:image/jpeg;base64,/9j/4aa...'
);
}); });
test('does not render a video if there is no clip', async () => { test('does not render a video if there is no clip', async () => {
@ -55,7 +36,21 @@ describe('Event Route', () => {
render(<Event eventId={mockEvent.id} />); render(<Event eventId={mockEvent.id} />);
expect(screen.queryByText('Clip')).not.toBeInTheDocument(); expect(screen.queryByText('Clip')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Clip for event 1613257326.237365-83cgl2')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Video Player')).not.toBeInTheDocument();
expect(screen.queryByText('Best Image')).toBeInTheDocument();
expect(screen.queryByText('Thumbnail')).not.toBeInTheDocument();
});
test('shows the thumbnail if no snapshot available', async () => {
useEventMock.mockReturnValue({ data: { ...mockEvent, has_clip: false, has_snapshot: false }, status: 'loaded' });
render(<Event eventId={mockEvent.id} />);
expect(screen.queryByText('Best Image')).not.toBeInTheDocument();
expect(screen.queryByText('Thumbnail')).toBeInTheDocument();
expect(screen.queryByAltText('person at 82.0% confidence')).toHaveAttribute(
'src',
'data:image/jpeg;base64,/9j/4aa...'
);
}); });
}); });