-
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
Open
jsit
wants to merge
8
commits into
develop
Choose a base branch
from
test/archived-show-view
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b91d32
test: start adding tests for archive show page
jsit a70fd8c
test: fix ArchiveShowView tests
jsit fad66df
test: clean up ArchivedShowView test
jsit bd0db89
test: revert track player mock complexity
jsit 6f967aa
fix: remove notify listeners
jsit d223053
fix: revert var rename
jsit 9e6bfd0
fix: add labels to archive playback button
jsit 7fbc1b6
test: simplify tests
jsit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| }, | ||
| ], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { | ||
| act, | ||
| renderAsync, | ||
| screen, | ||
| userEvent, | ||
| } from '@testing-library/react-native'; | ||
| import TrackPlayer, { State } 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'; | ||
| import { ArchiveService } from '@services/ArchiveService'; | ||
|
|
||
| const archiveService = ArchiveService.getInstance(); | ||
| const testArchive = mockShow.archives[0]; | ||
|
|
||
| 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 () => { | ||
| /** | ||
| * Drive the ArchiveService into a playing state using its public API. | ||
| * | ||
| * This is necessary so that `isArchivePlaying` is true in the component, | ||
| * causing the skip buttons to appear. | ||
| * | ||
| * Technically this only needs to be done once for the whole test suite, but | ||
| * I'm putting it in each test so that each test is more self-contained. | ||
| * | ||
| */ | ||
| await archiveService.playArchive(testArchive, mockShow); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| expect( | ||
| await screen.findByLabelText(`Skip backward ${SKIP_INTERVAL} seconds`), | ||
| ).toBeTruthy(); | ||
| expect( | ||
| await screen.findByLabelText(`Skip forward ${SKIP_INTERVAL} seconds`), | ||
| ).toBeTruthy(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ArchivedShowView skip buttons', () => { | ||
| test('skip forward works', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| const { setPlaybackState, setDuration, setPosition } = | ||
| getTrackPlayerTestApi(); | ||
|
|
||
| await archiveService.playArchive(testArchive, mockShow); | ||
|
|
||
| await act(async () => { | ||
| setPlaybackState(State.Playing); | ||
| setDuration(120); // 2 minutes | ||
| setPosition(40); // start at 40s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| 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 { setPlaybackState, setDuration, setPosition } = | ||
| getTrackPlayerTestApi(); | ||
|
|
||
| await archiveService.playArchive(testArchive, mockShow); | ||
|
|
||
| await act(async () => { | ||
| setPlaybackState(State.Playing); | ||
| setDuration(120); // 2 minutes | ||
| setPosition(40); // start at 40s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| 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 { setPlaybackState, setDuration, setPosition } = | ||
| getTrackPlayerTestApi(); | ||
|
|
||
| await archiveService.playArchive(testArchive, mockShow); | ||
|
|
||
| await act(async () => { | ||
| setPlaybackState(State.Playing); | ||
| setDuration(120); // 2 minutes | ||
| setPosition(110); // start at 110s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| 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 { setPlaybackState, setDuration, setPosition } = | ||
| getTrackPlayerTestApi(); | ||
|
|
||
| await archiveService.playArchive(testArchive, mockShow); | ||
|
|
||
| await act(async () => { | ||
| setPlaybackState(State.Playing); | ||
| setDuration(120); // 2 minutes | ||
| setPosition(10); // start at 10s | ||
| }); | ||
|
|
||
| await renderAsync(<ArchivedShowView />, { wrapper: TestWrapper }); | ||
|
|
||
| await user.press( | ||
| await screen.findByLabelText(`Skip backward ${SKIP_INTERVAL} seconds`), | ||
| ); | ||
| expect(TrackPlayer.seekTo).toHaveBeenLastCalledWith(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.