-
Notifications
You must be signed in to change notification settings - Fork 1
Use zustand instead of redux #319
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,34 +1,50 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Provider } from 'react-redux'; | ||
| import { describe, expect, test } from 'vitest'; | ||
| import { beforeEach, describe, expect, test, vi } from 'vitest'; | ||
| import { mockTrack } from '../../../tests/mockData'; | ||
| import { createMockStore } from '../../store/store'; | ||
| import { createTestStore, setupTestStoreMocks } from '../../store/test-utils'; | ||
| import * as zustandStore from '../../store/zustand-store'; | ||
| import Player from './Player'; | ||
|
|
||
| const playerStore = createMockStore({ | ||
| currentSong: { song: null, playing: false }, | ||
| }); | ||
|
|
||
| const playerStoreWithSong = createMockStore({ | ||
| currentSong: { song: mockTrack, playing: true }, | ||
| }); | ||
| vi.mock('../../store/zustand-store'); | ||
|
|
||
| describe('Player', () => { | ||
| test('should render nothing', async () => { | ||
| render( | ||
| <Provider store={playerStore}> | ||
| <Player /> | ||
| </Provider>, | ||
| ); | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should render nothing when no song is loaded', async () => { | ||
| const testStore = createTestStore({ | ||
| currentSong: { | ||
| song: null, | ||
| playing: false, | ||
| }, | ||
| }); | ||
| setupTestStoreMocks(testStore, zustandStore, vi); | ||
| render(<Player />); | ||
| expect(screen.queryByTestId('audioEml')).toBeFalsy(); | ||
| }); | ||
|
|
||
| test('should render audio element', async () => { | ||
| render( | ||
| <Provider store={playerStoreWithSong}> | ||
| <Player /> | ||
| </Provider>, | ||
| ); | ||
| test('should render audio element when song is loaded and playing', async () => { | ||
| const testStore = createTestStore({ | ||
| currentSong: { | ||
| song: mockTrack, | ||
| playing: true, | ||
| }, | ||
| }); | ||
| setupTestStoreMocks(testStore, zustandStore, vi); | ||
| render(<Player />); | ||
| expect(screen.getByTestId('audioEml')).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('should render audio element when song is loaded but not playing', async () => { | ||
| const testStore = createTestStore({ | ||
| currentSong: { | ||
| song: mockTrack, | ||
| playing: false, | ||
| }, | ||
| }); | ||
| setupTestStoreMocks(testStore, zustandStore, vi); | ||
| render(<Player />); | ||
| expect(screen.getByTestId('audioEml')).toBeTruthy(); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,17 +1,13 @@ | ||
| import React from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
| import { Provider } from 'react-redux'; | ||
| import App from './App'; | ||
| import './index.scss'; | ||
| import { store } from './store/store'; | ||
|
|
||
| const container = document.getElementById('root'); | ||
| // biome-ignore lint/style/noNonNullAssertion: <explanation> | ||
| const root = createRoot(container!); | ||
| root.render( | ||
| <React.StrictMode> | ||
| <Provider store={store}> | ||
| <App /> | ||
| </Provider> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); |
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 |
|---|---|---|
| @@ -1,54 +1,82 @@ | ||
| import { cleanup, render, screen } from '@testing-library/react'; | ||
| import { Provider } from 'react-redux'; | ||
| import { afterEach, describe, expect, test } from 'vitest'; | ||
| import { MemoryRouter } from 'react-router-dom'; | ||
| import { afterEach, describe, expect, test, vi } from 'vitest'; | ||
| import { mockPlaylistDetails } from '../../../tests/mockData'; | ||
| import { createMockStore } from '../../store/store'; | ||
| import { createTestStore, setupTestStoreMocks } from '../../store/test-utils'; | ||
| import * as zustandStore from '../../store/zustand-store'; | ||
| import PlaylistDetail from './PlaylistDetail'; | ||
|
|
||
| const store = createMockStore({ | ||
| playlistDetail: { | ||
| playlist: mockPlaylistDetails, | ||
| loading: false, | ||
| error: '', | ||
| }, | ||
| }); | ||
|
|
||
| const loadingStore = createMockStore({ | ||
| playlistDetail: { | ||
| playlist: null, | ||
| loading: true, | ||
| error: '', | ||
| }, | ||
| }); | ||
| vi.mock('../../store/zustand-store'); | ||
|
|
||
| describe('Playlist details', () => { | ||
| afterEach(cleanup); | ||
| afterEach(() => { | ||
| cleanup(); | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should render loader when playlist is loading', async () => { | ||
| const testStore = createTestStore({ | ||
| playlistDetail: { | ||
| playlist: null, | ||
| loading: true, | ||
| error: '', | ||
| }, | ||
| currentSong: { | ||
| song: null, | ||
| playing: false, | ||
| }, | ||
| }); | ||
| setupTestStoreMocks(testStore, zustandStore, vi); | ||
|
|
||
| test('should render loader', async () => { | ||
| render( | ||
| <Provider store={loadingStore}> | ||
| <MemoryRouter initialEntries={['/playlist/123']}> | ||
| <PlaylistDetail /> | ||
| </Provider>, | ||
| </MemoryRouter>, | ||
| ); | ||
| expect(screen.getByRole('progressbar', { busy: true })).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('should render playlist details', async () => { | ||
| test('should render playlist details when loaded', async () => { | ||
| const testStore = createTestStore({ | ||
| playlistDetail: { | ||
| playlist: mockPlaylistDetails, | ||
| loading: false, | ||
| error: '', | ||
| }, | ||
| currentSong: { | ||
| song: null, | ||
| playing: false, | ||
| }, | ||
| }); | ||
| setupTestStoreMocks(testStore, zustandStore, vi); | ||
| render( | ||
| <Provider store={store}> | ||
| <MemoryRouter initialEntries={['/playlist/123']}> | ||
| <PlaylistDetail /> | ||
| </Provider>, | ||
| </MemoryRouter>, | ||
| ); | ||
| expect(screen.findByText('Hits du Moment')).toBeTruthy(); | ||
| }); | ||
|
|
||
| // test('should have a background color', async () => { | ||
| // render( | ||
| // <Provider store={store}> | ||
| // <PlaylistDetail /> | ||
| // </Provider>, | ||
| // ); | ||
|
|
||
| // expect(screen.getByTestId('Background').style.backgroundColor).toBeTruthy(); | ||
| // }); | ||
| test('should render error state when there is an error', async () => { | ||
| const testStore = createTestStore({ | ||
| playlistDetail: { | ||
| playlist: null, | ||
| loading: false, | ||
| error: 'Failed to load playlist', | ||
| }, | ||
| currentSong: { | ||
| song: null, | ||
| playing: false, | ||
| }, | ||
| }); | ||
| setupTestStoreMocks(testStore, zustandStore, vi); | ||
| render( | ||
| <MemoryRouter initialEntries={['/playlist/123']}> | ||
| <PlaylistDetail /> | ||
| </MemoryRouter>, | ||
| ); | ||
| // The error handling would depend on how the component handles error states | ||
| // For now, we just verify the component renders without crashing | ||
| expect(screen.queryByRole('progressbar', { busy: true })).toBeFalsy(); | ||
| }); | ||
| }); | ||
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.