Skip to content

Commit f788bcc

Browse files
committed
refactor(e2e): share LegacyCustomerAccountUtil via describe-scoped let
What: Eliminate repeated instantiation of the stateless utility class. Why: Both test files created a new LegacyCustomerAccountUtil(page) in every single test body despite beforeEach hooks already creating one for navigation. Since the class is stateless (just a wrapper around page), re-instantiating per test adds cognitive noise without isolation benefit. How: Declare a let-scoped variable in each describe block, assign it in beforeEach, and reuse it across tests. Tests that only use recipe methods (no direct page assertions) drop the unused {page} destructure. Tests that still need page for URL assertions keep it. Logout and Header Navigation blocks are left as-is since they have 1-2 tests each.
1 parent 1baf9bd commit f788bcc

File tree

2 files changed

+35
-49
lines changed

2 files changed

+35
-49
lines changed

e2e/specs/recipes/legacy-customer-account-flow-auth.spec.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,37 @@ test.describe('Legacy Customer Account Flow — Authenticated', () => {
7676
});
7777

7878
test.describe('Orders Page', () => {
79+
let recipe: LegacyCustomerAccountUtil;
80+
7981
test.beforeEach(async ({page}) => {
80-
const recipe = new LegacyCustomerAccountUtil(page);
82+
recipe = new LegacyCustomerAccountUtil(page);
8183
await recipe.navigateToOrders();
8284
});
8385

84-
test('renders welcome heading with customer first name', async ({page}) => {
85-
const recipe = new LegacyCustomerAccountUtil(page);
86+
test('renders welcome heading with customer first name', async () => {
8687
await expect(
8788
recipe.getWelcomeHeading(LEGACY_CUSTOMER_MOCK.firstName),
8889
).toBeVisible();
8990
});
9091

91-
test('shows empty orders message with start shopping link', async ({
92-
page,
93-
}) => {
94-
const recipe = new LegacyCustomerAccountUtil(page);
92+
test('shows empty orders message with start shopping link', async () => {
9593
await recipe.assertEmptyOrders();
9694
});
9795

98-
test('displays account navigation menu', async ({page}) => {
99-
const recipe = new LegacyCustomerAccountUtil(page);
96+
test('displays account navigation menu', async () => {
10097
await recipe.assertAccountMenuLinks();
10198
});
10299
});
103100

104101
test.describe('Profile Page', () => {
102+
let recipe: LegacyCustomerAccountUtil;
103+
105104
test.beforeEach(async ({page}) => {
106-
const recipe = new LegacyCustomerAccountUtil(page);
105+
recipe = new LegacyCustomerAccountUtil(page);
107106
await recipe.navigateToProfile();
108107
});
109108

110-
test('renders profile form pre-filled with customer data', async ({
111-
page,
112-
}) => {
113-
const recipe = new LegacyCustomerAccountUtil(page);
109+
test('renders profile form pre-filled with customer data', async () => {
114110
await recipe.assertProfilePageRendered({
115111
firstName: LEGACY_CUSTOMER_MOCK.firstName,
116112
lastName: LEGACY_CUSTOMER_MOCK.lastName,
@@ -119,53 +115,51 @@ test.describe('Legacy Customer Account Flow — Authenticated', () => {
119115
});
120116
});
121117

122-
test('shows marketing preferences checkbox', async ({page}) => {
123-
const recipe = new LegacyCustomerAccountUtil(page);
118+
test('shows marketing preferences checkbox', async () => {
124119
await expect(recipe.getMarketingCheckbox()).toBeVisible();
125120
});
126121

127-
test('shows password change section', async ({page}) => {
128-
const recipe = new LegacyCustomerAccountUtil(page);
122+
test('shows password change section', async () => {
129123
await expect(recipe.getNewPasswordInput()).toBeVisible();
130124
await expect(recipe.getNewPasswordConfirmInput()).toBeVisible();
131125
});
132126
});
133127

134128
test.describe('Addresses Page', () => {
129+
let recipe: LegacyCustomerAccountUtil;
130+
135131
test.beforeEach(async ({page}) => {
136-
const recipe = new LegacyCustomerAccountUtil(page);
132+
recipe = new LegacyCustomerAccountUtil(page);
137133
await recipe.navigateToAddresses();
138134
});
139135

140-
test('renders addresses page with heading', async ({page}) => {
141-
const recipe = new LegacyCustomerAccountUtil(page);
136+
test('renders addresses page with heading', async () => {
142137
await recipe.assertAddressesPageRendered();
143138
});
144139

145-
test('shows new address form with required fields', async ({page}) => {
146-
const recipe = new LegacyCustomerAccountUtil(page);
140+
test('shows new address form with required fields', async () => {
147141
await expect(recipe.getFirstNameInput()).toBeVisible();
148142
await expect(recipe.getLastNameInput()).toBeVisible();
149143
await expect(recipe.getCityInput()).toBeVisible();
150144
});
151145
});
152146

153147
test.describe('Account Navigation', () => {
148+
let recipe: LegacyCustomerAccountUtil;
149+
154150
test.beforeEach(async ({page}) => {
155-
const recipe = new LegacyCustomerAccountUtil(page);
151+
recipe = new LegacyCustomerAccountUtil(page);
156152
await recipe.navigateToOrders();
157153
});
158154

159155
test('clicking Profile link navigates to profile page', async ({page}) => {
160-
const recipe = new LegacyCustomerAccountUtil(page);
161156
await recipe.getAccountMenuLink(/profile/i).click();
162157
await expect(page).toHaveURL(/\/account\/profile/);
163158
});
164159

165160
test('clicking Addresses link navigates to addresses page', async ({
166161
page,
167162
}) => {
168-
const recipe = new LegacyCustomerAccountUtil(page);
169163
await recipe.getAccountMenuLink(/addresses/i).click();
170164
await expect(page).toHaveURL(/\/account\/addresses/);
171165
});

e2e/specs/recipes/legacy-customer-account-flow.spec.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ setRecipeFixture({
2020

2121
test.describe('Legacy Customer Account Flow Recipe', () => {
2222
test.describe('Login Page', () => {
23+
let recipe: LegacyCustomerAccountUtil;
24+
2325
test.beforeEach(async ({page}) => {
24-
const recipe = new LegacyCustomerAccountUtil(page);
26+
recipe = new LegacyCustomerAccountUtil(page);
2527
await recipe.navigateToLogin();
2628
});
2729

28-
test('renders login form with email and password fields', async ({
29-
page,
30-
}) => {
31-
const recipe = new LegacyCustomerAccountUtil(page);
30+
test('renders login form with email and password fields', async () => {
3231
await recipe.assertLoginPageRendered();
3332
});
3433

35-
test('shows links to register and forgot password', async ({page}) => {
36-
const recipe = new LegacyCustomerAccountUtil(page);
34+
test('shows links to register and forgot password', async () => {
3735
await recipe.assertLoginPageLinks();
3836
});
3937

4038
test('navigates to register page via link', async ({page}) => {
41-
const recipe = new LegacyCustomerAccountUtil(page);
4239
await recipe.getLink(/register/i).click();
4340
await expect(page).toHaveURL(/\/account\/register/);
4441
await recipe.assertRegisterPageRendered();
@@ -47,57 +44,52 @@ test.describe('Legacy Customer Account Flow Recipe', () => {
4744
test('navigates to recover page via forgot password link', async ({
4845
page,
4946
}) => {
50-
const recipe = new LegacyCustomerAccountUtil(page);
5147
await recipe.getLink(/forgot password/i).click();
5248
await expect(page).toHaveURL(/\/account\/recover/);
5349
await recipe.assertRecoverPageRendered();
5450
});
5551
});
5652

5753
test.describe('Register Page', () => {
54+
let recipe: LegacyCustomerAccountUtil;
55+
5856
test.beforeEach(async ({page}) => {
59-
const recipe = new LegacyCustomerAccountUtil(page);
57+
recipe = new LegacyCustomerAccountUtil(page);
6058
await recipe.navigateToRegister();
6159
});
6260

63-
test('renders registration form with email, password, and confirm fields', async ({
64-
page,
65-
}) => {
66-
const recipe = new LegacyCustomerAccountUtil(page);
61+
test('renders registration form with email, password, and confirm fields', async () => {
6762
await recipe.assertRegisterPageRendered();
6863
});
6964

70-
test('shows link to login page', async ({page}) => {
71-
const recipe = new LegacyCustomerAccountUtil(page);
65+
test('shows link to login page', async () => {
7266
await recipe.assertRegisterPageLinks();
7367
});
7468

7569
test('navigates to login page via link', async ({page}) => {
76-
const recipe = new LegacyCustomerAccountUtil(page);
7770
await recipe.getLink(/login/i).click();
7871
await expect(page).toHaveURL(/\/account\/login/);
7972
await recipe.assertLoginPageRendered();
8073
});
8174
});
8275

8376
test.describe('Password Recovery Page', () => {
77+
let recipe: LegacyCustomerAccountUtil;
78+
8479
test.beforeEach(async ({page}) => {
85-
const recipe = new LegacyCustomerAccountUtil(page);
80+
recipe = new LegacyCustomerAccountUtil(page);
8681
await recipe.navigateToRecover();
8782
});
8883

89-
test('renders recovery form with email field', async ({page}) => {
90-
const recipe = new LegacyCustomerAccountUtil(page);
84+
test('renders recovery form with email field', async () => {
9185
await recipe.assertRecoverPageRendered();
9286
});
9387

94-
test('shows link to login page', async ({page}) => {
95-
const recipe = new LegacyCustomerAccountUtil(page);
88+
test('shows link to login page', async () => {
9689
await recipe.assertRecoverPageLinks();
9790
});
9891

9992
test('navigates to login page via link', async ({page}) => {
100-
const recipe = new LegacyCustomerAccountUtil(page);
10193
await recipe.getLink(/login/i).click();
10294
await expect(page).toHaveURL(/\/account\/login/);
10395
await recipe.assertLoginPageRendered();

0 commit comments

Comments
 (0)