Skip to content

Commit c112bad

Browse files
authored
Merge pull request #5 from kevinkace/feat/tests
Feat/tests
2 parents a3bc38d + a7e2098 commit c112bad

21 files changed

Lines changed: 519 additions & 238 deletions

e2e/about.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { test } from '@playwright/test';
2+
import { expectH1AndTitle, expectSections, expectLinks } from './lib/lib';
3+
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/about-us');
6+
});
7+
8+
test.describe('About', () => {
9+
test('has expected content', async ({ page }) => {
10+
await expectH1AndTitle({
11+
page,
12+
h1 : "Local Connectivity Lab",
13+
title: "About Us - Seattle Community Network"
14+
});
15+
16+
await expectSections({
17+
page,
18+
pageName: 'about-us',
19+
sections: [
20+
"lcl",
21+
'mission',
22+
'vision',
23+
'values',
24+
'social'
25+
]
26+
});
27+
});
28+
29+
test('main CTAs link correctly', async ({ page }) => {
30+
await expectLinks({
31+
page,
32+
pageName: 'about-us',
33+
links: [
34+
{
35+
linkLocator: 'donate-cta',
36+
destLocator: 'h1',
37+
destText : "Make a Donation"
38+
}
39+
]
40+
});
41+
});
42+
});

e2e/demo.test.ts

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

e2e/donate.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect, test } from '@playwright/test';
2+
import { expectH1AndTitle } from './lib/lib';
3+
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/donate/');
6+
});
7+
8+
test.describe('Donate', () => {
9+
test('has expected content', async ({ page }) => {
10+
await expectH1AndTitle({
11+
page,
12+
h1 : "Make a Donation",
13+
title: "Donate - Seattle Community Network"
14+
});
15+
});
16+
17+
test('donation CTAs work', async ({ page }) => {
18+
const buttonLocators = [
19+
{
20+
linkLocator : 'data-test=donate-paypal',
21+
destLocator : 'Local Connectivity Lab'
22+
},
23+
{
24+
linkLocator : 'data-test=donate-gofundme',
25+
destLocator : 'Local Connectivity Lab'
26+
},
27+
{
28+
linkLocator : 'data-test=donate-square',
29+
destLocator : 'Seattle Community Network'
30+
},
31+
];
32+
33+
for (const {linkLocator, destLocator} of buttonLocators) {
34+
const cta = page.locator(linkLocator);
35+
36+
await expect(page.locator(linkLocator)).toBeVisible();
37+
await cta.click();
38+
await expect(page.locator('body')).toContainText(destLocator);
39+
40+
await page.goBack();
41+
}
42+
});
43+
});

e2e/home.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { expect, test } from '@playwright/test';
2+
import { expectH1AndTitle, expectLinks, expectSections } from './lib/lib';
3+
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/');
6+
});
7+
8+
test.describe('Home', () => {
9+
test('has expected content', async ({ page }) => {
10+
await expectSections({
11+
page,
12+
pageName: 'home',
13+
sections: [
14+
'carousel',
15+
'hero',
16+
'building-image',
17+
'overview',
18+
'get-involved',
19+
'calendar',
20+
'partners',
21+
]
22+
});
23+
24+
await expectH1AndTitle({
25+
page,
26+
h1 : "Seattle Community Network",
27+
title: "Seattle Community Network"
28+
});
29+
});
30+
31+
test('main CTAs link correctly', async ({ page }) => {
32+
await expectLinks({
33+
page,
34+
pageName: 'home',
35+
links: [
36+
{
37+
linkLocator: 'hero-cta',
38+
destLocator: 'h1#join-us'
39+
},
40+
{
41+
linkLocator: 'overview-cta',
42+
destLocator: 'h1#seattle-community-network-docs'
43+
},
44+
{
45+
linkLocator: 'involved-volunteer-cta',
46+
destLocator: 'h1#join-us'
47+
},
48+
{
49+
linkLocator: 'involved-connect-cta',
50+
destLocator: 'h1',
51+
destText : /Our Sites|Get Connected/
52+
}
53+
]
54+
});
55+
});
56+
57+
test('google calendar iframe is loaded', async ({ page }) => {
58+
await expect(page.locator('iframe[src*="calendar.google.com"]')).toBeVisible();
59+
});
60+
61+
test('partners section has image', async ({ page }) => {
62+
const partnersImage = page.locator('[data-test=home-partners] img');
63+
64+
await expect(partnersImage).toBeVisible();
65+
});
66+
});

e2e/layout.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test.beforeEach(async ({ page }) => {
4+
await page.goto('/');
5+
});
6+
7+
test.describe('Layout', () => {
8+
test('has expected header and footer content', async ({ page }) => {
9+
await expect(page.locator('data-test=site-header')).toBeVisible();
10+
await expect(page.locator('data-test=site-footer')).toBeVisible();
11+
});
12+
13+
test('header links work correctly', async ({ page }) => {
14+
const logoLink = page.locator('data-test=site-logo-link');
15+
await expect(logoLink).toBeVisible();
16+
await logoLink.click();
17+
await expect(page).toHaveURL('/');
18+
});
19+
20+
test('navigation menu is present', async ({ page }) => {
21+
const navMenu = page.locator('data-test=site-nav');
22+
await expect(navMenu).toBeVisible();
23+
});
24+
});

e2e/lib/lib.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect } from '@playwright/test';
2+
3+
/**
4+
* Helper function to verify the presence of multiple sections on a page.
5+
*/
6+
export async function expectSections({ page, pageName, sections } : {
7+
page: import('@playwright/test').Page,
8+
pageName: string,
9+
sections: string[],
10+
}) {
11+
for (const section of sections) {
12+
const locator = `data-test=${pageName}-${section}`;
13+
await expect(page.locator(locator)).toBeVisible();
14+
}
15+
}
16+
17+
export async function expectH1AndTitle({ page, h1, title } : {
18+
page: import('@playwright/test').Page,
19+
h1: string | RegExp,
20+
title: string | RegExp,
21+
}) {
22+
await expect(page.locator('h1')).toHaveText(h1);
23+
await expect(page).toHaveTitle(title);
24+
}
25+
26+
export async function expectLinks({ page, pageName, links } : {
27+
page: import('@playwright/test').Page,
28+
pageName: string,
29+
links: { linkLocator: string, destLocator: string, destText?: string | RegExp }[],
30+
}) {
31+
for (const { linkLocator, destLocator, destText } of links) {
32+
const link = page.locator(`data-test=${pageName}-${linkLocator}`);
33+
34+
await link.click();
35+
await expect(page.locator(destLocator)).toBeVisible();
36+
37+
if (destText !== undefined) {
38+
await expect(page.locator(destLocator)).toHaveText(destText);
39+
}
40+
41+
// go back to the previous page for the next link test
42+
await page.goBack();
43+
}
44+
}

e2e/our-sites.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { expect, test } from '@playwright/test';
2+
import { expectH1AndTitle, expectSections, expectLinks } from './lib/lib';
3+
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/our-sites');
6+
});
7+
8+
test.describe('Our Sites', () => {
9+
test('has expected content', async ({ page }) => {
10+
await expectSections({
11+
page,
12+
pageName: 'our-sites',
13+
sections: [
14+
'overview',
15+
'details',
16+
'eligibility',
17+
'locations',
18+
'map',
19+
]
20+
});
21+
22+
await expectH1AndTitle({
23+
page,
24+
h1 : "Get Connected",
25+
title: "Get Connected - Seattle Community Network"
26+
});
27+
});
28+
29+
// skip for now, destination page is down
30+
test.skip('main CTAs link correctly', async ({ page }) => {
31+
await expectLinks({
32+
page,
33+
pageName: 'our-sites',
34+
links: [
35+
{
36+
linkLocator: 'map-cta',
37+
destLocator: 'h1'
38+
}
39+
]
40+
});
41+
});
42+
43+
test('google map iframe is loaded', async ({ page }) => {
44+
await expect(page.locator('iframe[src*="google.com/maps"]')).toBeVisible();
45+
});
46+
});

messages/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
"pages.sites.title": "Get Connected",
121121

122-
"pages.sites.overview.header": "Overview",
122+
"pages.sites.overview.header": "Get Connected",
123123
"pages.sites.overview.paragraphs.0": "Through our volunteer efforts and community partnerships, we strive to provide low-income and in-need users with free or low-cost Internet service as reliably as possible. Our service is best-effort and will not necessarily match the performance of paid or commercial Internet service.",
124124
"pages.sites.overview.paragraphs.1": "Our network includes site locations throughout King County and Tacoma, where we are able to provide coverage within specific neighborhoods near the sites. Please refer to the list of locations below to see if your neighborhood is covered.",
125125
"pages.sites.overview.paragraphs.2": "Within these coverage areas, we can offer either home-based WiFi or mobile (phone-based) Internet access options.",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1313
"lint": "eslint .",
1414
"test:e2e": "playwright test",
15+
"test:ui" : "playwright test --ui",
1516
"test": "npm run test:e2e",
1617
"deploy": "npm run build && gh-pages -d build -t",
1718
"redirects": "node create-redirects.js"

playwright.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { defineConfig } from '@playwright/test';
22

33
export default defineConfig({
4-
webServer: {
5-
command: 'npm run build && npm run preview',
6-
port: 4173
4+
// webServer: {
5+
// command: 'npm run build && npm run preview',
6+
// port: 4173
7+
// },
8+
use: {
9+
baseURL: "http://localhost:5173"
710
},
811
testDir: 'e2e'
912
});

0 commit comments

Comments
 (0)