Skip to content

Commit 12f0a80

Browse files
authored
Merge pull request #25 from StreetSupport/staging
Staging > main
2 parents 06eee32 + 8c14f7d commit 12f0a80

File tree

5 files changed

+184
-308
lines changed

5 files changed

+184
-308
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Unit
22
on:
33
push:
44
branches: [main, staging]

e2e/find-help.spec.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,75 @@
11
import { test, expect } from '@playwright/test';
22

33
test.describe('Find Help Page', () => {
4-
test('loads and shows postcode input', async ({ page }) => {
4+
5+
test('should load the Find Help page and show fallback form when geolocation is blocked', async ({ context, page }) => {
6+
await context.grantPermissions([], { origin: 'http://localhost:3000' });
57
await page.goto('/find-help');
68

9+
await expect(page.getByRole('heading', { name: /find help near you/i })).toBeVisible();
710
await expect(page.getByLabel('Enter your postcode')).toBeVisible();
811
await expect(page.getByRole('button', { name: /continue/i })).toBeVisible();
912
});
10-
});
13+
14+
test('should allow postcode entry and show service results', async ({ context, page }) => {
15+
await context.grantPermissions([], { origin: 'http://localhost:3000' });
16+
await page.goto('/find-help');
17+
18+
await page.getByLabel('Enter your postcode').fill('M1 1AE');
19+
await page.getByRole('button', { name: /continue/i }).click();
20+
21+
await expect(page.getByText(/services near you/i)).toBeVisible();
22+
});
23+
24+
test('should allow selecting category and subcategory', async ({ context, page }) => {
25+
await context.grantPermissions([], { origin: 'http://localhost:3000' });
26+
27+
await page.route('/api/get-categories', async (route) => {
28+
route.fulfill({
29+
status: 200,
30+
contentType: 'application/json',
31+
body: JSON.stringify([
32+
{
33+
key: 'health',
34+
name: 'Health',
35+
subCategories: [
36+
{ key: 'gp', name: 'GP' },
37+
{ key: 'dentist', name: 'Dentist' }
38+
],
39+
},
40+
]),
41+
});
42+
});
43+
44+
await page.goto('/find-help');
45+
46+
await page.getByLabel('Enter your postcode').fill('M1 1AE');
47+
await page.getByRole('button', { name: /continue/i }).click();
48+
49+
await expect(page.getByLabel('Category')).toBeVisible();
50+
await page.locator('#category').selectOption('health');
51+
52+
await expect(page.getByLabel('Subcategory')).toBeVisible();
53+
await page.selectOption('#subCategory', 'gp');
54+
});
55+
56+
test('should toggle map visibility', async ({ context, page }) => {
57+
await context.grantPermissions([], { origin: 'http://localhost:3000' });
58+
await page.goto('/find-help');
59+
60+
await page.getByLabel('Enter your postcode').fill('M1 1AE');
61+
await page.getByRole('button', { name: /continue/i }).click();
62+
63+
await page.getByRole('button', { name: /show map/i }).click();
64+
await expect(page.getByText('🗺️ Map is toggled ON')).toBeVisible();
65+
});
66+
67+
test('should show service cards when services are matched', async ({ context, page }) => {
68+
await context.setGeolocation({ latitude: 53.4808, longitude: -2.2426 });
69+
await context.grantPermissions(['geolocation']);
70+
await page.goto('/find-help');
71+
72+
await expect(page.locator('[data-testid="service-card"]').first()).toBeVisible();
73+
});
74+
75+
});

jest.setup.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// jest.setup.ts
22
import '@testing-library/jest-dom';
33

4-
// Provide a global fetch mock for components using fetch
4+
// Mock global fetch
55
global.fetch = jest.fn(() =>
66
Promise.resolve({
77
json: () => Promise.resolve([
@@ -25,10 +25,13 @@ global.fetch = jest.fn(() =>
2525
})
2626
) as jest.Mock;
2727

28-
// Suppress React act(...) warnings globally (Jest syntax)
28+
// Suppress React act(...) warnings globally
29+
const originalError = console.error;
30+
2931
beforeAll(() => {
30-
jest.spyOn(console, 'error').mockImplementation((msg) => {
32+
jest.spyOn(console, 'error').mockImplementation((...args) => {
33+
const [msg] = args;
3134
if (typeof msg === 'string' && msg.includes('not wrapped in act')) return;
32-
console.error(msg);
35+
originalError(...args);
3336
});
3437
});

0 commit comments

Comments
 (0)