Sfoglia il codice sorgente

fix: deselect album when closing parent artist

Fela Maslen 5 anni fa
parent
commit
afdd388fce

+ 22 - 0
gmus/src/components/ui/cmus/reducer.spec.ts

@@ -423,6 +423,28 @@ describe(cmusUIReducer.name, () => {
               expect(result).toStrictEqual(stateNoActive);
             });
           });
+
+          describe('when the active album will disappear', () => {
+            const stateWithActiveAlbum: CmusUIState = {
+              ...initialCmusUIState,
+              artistAlbums: {
+                'Artist A': ['Album A', 'Album B', 'Album C'],
+              },
+              library: {
+                ...initialCmusUIState.library,
+                activeArtist: 'Artist A',
+                expandedArtists: ['Artist A'],
+                activeAlbum: 'Album B',
+              },
+            };
+
+            it('should set the active album to null', () => {
+              expect.assertions(2);
+              const result = cmusUIReducer(stateWithActiveAlbum, action);
+              expect(result.library.activeArtist).toBe('Artist A');
+              expect(result.library.activeAlbum).toBeNull();
+            });
+          });
         });
       });
     });

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

@@ -117,6 +117,7 @@ function toggleExpandArtist(library: CmusUIState['library']): CmusUIState['libra
       expandedArtists: library.expandedArtists.filter(
         (compare) => compare !== library.activeArtist,
       ),
+      activeAlbum: null,
     };
   }
   return { ...library, expandedArtists: [...library.expandedArtists, library.activeArtist] };