Skip to content

Commit d68f3db

Browse files
committed
add some basic navigation tests
1 parent 073acd6 commit d68f3db

File tree

8 files changed

+76
-530
lines changed

8 files changed

+76
-530
lines changed

.github/workflows/playwright.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ chimp.js
2121
.DS_Store
2222
.env.local
2323
.env.*.local
24+
.env.test
25+
.env.*.test
2426
/public/env.json
2527

2628
npm-debug.log*
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @ts-check
2+
import { test, expect } from '@playwright/test';
3+
4+
test.describe('Navigation (Logged In)', () => {
5+
test.beforeEach(async ({ page }) => {
6+
// Login before each test
7+
await page.goto('http://localhost:3000');
8+
await page.locator('a').filter({ hasText: 'Sign in' }).click();
9+
await page.getByLabel('Email Address or Username').fill(process.env.REACT_APP_USERNAME || "");
10+
await page.getByLabel('Password').fill(process.env.REACT_APP_PASSWORD || "");
11+
await page.getByRole('button', { name: 'Log in' }).click();
12+
await page.waitForLoadState('networkidle');
13+
await expect(page).toHaveTitle(/MapRoulette/);
14+
});
15+
16+
test('should navigate to Find Chalslenges', async ({ page }) => {
17+
await page.getByRole('navigation').getByRole('link', { name: 'Find Challenges' }).click();
18+
await expect(page.getByRole('heading', { name: 'Challenges' }).locator('span')).toBeVisible();
19+
});
20+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @ts-check
2+
import { test, expect } from '@playwright/test';
3+
4+
test.describe('Navigation (Logged Out)', () => {
5+
6+
test.beforeEach(async ({ page }) => {
7+
await page.goto('http://localhost:3000');
8+
await page.waitForLoadState('networkidle');
9+
await expect(page).toHaveTitle(/MapRoulette/);
10+
});
11+
12+
test('should load find challenges page', async ({ page }) => {
13+
await page.getByRole('navigation').getByRole('link', { name: 'Find Challenges' }).click();
14+
await expect(page.getByRole('heading', { name: 'Challenges' }).locator('span')).toBeVisible();
15+
await expect(page.locator('a').filter({ hasText: 'Sign in' })).toBeVisible();
16+
});
17+
test('should load leaderboard page', async ({ page }) => {
18+
await page.getByRole('navigation').getByRole('link', { name: 'Leaderboard' }).click();
19+
await page.waitForLoadState('networkidle');
20+
});
21+
test('should load learn page', async ({ page }) => {
22+
await page.getByRole('navigation').getByRole('link', { name: 'Learn' }).click();
23+
await page.waitForLoadState('networkidle');
24+
});
25+
test('should load blog page', async ({ page }) => {
26+
await page.getByRole('navigation').getByRole('link', { name: 'Blog' }).click();
27+
await page.waitForLoadState('networkidle');
28+
});
29+
test('should load donate page', async ({ page }) => {
30+
await page.getByRole('navigation').getByRole('link', { name: 'Donate' }).click();
31+
await page.waitForLoadState('networkidle');
32+
});
33+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
"test": "vitest",
148148
"test:cov": "vitest run --coverage",
149149
"lint": "eslint src/",
150-
"explore": "source-map-explorer --only-mapped --no-border-checks 'dist/**/*.js'"
150+
"explore": "source-map-explorer --only-mapped --no-border-checks 'dist/**/*.js'",
151+
"test:e2e":"playwright test --ui"
151152
},
152153
"browserslist": [
153154
">0.2%",

playwright.config.cjs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
// @ts-check
2+
const path = require('path');
23
const { defineConfig, devices } = require('@playwright/test');
3-
44
/**
55
* Read environment variables from file.
66
* https://github.com/motdotla/dotenv
77
*/
8-
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });
8+
require('dotenv').config({ path: path.resolve(__dirname, '.env.local') });
9+
10+
// Validate required environment variables
11+
const requiredEnvVars = ['REACT_APP_USERNAME', 'REACT_APP_PASSWORD'];
12+
requiredEnvVars.forEach(envVar => {
13+
if (!process.env[envVar]) {
14+
throw new Error(`Required environment variable ${envVar} is missing. Please add it to .env.local`);
15+
}
16+
});
917

1018
/**
1119
* @see https://playwright.dev/docs/test-configuration
1220
*/
1321
module.exports = defineConfig({
14-
testDir: './tests',
22+
testDir: './e2eTests',
1523
/* Run tests in files in parallel */
16-
fullyParallel: true,
24+
fullyParallel: false,
1725
/* Fail the build on CI if you accidentally left test.only in the source code. */
1826
forbidOnly: !!process.env.CI,
1927
/* Retry on CI only */
@@ -22,13 +30,17 @@ module.exports = defineConfig({
2230
workers: process.env.CI ? 1 : undefined,
2331
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2432
reporter: 'html',
25-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2633
use: {
27-
/* Base URL to use in actions like `await page.goto('/')`. */
28-
// baseURL: 'http://127.0.0.1:3000',
34+
baseURL: 'http://localhost:3000',
2935

3036
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3137
trace: 'on-first-retry',
38+
39+
// Add environment variables to be available in tests
40+
env: {
41+
REACT_APP_USERNAME: process.env.REACT_APP_USERNAME,
42+
REACT_APP_PASSWORD: process.env.REACT_APP_PASSWORD,
43+
},
3244
},
3345

3446
/* Configure projects for major browsers */
@@ -47,33 +59,6 @@ module.exports = defineConfig({
4759
name: 'webkit',
4860
use: { ...devices['Desktop Safari'] },
4961
},
50-
51-
/* Test against mobile viewports. */
52-
// {
53-
// name: 'Mobile Chrome',
54-
// use: { ...devices['Pixel 5'] },
55-
// },
56-
// {
57-
// name: 'Mobile Safari',
58-
// use: { ...devices['iPhone 12'] },
59-
// },
60-
61-
/* Test against branded browsers. */
62-
// {
63-
// name: 'Microsoft Edge',
64-
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
65-
// },
66-
// {
67-
// name: 'Google Chrome',
68-
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
69-
// },
7062
],
71-
72-
/* Run your local dev server before starting the tests */
73-
// webServer: {
74-
// command: 'npm run start',
75-
// url: 'http://127.0.0.1:3000',
76-
// reuseExistingServer: !process.env.CI,
77-
// },
7863
});
7964

0 commit comments

Comments
 (0)