Skip to content

Commit

Permalink
Setup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darashi committed Mar 8, 2024
1 parent 34fb9a1 commit f50321e
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Build Frontend
run: npm run build
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
Expand Down
18 changes: 0 additions & 18 deletions e2e/example.spec.ts

This file was deleted.

23 changes: 23 additions & 0 deletions e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test, expect } from "@playwright/test";

test.describe("login", () => {
test("bad password", async ({ page }) => {
await page.goto("/-login");

await page.fill("input[id=password]", "bad-password");
await page.getByRole("button", { name: "Login" }).click();
await expect(page.getByRole("alert")).toContainText("Authenitacion failed");
});

test("successful login and logout", async ({ page }) => {
await page.goto("/-login");

await page.fill("input[id=password]", "admin-password");
await page.getByRole("button", { name: "Login" }).click();

await expect(page).toHaveURL("/");

await page.getByRole("link", { name: "Logout" }).click();
await expect(page.getByRole("link", { name: "Login" })).toBeVisible();
});
});
37 changes: 37 additions & 0 deletions e2e/top.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { test, expect } from "@playwright/test";

test.describe("/", () => {
test("navigation", async ({ page }) => {
await page.goto("/");

await expect(page.getByRole("navigation")).toContainText("SPARQList");
await expect(page.getByRole("link", { name: "Login" })).toBeVisible();
});

test("navigate to login", async ({ page }) => {
await page.goto("/");
await page.click("text=Login");

await expect(page).toHaveURL("/-login");
});

test("search", async ({ page }) => {
await page.goto("/");

await expect(
page.getByRole("link", { name: "gene_and_organism_annotation" }),
).toBeVisible();
await expect(
page.getByRole("link", { name: "adjacent_prefectures -" }),
).toBeVisible();

await page.fill("input[type=search]", "ge");

await expect(
page.getByRole("link", { name: "gene_and_organism_annotation" }),
).toBeVisible();
await expect(
page.getByRole("link", { name: "adjacent_prefectures -" }),
).not.toBeVisible();
});
});
116 changes: 58 additions & 58 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test';
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
Expand All @@ -10,68 +10,68 @@ import { defineConfig, devices } from '@playwright/test';
* 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',
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',
},
/* 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'] },
},
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

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

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// {
// 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 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' },
// },
],
/* 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,
// },
/* Run your local dev server before starting the tests */
webServer: {
command: "env ADMIN_PASSWORD=admin-password npm run start",
url: "http://127.0.0.1:3000",
reuseExistingServer: !process.env.CI,
},
});

0 comments on commit f50321e

Please sign in to comment.