generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding more tests to the Dashboard
- Loading branch information
1 parent
ce8276a
commit 4e99eb2
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -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); | ||
}); | ||
}); | ||
}); |