diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 0000000..9b61d7e --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,22 @@ +name: E2E tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['20'] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build + - run: npm run test:e2e diff --git a/cypress/e2e/example.cy.ts b/cypress/e2e/example.cy.ts deleted file mode 100644 index 7554c35..0000000 --- a/cypress/e2e/example.cy.ts +++ /dev/null @@ -1,8 +0,0 @@ -// https://on.cypress.io/api - -describe('My First Test', () => { - it('visits the app root url', () => { - cy.visit('/') - cy.contains('h1', 'You did it!') - }) -}) diff --git a/cypress/e2e/game.cy.ts b/cypress/e2e/game.cy.ts new file mode 100644 index 0000000..33a3836 --- /dev/null +++ b/cypress/e2e/game.cy.ts @@ -0,0 +1,33 @@ +/* eslint-disable cypress/no-unnecessary-waiting */ +const moveTilesAndWait = (key: "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight") => { + cy.get("html").trigger("keyup", { key }); + cy.wait(500); +}; + +describe("Game", () => { + it("should move tiles around the board and add new ones", () => { + cy.visit("/"); + + // Trigger several arrow clicks + moveTilesAndWait("ArrowUp"); + moveTilesAndWait("ArrowDown"); + moveTilesAndWait("ArrowLeft"); + moveTilesAndWait("ArrowRight"); + + // At least one tile should appear after movements + cy.get(".tile").should("have.length.at.least", 2); + }); + + it("start a new game", () => { + cy.visit("/"); + + // Trigger several arrow clicks + moveTilesAndWait("ArrowUp"); + moveTilesAndWait("ArrowLeft"); + + // Restart game + cy.get("[data-testid='new-game']").click(); + + cy.get(".tile").should("have.length", 1); + }); +}); diff --git a/cypress/e2e/settings.cy.ts b/cypress/e2e/settings.cy.ts new file mode 100644 index 0000000..b4a3945 --- /dev/null +++ b/cypress/e2e/settings.cy.ts @@ -0,0 +1,25 @@ +const newGridSize = 4; +const newNumOnbstacles = 2; + +describe("Settings", () => { + it("should update board settings", () => { + cy.visit("/"); + + // Open settings dialog + cy.get("[data-testid='open-settings']").click(); + cy.get("[data-testid='app-dialog']").should("be.visible"); + + // Update grid size + cy.get("[data-testid='grid-size-setting']").select(newGridSize.toString()); + + // Update obstacles + cy.get("[data-testid='obstacles-setting']").select(newNumOnbstacles.toString()); + + // Save settings + cy.get("[data-testid='save-settings']").click(); + + // Vefiry game changed + cy.get(".tile.tile--obstacle").should('have.length', newNumOnbstacles); + cy.get("[data-testid='grid-item']").should('have.length', Math.pow(newGridSize, 2)); + }); +}); diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json deleted file mode 100644 index 02e4254..0000000 --- a/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} diff --git a/package.json b/package.json index cdcb4dd..4156ea2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "dev": "vite", "build": "run-p type-check \"build-only {@}\" --", "preview": "vite preview", - "test:unit": "vitest", + "test:unit:dev": "vitest", + "test:unit": "vitest run", "test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'", "test:e2e:dev": "start-server-and-test 'vite dev --port 4173' http://localhost:4173 'cypress open --e2e'", "build-only": "vite build", diff --git a/src/components/App/Dialog/AppDialog.vue b/src/components/App/Dialog/AppDialog.vue index f2769ed..bc5c3d0 100644 --- a/src/components/App/Dialog/AppDialog.vue +++ b/src/components/App/Dialog/AppDialog.vue @@ -1,9 +1,14 @@