Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
Binary file modified bun.lockb
Binary file not shown.
23 changes: 23 additions & 0 deletions e2e/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from "@playwright/test"

test.describe("auth page", () => {
test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:3000/auth")
})

test("auth page renders", async ({ page }) => {
await expect(page.getByRole("heading", { name: "Login" })).toBeVisible()
})
})

// test("get started link", async ({ page }) => {
// await page.goto("https://playwright.dev/")

// // Click the get started link.
// await page.getByRole("link", { name: "Get started" }).click()

// // Expects page to have a heading with the name of Installation.
// await expect(
// page.getByRole("heading", { name: "Installation" }),
// ).toBeVisible()
// })
29 changes: 29 additions & 0 deletions e2e/landing.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test } from "@playwright/test"

test.describe("landing page", () => {
test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:3000/")
})

test("landing page renders", async ({ page }) => {
await expect(page.getByRole("heading", { name: "KeepArr" })).toBeVisible()
})

test("dark mode toggle works", async ({ page }) => {
await page.getByRole("button", { name: "Toggle Theme" }).click()

await page.getByRole("menuitem", { name: "Dark" }).click()

await expect(page.locator("html").first()).toHaveClass("dark")
})

test("it goes to the auth page from the landing", async ({ page }) => {
await page.locator("button[data-testid=nav-menu]").click()

await page.locator("a[href='/auth']").click()

await page.waitForTimeout(1000)

await expect(page.url()).toBe("http://localhost:3000/auth")
})
})
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "vitest",
"format": "prettier --check --ignore-path .gitignore .",
"format:fix": "prettier --write --ignore-path .gitignore .",
"prepare": "husky"
Expand Down Expand Up @@ -35,9 +36,12 @@
"@commitlint/cli": "^19.1.0",
"@commitlint/config-conventional": "^19.1.0",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
"@playwright/test": "^1.42.1",
"@testing-library/react": "^14.2.1",
"@types/node": "^20",
"@types/react": "^18.2.52",
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10",
"eslint": "^8",
"eslint-config-next": "latest",
Expand All @@ -46,11 +50,13 @@
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-tailwindcss": "^3.15.1",
"husky": "^9.0.11",
"jsdom": "^24.0.0",
"postcss": "^8",
"prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.11",
"pretty-quick": "^4.0.0",
"tailwindcss": "^3",
"typescript": "^5"
"typescript": "^5",
"vitest": "^1.3.1"
}
}
77 changes: 77 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from "@playwright/test"

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./e2e",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

// {
// name: "firefox",
// use: { ...devices["Desktop Firefox"] },
// },

// {
// name: "webkit",
// use: { ...devices["Desktop Safari"] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: "bun run turbo",
// url: "http://localhost:3000",
// reuseExistingServer: !process.env.CI,
// },
})
1 change: 1 addition & 0 deletions src/app/(landing)/_components/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function SMNav({ Items }: { Items: ReactElement }) {
<Button
variant={"plain"}
size={"icon"}
data-testid="nav-menu"
className="aspect-square rounded-full border border-black/40 hover:border-black/80 dark:border-white/40 dark:hover:border-white/80"
>
<svg className="size-6 " fill="currentColor" viewBox="0 0 20 20">
Expand Down
Loading
Loading