Преглед изворни кода

feat: scroll to next song when queueing a song

Fela Maslen пре 5 година
родитељ
комит
56f3526035

+ 9 - 0
gmus-web/src/components/ui/cmus/reducer/fixtures.ts

@@ -36,9 +36,18 @@ export const stateWithActiveArtist: CmusUIState = {
 
 export const stateWithActiveSong: CmusUIState = {
   ...stateLibrary,
+  artistSongs: {
+    'My artist': [
+      { id: 1867 } as Song,
+      { id: 1870, album: 'Different album' } as Song,
+      { id: 46, album: 'My album' } as Song,
+    ],
+  },
   library: {
     ...stateLibrary.library,
     modeWindow: LibraryModeWindow.SongList,
+    activeArtist: 'My artist',
+    activeAlbum: 'My album',
     activeSongId: 1867,
   },
 };

+ 12 - 4
gmus-web/src/components/ui/cmus/reducer/keypress.spec.ts

@@ -77,10 +77,18 @@ describe(ActionTypeKeyPressed, () => {
     const action: ActionKeyPressed = { type: ActionTypeKeyPressed, key: Keys.E };
 
     describe('when in library view', () => {
-      it('should set global action to add the selected song to the queue', () => {
-        expect.assertions(1);
-        const result = cmusUIReducer(stateWithActiveSong, action);
-        expect(result.globalAction).toStrictEqual(queuePushed(1867));
+      describe('when in songs list mode', () => {
+        it('should set global action to add the selected song to the queue', () => {
+          expect.assertions(1);
+          const result = cmusUIReducer(stateWithActiveSong, action);
+          expect(result.globalAction).toStrictEqual(queuePushed(1867));
+        });
+
+        it('should select the next song in the list', () => {
+          expect.assertions(1);
+          const result = cmusUIReducer(stateWithActiveSong, action);
+          expect(result.library.activeSongId).toBe(46);
+        });
       });
     });
   });

+ 2 - 2
gmus-web/src/components/ui/cmus/reducer/keypress.ts

@@ -2,7 +2,7 @@ import { masterSet, playPaused, queuePushed, queueRemoved, stateSet } from '../.
 import { ActionKeyPressed, Keys } from '../../../../hooks/vim';
 import { CmusUIState, LibraryModeWindow, Overlay, View } from '../types';
 import { handleOrder } from './order';
-import { handleScroll } from './scroll';
+import { handleScroll, scrollSongs } from './scroll';
 import { withGlobalAction } from './utils';
 
 const libraryModeWindows: LibraryModeWindow[] = Object.values(LibraryModeWindow);
@@ -133,7 +133,7 @@ export function handleKeyPress(state: CmusUIState, action: ActionKeyPressed): Cm
         state.library.modeWindow === LibraryModeWindow.SongList &&
         state.library.activeSongId
       ) {
-        return withGlobalAction(state, queuePushed(state.library.activeSongId));
+        return withGlobalAction(scrollSongs(state, 1), queuePushed(state.library.activeSongId));
       }
       return state;
 

+ 1 - 1
gmus-web/src/components/ui/cmus/reducer/scroll.ts

@@ -4,7 +4,7 @@ import { getFilteredSongs } from '../selectors';
 import { CmusUIState, LibraryModeWindow, View } from '../types';
 import { getNextActiveArtistAndAlbum } from '../utils/scroll';
 
-const scrollSongs = (state: CmusUIState, delta: number): CmusUIState =>
+export const scrollSongs = (state: CmusUIState, delta: number): CmusUIState =>
   state.library.activeArtist === null
     ? state
     : {

+ 5 - 3
gmus-web/src/hooks/request.spec.tsx

@@ -67,8 +67,9 @@ describe(useRequestCallback.name, () => {
       unmount();
     });
 
-    // eslint-disable-next-line jest/prefer-expect-assertions
     it('should set the response and loading state back to false', async () => {
+      expect.hasAssertions();
+
       const { getByTestId, unmount } = setupRequest();
 
       await waitFor(() => {
@@ -80,8 +81,9 @@ describe(useRequestCallback.name, () => {
     });
 
     describe('when the request is cancelled', () => {
-      // eslint-disable-next-line jest/prefer-expect-assertions
       it('should set the loading state back to false and not set the response', async () => {
+        expect.hasAssertions();
+
         const { getByText, getByTestId, unmount } = setupRequest();
         act(() => {
           fireEvent.click(getByText('Cancel!'));
@@ -109,8 +111,8 @@ describe(useRequestCallback.name, () => {
       onError.mockClear();
     });
 
-    // eslint-disable-next-line jest/prefer-expect-assertions
     it('should call onError', async () => {
+      expect.hasAssertions();
       const { unmount } = setupRequest();
 
       await waitFor(() => {

+ 2 - 1
gmus-web/src/hooks/status.spec.tsx

@@ -105,9 +105,10 @@ describe(useCurrentlyPlayingSongInfo.name, () => {
           .reply(200, testSong, { 'Access-Control-Allow-Origin': '*' });
       });
 
-      // eslint-disable-next-line jest/prefer-expect-assertions
       it('should fetch the info for the updated song ID, and update the state', async () => {
+        expect.hasAssertions();
         setup(stateStale);
+
         await waitFor(() => {
           expect(dispatch).toHaveBeenCalledTimes(1);
         });