-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.test.tsx
More file actions
41 lines (36 loc) · 1.33 KB
/
Game.test.tsx
File metadata and controls
41 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {Game} from "./Game";
import "@testing-library/jest-dom";
import {render, screen} from "@testing-library/react";
import React from "react";
import {LevelContext, levelProgressDefault} from "@/pages";
import userEvent from '@testing-library/user-event'
jest.mock('next/router', () => require('next-router-mock'));
describe("First Level", () => {
it("Solve the second level", async () => {
// The solution to easy level 2 is probably not too much of a spoiler,
// and it's a good initial test to check that we can click buttons
// solve a level.
// TODO https://github.com/jsdom/jsdom/issues/3363
global.structuredClone = jest.fn(val => {
return JSON.parse(JSON.stringify(val));
});
const user = userEvent.setup()
render(
<LevelContext.Provider value={{
levelNumber: 1,
changeLevelNumber: () => {},
changeCurrentScreen: () => {},
levelProgress: levelProgressDefault,
changeLevelProgress: () => {},
pack: "Easy",
changePack: () => {},
}}>
<Game/>
</LevelContext.Provider>
)
expect(screen.getByTestId("square-0-0")).toBeInTheDocument()
await user.click(screen.getByTestId("square-4-0"));
await user.click(screen.getByTestId("square-2-2"))
expect(screen.getByTestId("message-modal")).toBeInTheDocument()
});
});