Skip to content

Commit e7b7c2b

Browse files
committed
fix: tests and page design
1 parent 4a3b8c4 commit e7b7c2b

21 files changed

Lines changed: 506 additions & 396 deletions

e2e/newsletter-signup.spec.ts

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,44 @@ test.describe('Newsletter Signup Page', () => {
88
await route.fulfill({
99
status: 400,
1010
contentType: 'application/json',
11-
body: JSON.stringify([{
12-
error: {
13-
message: 'Subscription failed',
14-
code: -32600,
15-
data: {
16-
code: 'BAD_REQUEST',
17-
httpStatus: 400
18-
}
19-
}
20-
}])
11+
body: JSON.stringify([
12+
{
13+
error: {
14+
message: 'Subscription failed',
15+
code: -32600,
16+
data: {
17+
code: 'BAD_REQUEST',
18+
httpStatus: 400,
19+
},
20+
},
21+
},
22+
]),
2123
});
2224
});
23-
24-
await page.goto('/newsletter-signup');
25+
26+
await page.goto('/subscribe');
2527
});
2628

27-
test('should render the newsletter signup page correctly', async ({ page }) => {
29+
test('should render the newsletter signup page correctly', async ({
30+
page,
31+
}) => {
2832
// Check page elements are visible
29-
await expect(page.locator('h1')).toContainText('Get the newsletter');
30-
await expect(page.locator('h2')).toContainText('💌 Tiny Improvements');
31-
await expect(page.getByText('Straight to your inbox, once a week')).toBeVisible();
33+
await expect(page.getByTestId('newsletter-title')).toContainText(' devs & founders building better.');
3234

3335
// Check form elements
34-
await expect(page.getByPlaceholder('First Name')).toBeVisible();
35-
await expect(page.getByPlaceholder('Email Address')).toBeVisible();
36-
await expect(page.getByRole('button', { name: /💌 Subscribe/i })).toBeVisible();
36+
await expect(page.getByTestId('first-name-input')).toBeVisible();
37+
await expect(page.getByTestId('email-input')).toBeVisible();
38+
await expect(page.getByTestId('submit-button')).toBeVisible();
3739

3840
// Check privacy disclaimer
39-
await expect(page.getByText("I'll never sell your contact info")).toBeVisible();
40-
await expect(page.getByRole('link', { name: /unsubscribe at any time/i })).toBeVisible();
41+
await expect(page.getByTestId('privacy-link')).toBeVisible();
42+
await expect(page.getByTestId('unsubscribe-text')).toBeVisible();
4143
});
4244

43-
44-
test('should show validation errors for empty form submission', async ({ page }) => {
45-
const submitButton = page.getByRole('button', { name: /💌 Subscribe/i });
45+
test('should show validation errors for empty form submission', async ({
46+
page,
47+
}) => {
48+
const submitButton = page.getByTestId('submit-button');
4649
await submitButton.click();
4750

4851
// Check validation error messages appear
@@ -51,9 +54,9 @@ test.describe('Newsletter Signup Page', () => {
5154
});
5255

5356
test('should show validation error for invalid email', async ({ page }) => {
54-
const firstNameInput = page.getByPlaceholder('First Name');
55-
const emailInput = page.getByPlaceholder('Email Address');
56-
const submitButton = page.getByRole('button', { name: /💌 Subscribe/i });
57+
const firstNameInput = page.getByTestId('first-name-input');
58+
const emailInput = page.getByTestId('email-input');
59+
const submitButton = page.getByTestId('submit-button');
5760

5861
await firstNameInput.fill('John');
5962
await emailInput.fill('not-an-email-at-all');
@@ -66,17 +69,17 @@ test.describe('Newsletter Signup Page', () => {
6669

6770
// The form should submit successfully since validation happens server-side
6871
// Check that we can still see the form (indicating it didn't navigate away)
69-
await expect(page.getByPlaceholder('Email Address')).toBeVisible();
72+
await expect(page.getByTestId('email-input')).toBeVisible();
7073

7174
// Check that the form fields are cleared (indicating successful submission)
7275
await expect(emailInput).toHaveValue('');
7376
await expect(firstNameInput).toHaveValue('');
7477
});
7578

7679
test('should handle form submission with valid data', async ({ page }) => {
77-
const firstNameInput = page.getByPlaceholder('First Name');
78-
const emailInput = page.getByPlaceholder('Email Address');
79-
const submitButton = page.getByRole('button', { name: /💌 Subscribe/i });
80+
const firstNameInput = page.getByTestId('first-name-input');
81+
const emailInput = page.getByTestId('email-input');
82+
const submitButton = page.getByTestId('submit-button');
8083

8184
await firstNameInput.fill('John');
8285
await emailInput.fill('test@example.com');
@@ -92,79 +95,77 @@ test.describe('Newsletter Signup Page', () => {
9295
await expect(firstNameInput).toHaveValue('');
9396
});
9497

95-
test('should accept valid form input without validation errors', async ({ page }) => {
96-
const firstNameInput = page.getByPlaceholder('First Name');
97-
const emailInput = page.getByPlaceholder('Email Address');
98+
test('should accept valid form input without validation errors', async ({
99+
page,
100+
}) => {
101+
const firstNameInput = page.getByTestId('first-name-input');
102+
const emailInput = page.getByTestId('email-input');
98103

99104
await firstNameInput.fill('John');
100105
await emailInput.fill('john@example.com');
101106

102107
// Validation errors should not be present
103108
await expect(page.getByText('First name is required')).not.toBeVisible();
104109
await expect(page.getByText('Email is required')).not.toBeVisible();
105-
await expect(page.getByText('Please enter a valid email address')).not.toBeVisible();
110+
await expect(
111+
page.getByText('Please enter a valid email address')
112+
).not.toBeVisible();
106113
});
107114

108-
test('should have working newsletter link in disclaimer', async ({ page }) => {
109-
const newsletterLink = page.getByRole('link', { name: /unsubscribe at any time/i });
110-
await expect(newsletterLink).toHaveAttribute('href', '/newsletter');
111-
112-
// Test navigation (but don't actually navigate to avoid breaking test isolation)
113-
const href = await newsletterLink.getAttribute('href');
114-
expect(href).toBe('/newsletter');
115-
});
116115

117116
test('should have proper form accessibility', async ({ page }) => {
118117
// Check form labels are properly associated
119-
const firstNameInput = page.getByPlaceholder('First Name');
120-
const emailInput = page.getByPlaceholder('Email Address');
118+
const firstNameInput = page.getByTestId('first-name-input');
119+
const emailInput = page.getByTestId('email-input');
121120

122121
// Check inputs have proper IDs and labels (even if sr-only)
123122
await expect(firstNameInput).toHaveAttribute('id', 'firstName');
124123
await expect(emailInput).toHaveAttribute('id', 'email');
125124

126125
// Check submit button is properly labeled
127-
const submitButton = page.getByRole('button', { name: /💌 Subscribe/i });
126+
const submitButton = page.getByTestId('submit-button');
128127
await expect(submitButton).toHaveAttribute('type', 'submit');
129128
});
130129

131130
test('should handle form submission button states', async ({ page }) => {
132-
const firstNameInput = page.getByPlaceholder('First Name');
133-
const emailInput = page.getByPlaceholder('Email Address');
134-
const submitButton = page.getByRole('button', { name: /💌 Subscribe/i });
131+
const firstNameInput = page.getByTestId('first-name-input');
132+
const emailInput = page.getByTestId('email-input');
133+
const submitButton = page.getByTestId('submit-button');
135134

136135
// Fill valid data
137136
await firstNameInput.fill('John');
138137
await emailInput.fill('john@example.com');
139138

140139
// Button should be enabled with valid data
141140
await expect(submitButton).not.toBeDisabled();
142-
await expect(submitButton).toContainText('💌 Subscribe');
141+
await expect(submitButton).toContainText('💌 Get the newsletter');
143142
});
144143

145-
test('should have correct page title and meta description', async ({ page }) => {
144+
test('should have correct page title and meta description', async ({
145+
page,
146+
}) => {
146147
await expect(page).toHaveTitle(/Newsletter Signup - Mike Bifulco/);
147148
});
148149

149150
test('should be responsive on mobile viewport', async ({ page }) => {
150151
await page.setViewportSize({ width: 375, height: 667 }); // iPhone SE size
151152

152153
// Check that elements are still visible and properly arranged
153-
await expect(page.locator('h1')).toContainText('Get the newsletter');
154-
await expect(page.getByPlaceholder('First Name')).toBeVisible();
155-
await expect(page.getByPlaceholder('Email Address')).toBeVisible();
156-
await expect(page.getByRole('button', { name: /💌 Subscribe/i })).toBeVisible();
154+
await expect(page.getByTestId('newsletter-title')).toContainText('devs & founders building better.');
155+
await expect(page.getByTestId('first-name-input')).toBeVisible();
156+
await expect(page.getByTestId('email-input')).toBeVisible();
157+
await expect(page.getByTestId('submit-button')).toBeVisible();
157158
});
158159

159160
test('should maintain focus management', async ({ page }) => {
160161
// Tab through form elements
161162
await page.keyboard.press('Tab'); // Should focus first input
162-
await expect(page.getByPlaceholder('First Name')).toBeFocused();
163+
await expect(page.getByTestId('first-name-input')).toBeFocused();
163164

164165
await page.keyboard.press('Tab'); // Should focus second input
165-
await expect(page.getByPlaceholder('Email Address')).toBeFocused();
166+
await expect(page.getByTestId('email-input')).toBeFocused();
166167

167168
await page.keyboard.press('Tab'); // Should focus submit button
168-
await expect(page.getByRole('button', { name: /💌 Subscribe/i })).toBeFocused();
169+
await expect(page.getByTestId('submit-button')).toBeFocused();
169170
});
170171
});

e2e/smoke.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ test('404 error page smoke test', async ({ page }) => {
3737
// Check for the default Next.js 404 page in development mode
3838
await expect(page.locator('h1')).toContainText('404');
3939
await expect(
40-
page.locator(
41-
"text=This page could not be found."
42-
)
40+
page.locator('text=This page could not be found.')
4341
).toBeVisible();
4442
});

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import localFont from 'next/font/local';
22
import { Toaster } from 'sonner';
33

44
import FathomAnalytics from '@components/Analytics/Fathom';
5+
import { env } from '@utils/env';
56
import PostHogProvider from './posthog-provider';
67
import TRPCProvider from './trpc-provider';
7-
import { env } from '@utils/env';
88

99
import '../styles/globals.css';
1010
import '../components/CarbonAd/CarbonAd.css';
@@ -50,4 +50,4 @@ export default function RootLayout({
5050
</body>
5151
</html>
5252
);
53-
}
53+
}

src/app/newsletter-signup/layout.tsx

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

0 commit comments

Comments
 (0)