Jason Hunter 3 роки тому
батько
коміт
da8e54ed51

+ 1 - 1
web/.eslintrc.js

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

+ 3 - 0
web/jest.config.js

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

+ 1 - 0
web/src/__mocks__/styleMock.js

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

+ 2 - 2
web/src/components/VideoPlayer.jsx

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

+ 14 - 19
web/src/routes/__tests__/Event.test.jsx

@@ -26,37 +26,32 @@ describe('Event Route', () => {
     expect(screen.queryByLabelText('Loading…')).not.toBeInTheDocument();
 
     expect(screen.queryByText('Clip')).toBeInTheDocument();
-    expect(screen.queryByLabelText('Clip for event 1613257326.237365-83cgl2')).toHaveAttribute(
-      'src',
-      'http://localhost:5000/clips/front-1613257326.237365-83cgl2.mp4'
-    );
-    expect(screen.queryByText('Best image')).toBeInTheDocument();
+    expect(screen.queryByLabelText('Video Player')).toBeInTheDocument();
+    expect(screen.queryByText('Best Image')).not.toBeInTheDocument();
+    expect(screen.queryByText('Thumbnail')).not.toBeInTheDocument();
+  });
+
+  test('does not render a video if there is no clip', async () => {
+    useEventMock.mockReturnValue({ data: { ...mockEvent, has_clip: false }, status: 'loaded' });
+    render(<Event eventId={mockEvent.id} />);
+
+    expect(screen.queryByText('Clip')).not.toBeInTheDocument();
+    expect(screen.queryByLabelText('Video Player')).not.toBeInTheDocument();
+    expect(screen.queryByText('Best Image')).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' });
+    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('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 () => {
-    useEventMock.mockReturnValue({ data: { ...mockEvent, has_clip: false }, status: 'loaded' });
-    render(<Event eventId={mockEvent.id} />);
-
-    expect(screen.queryByText('Clip')).not.toBeInTheDocument();
-    expect(screen.queryByLabelText('Clip for event 1613257326.237365-83cgl2')).not.toBeInTheDocument();
-  });
 });
 
 const mockEvent = {