diff --git a/web/src/screens/RerunCollectionsScreen.test.tsx b/web/src/screens/RerunCollectionsScreen.test.tsx index 3482807bf..18fa1eb1a 100644 --- a/web/src/screens/RerunCollectionsScreen.test.tsx +++ b/web/src/screens/RerunCollectionsScreen.test.tsx @@ -154,6 +154,58 @@ describe('RerunCollectionsScreen', () => { expect(await within(refreshed[1]).findByText('Bundle')).toBeInTheDocument(); }); + it('preserves an out-of-set stored playback order on edit-load and re-saves it unchanged', async () => { + const outOfSet = [ + { + collectionType: 'Artist', + firstRunPlaybackOrder: 'SeasonEpisode', + id: 9, + name: 'Odd Order Reruns', + rerunPlaybackOrder: 'SeasonEpisode', + selectedId: 42, + selectedName: 'Some Artist' + } + ]; + + const fetchMock = mockApi({ + list: outOfSet, + onRequest: (url, method) => + url === '/api/rerun-collections/9' && method === 'PUT' ? jsonResponse({ id: 9 }, 200) : null + }); + + render(); + + fireEvent.click(await screen.findByText('Odd Order Reruns')); + + // combobox order: [0] Collection Type, [1] selection picker, [2] First Run, [3] Rerun. + const comboboxes = await screen.findAllByRole('combobox'); + const firstRunSelect = comboboxes[2]; + const rerunSelect = comboboxes[3]; + + // Artist's normal order set (Chronological / Random / Shuffle) does not include + // SeasonEpisode, but the stored value must still be present and selected. + expect(within(firstRunSelect).getByText('Season, Episode')).toBeInTheDocument(); + expect((firstRunSelect as HTMLSelectElement).value).toBe('SeasonEpisode'); + expect(within(rerunSelect).getByText('Season, Episode')).toBeInTheDocument(); + expect((rerunSelect as HTMLSelectElement).value).toBe('SeasonEpisode'); + + fireEvent.click(screen.getByRole('button', { name: 'Save rerun collection' })); + + await waitFor(() => { + const putCall = fetchMock.mock.calls.find( + ([u, init]) => u === '/api/rerun-collections/9' && (init?.method ?? '').toUpperCase() === 'PUT' + ); + expect(putCall).toBeDefined(); + expect(JSON.parse(String(putCall?.[1]?.body))).toEqual({ + collectionType: 'Artist', + firstRunPlaybackOrder: 'SeasonEpisode', + name: 'Odd Order Reruns', + rerunPlaybackOrder: 'SeasonEpisode', + selectedId: 42 + }); + }); + }); + it('confirms and DELETEs a rerun collection', async () => { const fetchMock = mockApi(); diff --git a/web/src/screens/RerunCollectionsScreen.tsx b/web/src/screens/RerunCollectionsScreen.tsx index 6371a33c6..0dd504567 100644 --- a/web/src/screens/RerunCollectionsScreen.tsx +++ b/web/src/screens/RerunCollectionsScreen.tsx @@ -80,6 +80,15 @@ function defaultOrderFor(type: RerunCollectionType): PlaybackOrder { return type === 'MultiCollection' ? 'Shuffle' : 'Chronological'; } +// The REST API accepts any PlaybackOrder for any collectionType (the per-type restriction +// enforced by orderOptionsFor is only a UI convention), so a rerun collection created via the +// API can carry a stored order outside the type's normal set. On edit-load, union that value in +// rather than letting the Select coerce it away (which would silently change what gets saved). +function orderOptionsWithCurrent(type: RerunCollectionType, current: PlaybackOrder): SelectOption[] { + const options = orderOptionsFor(type); + return options.some((option) => option.value === current) ? options : [...options, orderOption(current)]; +} + function loadPickerOptions(type: RerunCollectionType): Promise { const config = COLLECTION_TYPES.find((entry) => entry.value === type); if (!config) { @@ -290,7 +299,8 @@ function RerunCollectionEditor({ ...pickerItems.map((item) => ({ label: item.name, value: String(item.id) })) ]; - const orderOptions = orderOptionsFor(collectionType); + const firstRunOrderOptions = orderOptionsWithCurrent(collectionType, draft.firstRunPlaybackOrder); + const rerunOrderOptions = orderOptionsWithCurrent(collectionType, draft.rerunPlaybackOrder); return (
@@ -352,7 +362,7 @@ function RerunCollectionEditor({ onChange={(event) => setDraft((current) => ({ ...current, firstRunPlaybackOrder: event.target.value as PlaybackOrder })) } - options={orderOptions} + options={firstRunOrderOptions} value={draft.firstRunPlaybackOrder} />
@@ -363,7 +373,7 @@ function RerunCollectionEditor({ onChange={(event) => setDraft((current) => ({ ...current, rerunPlaybackOrder: event.target.value as PlaybackOrder })) } - options={orderOptions} + options={rerunOrderOptions} value={draft.rerunPlaybackOrder} />