forked from freeCodeCamp/Developer_Quiz_Site
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
314 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [main, master, add-first-e2e-test] | ||
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 install -g pnpm && pnpm install | ||
- name: Install Playwright Browsers | ||
run: pnpm exec playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: pnpm exec playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx pretty-quick --staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://localhost:3000/#/quizzes"); | ||
|
||
await page.getByRole("button", { name: "HTML" }).click(); | ||
|
||
await page.getByRole("button", { name: "10", exact: true }).click(); | ||
}); | ||
|
||
test("after answer all the questions user should see 'results' page", async ({ | ||
page | ||
}) => { | ||
// loop through all the questions. | ||
for (let i = 1; i <= 10; i++) { | ||
// Select the first optino (no matter if it right or worng) | ||
await page.getByRole("button").nth(0).click(); | ||
|
||
// Click the submit button | ||
await page.getByRole("button").nth(4).click(); | ||
|
||
await expect(page.getByRole("dialog")).toBeVisible(); | ||
// Find the modal-dialog element | ||
const modalDialog = await page.$(".modal-dialog"); | ||
|
||
// Ensure the modal-dialog element exists | ||
expect(modalDialog).not.toBeNull(); | ||
|
||
// Find the button inside the modal-dialog element | ||
const button = await modalDialog.$("button"); | ||
// Click submit | ||
await button.click(); | ||
|
||
if (i === 10) { | ||
expect(page.url()).toContain("results"); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
const CATEGORIES = [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"Accessibility", | ||
"General CS", | ||
"IT", | ||
"Linux", | ||
"Python", | ||
"SQL", | ||
"Random" | ||
] as const; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://localhost:3000/#/quizzes"); | ||
}); | ||
|
||
test("select category page has full list of categories", async ({ page }) => { | ||
// Make sure the list has all the categores. | ||
await expect(page.getByRole("button")).toHaveText(CATEGORIES); | ||
}); | ||
|
||
test("clicking HTML category should lead to select-questions-number page ", async ({ | ||
page | ||
}) => { | ||
await page.getByRole("button", { name: "HTML" }).click(); | ||
|
||
expect(page.url()).toContain("HTML"); | ||
|
||
await expect( | ||
page.getByRole("heading", { name: "Choose a length for the Quiz" }) | ||
).toBeVisible(); | ||
|
||
// should display numbers options | ||
const buttons = await page.$$eval("button", buttons => | ||
buttons.map(button => button.textContent.trim()) | ||
); | ||
|
||
// Define the expected button texts | ||
const expectedButtonTexts = ["10", "25", "50", "100"]; | ||
|
||
// Check if the page contains the expected number of buttons | ||
expect(buttons.length).toBe(5); | ||
|
||
// Check if the buttons have the expected text content | ||
expect(buttons).toEqual(expect.arrayContaining(expectedButtonTexts)); | ||
|
||
expect(buttons[4]).toContain("All"); | ||
}); | ||
|
||
test("clicking '10' option should lead to question page ", async ({ page }) => { | ||
await page.getByRole("button", { name: "HTML" }).click(); | ||
|
||
await page.getByRole("button", { name: "10", exact: true }).click(); | ||
|
||
expect(page.url()).toContain("questions/1/of/10"); | ||
|
||
await expect(page.getByRole("heading", { name: "Question 1" })).toBeVisible(); | ||
}); | ||
|
||
test("question page should contain 4 options and `submit` button", async ({ | ||
page | ||
}) => { | ||
await page.getByRole("button", { name: "HTML" }).click(); | ||
|
||
await page.getByRole("button", { name: "10", exact: true }).click(); | ||
|
||
// Get all buttons at 'question' page | ||
const buttons = await page.$$("button"); | ||
|
||
// Check if the page contains exactly 5 buttons | ||
expect(buttons.length).toBe(5); | ||
|
||
const lastButtonText = await buttons[4].textContent(); | ||
|
||
expect(lastButtonText).toBe("Submit"); | ||
}); | ||
|
||
test("should show modal after selecting one option and click the `submit` button", async ({ | ||
page | ||
}) => { | ||
await page.getByRole("button", { name: "HTML" }).click(); | ||
|
||
await page.getByRole("button", { name: "10", exact: true }).click(); | ||
|
||
// Select the first optino (no matter if it right or worng) | ||
await page.getByRole("button").nth(0).click(); | ||
|
||
// Click the submit button | ||
await page.getByRole("button").nth(4).click(); | ||
|
||
await expect(page.getByRole("dialog")).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://localhost:3000/"); | ||
}); | ||
|
||
test("has title", async ({ page }) => { | ||
// Expect a title "to contain" a substring. | ||
await expect(page).toHaveTitle(/Developer Quiz/); | ||
}); | ||
|
||
test("pressing get started link should lead to select categories page", async ({ | ||
page | ||
}) => { | ||
// Click the get started link. | ||
await page.getByRole("link", { name: "Get started (it's free)" }).click(); | ||
|
||
expect(page.url()).toContain("quizzes"); | ||
// Expects page to have a heading that says 'Choose a Category'. | ||
await expect( | ||
page.getByRole("heading", { name: "Choose a Category" }) | ||
).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* 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: "npm run start", | ||
url: "http://127.0.0.1:3000", | ||
reuseExistingServer: !process.env.CI | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.