-
Notifications
You must be signed in to change notification settings - Fork 2
test: add tests for ArchivedShowView #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
8b91d32
a70fd8c
fad66df
bd0db89
6f967aa
d223053
9e6bfd0
7fbc1b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { Show } from '@customTypes/RecentlyPlayed'; | ||
|
|
||
| // Realistic mock show based on __mocks__/MockNetworkResponses.ts (archivesXml) | ||
| export const mockShow: Show = { | ||
| id: '8982', | ||
| name: 'Africa Kabisa', | ||
| day: 0, | ||
| day_str: 'Sunday', | ||
| time: 960, | ||
| time_str: '4:00p', | ||
| length: 120, | ||
| hosts: 'Brutus leaderson', | ||
| alternates: 0, | ||
| archives: [ | ||
| { | ||
| url: 'https://wmbr.org/archive/Africa_Kabisa_%28rebroadcast%29____11_12_25_1%3A58_AM.mp3', | ||
| date: 'Wed, 12 Nov 2025 07:00:00 GMT', | ||
| size: '119046897', | ||
| }, | ||
| { | ||
| url: 'https://wmbr.org/archive/Africa_Kabisa____11_9_25_3%3A58_PM.mp3', | ||
| date: 'Sun, 09 Nov 2025 21:00:00 GMT', | ||
| size: '119033104', | ||
| }, | ||
| { | ||
| url: 'https://wmbr.org/archive/Africa_Kabisa____11_2_25_3%3A58_PM.mp3', | ||
| date: 'Sun, 02 Nov 2025 21:00:00 GMT', | ||
| size: '119066540', | ||
| }, | ||
| ], | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { | ||
| act, | ||
| renderAsync, | ||
| screen, | ||
| userEvent, | ||
| } from '@testing-library/react-native'; | ||
| import TrackPlayer from 'react-native-track-player'; | ||
|
|
||
| import ArchivedShowView from '@app/Schedule/ArchivedShowView'; | ||
| import { mockShow } from '../__mocks__/MockShows'; | ||
| import { getTrackPlayerTestApi, TestWrapper } from '@utils/TestUtils'; | ||
| import { SKIP_INTERVAL } from '@utils/TrackPlayerUtils'; | ||
|
|
||
| jest.mock('@react-navigation/native', () => { | ||
| const actualNav = jest.requireActual('@react-navigation/native'); | ||
| return { | ||
| ...actualNav, | ||
| useRoute: () => ({ | ||
| params: { | ||
| show: mockShow, | ||
| archive: mockShow.archives[0], | ||
| }, | ||
| }), | ||
| }; | ||
| }); | ||
|
|
||
| describe('ArchivedShowView', () => { | ||
| test('renders ArchivedShowView', async () => { | ||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| expect(screen.getByText(mockShow.name)).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('renders skip forward and back', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| await user.press(await screen.findByLabelText('Play')); | ||
|
|
||
| expect( | ||
| await screen.findByLabelText(`Skip backward ${SKIP_INTERVAL} seconds`), | ||
| ).toBeTruthy(); | ||
|
|
||
| expect( | ||
| await screen.findByLabelText(`Skip forward ${SKIP_INTERVAL} seconds`), | ||
| ).toBeTruthy(); | ||
| }); | ||
|
Comment on lines
+27
to
+48
|
||
| }); | ||
|
|
||
| describe('ArchivedShowView skip buttons', () => { | ||
| test('skip forward works', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| const { setDuration, setPosition } = getTrackPlayerTestApi(); | ||
|
|
||
| await act(async () => { | ||
| setDuration(120); // 2 minutes | ||
| setPosition(40); // start at 40s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| await user.press(await screen.findByLabelText('Play')); | ||
|
|
||
| await user.press( | ||
| await screen.findByLabelText(`Skip forward ${SKIP_INTERVAL} seconds`), | ||
| ); | ||
|
|
||
| expect(TrackPlayer.seekTo).toHaveBeenLastCalledWith(70); | ||
| }); | ||
|
|
||
| test('skip backward works', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| const { setDuration, setPosition } = getTrackPlayerTestApi(); | ||
|
|
||
| await act(async () => { | ||
| setDuration(120); // 2 minutes | ||
| setPosition(40); // start at 40s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| await user.press(await screen.findByLabelText('Play')); | ||
|
|
||
| await user.press( | ||
| await screen.findByLabelText(`Skip backward ${SKIP_INTERVAL} seconds`), | ||
| ); | ||
|
|
||
| expect(TrackPlayer.seekTo).toHaveBeenLastCalledWith(10); | ||
| }); | ||
|
|
||
| test('skip forward is clamped to duration', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| const { setDuration, setPosition } = getTrackPlayerTestApi(); | ||
|
|
||
| await act(async () => { | ||
| setDuration(120); // 2 minutes | ||
| setPosition(110); // start at 110s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| await user.press(await screen.findByLabelText('Play')); | ||
|
|
||
| await user.press( | ||
| await screen.findByLabelText(`Skip forward ${SKIP_INTERVAL} seconds`), | ||
| ); | ||
| expect(TrackPlayer.seekTo).toHaveBeenLastCalledWith(120); | ||
| }); | ||
|
|
||
| test('skip backward is clamped to 0', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| const { setDuration, setPosition } = getTrackPlayerTestApi(); | ||
|
|
||
| await act(async () => { | ||
| setDuration(120); // 2 minutes | ||
| setPosition(10); // start at 10s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| await user.press(await screen.findByLabelText('Play')); | ||
|
|
||
| await user.press( | ||
| await screen.findByLabelText(`Skip backward ${SKIP_INTERVAL} seconds`), | ||
| ); | ||
| expect(TrackPlayer.seekTo).toHaveBeenLastCalledWith(0); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These all make more sense as enums (that's what they are in React Native Track Player itself) and allows us to type things better in tests.