@@ -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 : / 💌 S u b s c r i b e / 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 : / u n s u b s c r i b e a t a n y t i m e / 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 : / 💌 S u b s c r i b e / 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 : / 💌 S u b s c r i b e / 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 : / 💌 S u b s c r i b e / 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 : / u n s u b s c r i b e a t a n y t i m e / 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 : / 💌 S u b s c r i b e / 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 : / 💌 S u b s c r i b e / 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 ( / N e w s l e t t e r S i g n u p - M i k e B i f u l c o / ) ;
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 : / 💌 S u b s c r i b e / 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 : / 💌 S u b s c r i b e / i } ) ) . toBeFocused ( ) ;
169+ await expect ( page . getByTestId ( 'submit- button') ) . toBeFocused ( ) ;
169170 } ) ;
170171} ) ;
0 commit comments