diff --git a/.github/workflows/nextjs.yml b/.github/workflows/deploy-to-github-pages.yml
similarity index 98%
rename from .github/workflows/nextjs.yml
rename to .github/workflows/deploy-to-github-pages.yml
index 39c791b..1f3c13f 100644
--- a/.github/workflows/nextjs.yml
+++ b/.github/workflows/deploy-to-github-pages.yml
@@ -1,4 +1,4 @@
-# Publish Flowit react to githup pages.
+# Deploy Flowit react to githup pages.
# Based on workflow from https://github.com/actions/starter-workflows/blob/main/pages/nextjs.yml
name: Deploy flowit-react to Pages
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
new file mode 100644
index 0000000..2299c8b
--- /dev/null
+++ b/.github/workflows/run-tests.yml
@@ -0,0 +1,48 @@
+# Run jest tests on pull request
+name: Run jest tests on PR
+
+on:
+ # Runs on pull requests targeting the default branch
+ pull_request:
+ branches:
+ - main
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# Only one set of tests running per PR at a time.
+# If a PR is updated while tests are running cancel the in progress tests and start the new ones.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ # Build job
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Setup Node
+ uses: actions/setup-node@v3
+ with:
+ node-version: "16"
+ cache: yarn
+ - name: Restore cache
+ uses: actions/cache@v3
+ with:
+ path: |
+ .next/cache
+ # Generate a new cache whenever packages or source files change.
+ key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
+ # If source files changed but packages didn't, rebuild from a prior cache.
+ restore-keys: |
+ ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
+ - name: Clone levels repository
+ run: git clone https://github.com/Flowit-Game/Levels.git
+ - name: Install dependencies
+ run: yarn
+ - name: Convert levels from xml to typescript
+ run: yarn convert-levels
+ - name: Run Jest tests
+ run: yarn test
\ No newline at end of file
diff --git a/components/Game/Game.test.tsx b/components/Game/Game.test.tsx
new file mode 100644
index 0000000..5e2796d
--- /dev/null
+++ b/components/Game/Game.test.tsx
@@ -0,0 +1,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(
+ {},
+ changeCurrentScreen: () => {},
+ levelProgress: levelProgressDefault,
+ changeLevelProgress: () => {},
+ pack: "Easy",
+ changePack: () => {},
+ }}>
+
+
+ )
+ 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()
+ });
+});
\ No newline at end of file
diff --git a/components/MessageModal/MessageModal.tsx b/components/MessageModal/MessageModal.tsx
index a7bca58..4a34d03 100644
--- a/components/MessageModal/MessageModal.tsx
+++ b/components/MessageModal/MessageModal.tsx
@@ -22,7 +22,7 @@ export function MessageModal(props: MessageModalProps) {
}
return (
-
+
diff --git a/components/SelectPack/SelectPack.tsx b/components/SelectPack/SelectPack.tsx
index 3cc380e..7808356 100644
--- a/components/SelectPack/SelectPack.tsx
+++ b/components/SelectPack/SelectPack.tsx
@@ -1,46 +1,28 @@
import {useContext} from "react";
import {LevelContext, screens} from "@/pages";
import styles from "./SelectPack.module.css"
+import {packChoices} from "@/levels/levelsUtils";
export function SelectPack() {
const {changeCurrentScreen, changePack} = useContext(
LevelContext
);
+ const packs: Array
= ["Easy", "Medium", "Hard", "Community"]
return (
Select Pack
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ {packs.map((packName, index) => (
+
+
+
+ ))}
);
}
\ No newline at end of file
diff --git a/components/Square/Square.tsx b/components/Square/Square.tsx
index 54892e5..66af15c 100644
--- a/components/Square/Square.tsx
+++ b/components/Square/Square.tsx
@@ -37,6 +37,7 @@ export type SquareProps = {
export function Square(props: SquareProps) {
return (