Skip to content

Commit

Permalink
feat: Adding more tests to the Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiorodriguezgarcia committed Apr 21, 2024
1 parent ce8276a commit 4e99eb2
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions webapp/src/tests/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,71 @@ describe('Dashboard', () => {
expect(mockAxios.history.post.length).toBeGreaterThan(0);
});
});

test('fetches user data and game modes on component mount', async () => {
mockAxios.onGet(`${api}/games/is-active`).reply(HttpStatusCode.Ok, {
"is_active": true
});

mockAxios.onGet(`${api}/games/gamemodes`).reply(HttpStatusCode.Ok, [
{
name: "KiWiQ",
description: "Test description of the game mode",
internal_representation: "KIWIQ_QUEST",
icon_name: "FaKiwiBird"
}
]);

mockAxios.onGet(`${api}/users/details`).reply(HttpStatusCode.Ok, {
id: 1,
username: 'testUser',
email: '[email protected]'
});

const {container} = render(
<ChakraProvider theme={theme}>
<MemoryRouter>
<Dashboard />
</MemoryRouter>
</ChakraProvider>
);

await waitFor(() => {
expect(mockAxios.history.get.length).toBe(3);
});
});

test('initializes a new game when Play button is clicked', async () => {
mockAxios.onGet(`${api}/games/is-active`).reply(HttpStatusCode.Ok, {
"is_active": false
});

mockAxios.onGet(`${api}/games/gamemodes`).reply(HttpStatusCode.Ok, [
{
name: "KiWiQ",
description: "Test description of the game mode",
internal_representation: "KIWIQ_QUEST",
icon_name: "FaKiwiBird"
}
]);

mockAxios.onGet(`${api}/users/details`).reply(HttpStatusCode.Ok, {
id: 1,
username: 'testUser',
email: '[email protected]'
});

const {container} = render(
<ChakraProvider theme={theme}>
<MemoryRouter>
<Dashboard />
</MemoryRouter>
</ChakraProvider>
);

await waitFor(() => {
fireEvent.click(container.querySelector("#play"));
expect(mockAxios.history.post.length).toBeGreaterThan(0);
});
});
});

0 comments on commit 4e99eb2

Please sign in to comment.