Skip to content
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

fix: Leaderboard PollSlice Import #10

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/features/pollSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Poll {
optionTwo: PollOption;
}

interface PollsState {
export interface PollsState {
polls: Record<string, Poll>;
status: 'idle' | 'loading' | 'succeeded' | 'failed';
error: string | undefined;
Expand Down
38 changes: 20 additions & 18 deletions src/tests/Leaderboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Leaderboard from '../components/Leaderboard';
type FullRootState = {
users: UsersState;
poll: PollsState;
}
};

const rootReducer = combineReducers({
users: userReducer,
Expand All @@ -36,54 +36,56 @@ const initialStateAuthenticated: RootState = {
password: 'password123',
avatarURL: '/path/to/avatar.png',
answers: {},
questions: []
questions: [],
},
users: {
'sarahedo': {
sarahedo: {
id: 'sarahedo',
name: 'Sarah Edo',
password: 'password123',
avatarURL: '/path/to/avatar.png',
answers: {},
questions: []
}
questions: [],
},
},
status: 'succeeded',
error: undefined
error: undefined,
},
poll: {
polls: {},
status: 'idle',
error: undefined
}
error: undefined,
},
};

// Create a custom render function that includes all providers
const customRender = (
ui: React.ReactElement,
{ initialState, store }: CustomRenderOptions = {}
{ initialState, store }: CustomRenderOptions = {},
) => {
// Create store only if it's not provided
store = store || configureStore({
reducer: rootReducer,
preloadedState: initialState
});
store =
store ||
configureStore({
reducer: rootReducer,
preloadedState: initialState,
});

return render(
<Provider store={store}>
<Router>
<ThemeProvider theme={theme}>
{ui}
</ThemeProvider>
<ThemeProvider theme={theme}>{ui}</ThemeProvider>
</Router>
</Provider>
</Provider>,
);
};

describe('Leaderboard Component', () => {
it('should display sorted users by activity', async () => {
customRender(<Leaderboard />, { initialState: initialStateAuthenticated });
expect(await screen.findByText(/Sarah Edo/)).toBeInTheDocument();
expect(await screen.findByText(/Questions Asked: 0 - Answers Given: 0/)).toBeInTheDocument();
expect(
await screen.findByText(/Questions Asked: 0 - Answers Given: 0/),
).toBeInTheDocument();
});
});