From 1baf28cafc9f5805aa7b4db4fe673b63b5ff1335 Mon Sep 17 00:00:00 2001 From: Limerio <44976231+Limerio@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:21:09 +0100 Subject: [PATCH] chore(): add home spec and update playwright config --- .github/workflows/playwright.yml | 2 ++ package-lock.json | 19 ------------ package.json | 5 ++-- scripts/seed.js | 5 +++- tests/home.spec.js | 50 ++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 tests/home.spec.js diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 6bc9eab..e567969 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -21,5 +21,7 @@ jobs: run: npx playwright install --with-deps - name: Test database deployment run: docker-compose up -d + - name: Seeding + run: npm run seed - name: Run Playwright tests run: npm run test:e2e diff --git a/package-lock.json b/package-lock.json index 75ec141..c063bdd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,6 @@ "@types/node": "^20.11.30", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.0.1", - "cross-env": "^7.0.3", "eslint": "^8.57.0", "eslint-config-next": "^14.1.3", "eslint-config-prettier": "^9.1.0", @@ -5905,24 +5904,6 @@ "url": "https://opencollective.com/core-js" } }, - "node_modules/cross-env": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", - "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.1" - }, - "bin": { - "cross-env": "src/bin/cross-env.js", - "cross-env-shell": "src/bin/cross-env-shell.js" - }, - "engines": { - "node": ">=10.14", - "npm": ">=6", - "yarn": ">=1" - } - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index e2fc626..7540994 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "seed": "node --env-file .env scripts/seed.js", "test": "vitest run", "test:watch": "vitest", - "test:e2e": "cross-env NEXT_PUBLIC_API_MOCKING=enabled playwright test -c ./playwright.config.cjs", - "test:e2e:ui": "cross-env NEXT_PUBLIC_API_MOCKING=enabled playwright test -c ./playwright.config.cjs --ui" + "test:e2e": "playwright test -c ./playwright.config.cjs", + "test:e2e:ui": "playwright test -c ./playwright.config.cjs --ui" }, "dependencies": { "@hookform/resolvers": "^3.3.4", @@ -57,7 +57,6 @@ "@types/node": "^20.11.30", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.0.1", - "cross-env": "^7.0.3", "eslint": "^8.57.0", "eslint-config-next": "^14.1.3", "eslint-config-prettier": "^9.1.0", diff --git a/scripts/seed.js b/scripts/seed.js index 78ab001..36c3fe6 100644 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -1,6 +1,9 @@ import { faker } from "@faker-js/faker" import { MongoClient } from "mongodb" -import { artisticMovements, typesOfBuilding } from "../src/utils/constants.js" +import { + artisticMovements, + typesOfBuilding, +} from "../src/features/places/utils/constants.js" import { generateArray } from "../src/utils/functions.js" const uri = process.env.DATABASE_URL diff --git a/tests/home.spec.js b/tests/home.spec.js new file mode 100644 index 0000000..1b0e053 --- /dev/null +++ b/tests/home.spec.js @@ -0,0 +1,50 @@ +import { expect, test } from "@playwright/test" + +test.beforeEach(async ({ page }) => { + await page.goto("/", { waitUntil: "networkidle" }) +}) + +test("Theme", async ({ page }) => { + await page.getByRole("button", { name: "Toggle theme" }).click() + await page.getByRole("menuitem", { name: "Light" }).click() + await expect(page.locator("html")).toHaveClass("light") + + await page.getByRole("button", { name: "Toggle theme" }).click() + await page.getByRole("menuitem", { name: "Dark" }).click() + await expect(page.locator("html")).toHaveClass("dark") + + await page.getByRole("button", { name: "Toggle theme" }).click() + await page.getByRole("menuitem", { name: "System" }).click() +}) + +test("Create place with dialog", async ({ page }) => { + await page.getByRole("button", { name: "Add" }).click() + await page.getByLabel("Building").click() + await page.getByLabel("Bar").click() + await page.getByPlaceholder("Name of the building....").click() + await page.getByPlaceholder("Name of the building....").fill("Random Name") + await page.getByPlaceholder("Name of the building....").press("Tab") + await page + .getByPlaceholder("Which city are the building ?") + .fill("Random City") + await page.getByPlaceholder("Which city are the building ?").press("Tab") + await page.getByPlaceholder("What is the zipcode ?").fill("12345") + await page.getByPlaceholder("What is the zipcode ?").press("Tab") + await page.getByPlaceholder("Which country are the").fill("Random Country") + await page.getByRole("button", { name: "Next" }).click() + await page.getByLabel("Bar").click() + await page.getByLabel("Cocktail").getByText("Cocktail").click() + + await page.getByRole("button", { name: "Next" }).click() + await page.getByLabel("Create a place").getByText("Bar").click() + await page.getByRole("button", { name: "Finish" }).click() +}) + +test("Pagination", async ({ page }) => { + await expect(page.getByRole("button", { name: "Previous" })).toBeDisabled() + await page.getByRole("button", { name: "Next" }).click() + + await expect(page.getByRole("button", { name: "Previous" })).toBeEnabled() + await page.getByRole("button", { name: "Previous" }).click() + await expect(page.getByRole("button", { name: "Previous" })).toBeDisabled() +})