Skip to content

Commit 0a34f8b

Browse files
committed
Add more e2e testing
1 parent 415d43f commit 0a34f8b

File tree

2 files changed

+115
-9
lines changed

2 files changed

+115
-9
lines changed

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/src/pages/InnerLazyRoutes.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const someMoreNestedRoutes = [
3232
<Link to="/another-lazy/sub/888/999" id="navigate-to-another-from-inner">
3333
Navigate to Another Lazy Route
3434
</Link>
35+
<Link to="/lazy/inner/1/2/" id="navigate-to-upper">
36+
Navigate to Upper Lazy Route
37+
</Link>
3538
</div>
3639
),
3740
},

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/tests/transactions.test.ts

Lines changed: 112 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,15 @@ test('Creates navigation transactions between two different lazy routes', async
107107
expect(secondEvent.contexts?.trace?.op).toBe('navigation');
108108
});
109109

110-
test('Creates navigation transactions from inner lazy route to another lazy route', async ({ page }) => {
110+
test('Creates navigation transactions from inner lazy route to another lazy route with history navigation', async ({
111+
page,
112+
}) => {
113+
await page.goto('/');
114+
115+
// Navigate to inner lazy route first
116+
const navigationToInner = page.locator('id=navigation');
117+
await expect(navigationToInner).toBeVisible();
118+
111119
// First, navigate to the inner lazy route
112120
const firstTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
113121
return (
@@ -117,11 +125,6 @@ test('Creates navigation transactions from inner lazy route to another lazy rout
117125
);
118126
});
119127

120-
await page.goto('/');
121-
122-
// Navigate to inner lazy route first
123-
const navigationToInner = page.locator('id=navigation');
124-
await expect(navigationToInner).toBeVisible();
125128
await navigationToInner.click();
126129

127130
const firstEvent = await firstTransactionPromise;
@@ -135,6 +138,10 @@ test('Creates navigation transactions from inner lazy route to another lazy rout
135138
expect(firstEvent.type).toBe('transaction');
136139
expect(firstEvent.contexts?.trace?.op).toBe('navigation');
137140

141+
// Click the navigation link from within the inner lazy route to another lazy route
142+
const navigationToAnotherFromInner = page.locator('id=navigate-to-another-from-inner');
143+
await expect(navigationToAnotherFromInner).toBeVisible();
144+
138145
// Now navigate from the inner lazy route to another lazy route
139146
const secondTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
140147
return (
@@ -144,9 +151,6 @@ test('Creates navigation transactions from inner lazy route to another lazy rout
144151
);
145152
});
146153

147-
// Click the navigation link from within the inner lazy route to another lazy route
148-
const navigationToAnotherFromInner = page.locator('id=navigate-to-another-from-inner');
149-
await expect(navigationToAnotherFromInner).toBeVisible();
150154
await navigationToAnotherFromInner.click();
151155

152156
const secondEvent = await secondTransactionPromise;
@@ -159,4 +163,103 @@ test('Creates navigation transactions from inner lazy route to another lazy rout
159163
expect(secondEvent.transaction).toBe('/another-lazy/sub/:id/:subId');
160164
expect(secondEvent.type).toBe('transaction');
161165
expect(secondEvent.contexts?.trace?.op).toBe('navigation');
166+
167+
// Go back to the previous page to ensure history navigation works as expected
168+
const goBackTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
169+
return (
170+
!!transactionEvent?.transaction &&
171+
transactionEvent.contexts?.trace?.op === 'navigation' &&
172+
transactionEvent.transaction === '/lazy/inner/:id/:anotherId/:someAnotherId'
173+
);
174+
});
175+
176+
await page.goBack();
177+
178+
const goBackEvent = await goBackTransactionPromise;
179+
180+
// Validate the second go back transaction event
181+
expect(goBackEvent.transaction).toBe('/lazy/inner/:id/:anotherId/:someAnotherId');
182+
expect(goBackEvent.type).toBe('transaction');
183+
expect(goBackEvent.contexts?.trace?.op).toBe('navigation');
184+
185+
// Navigate to the upper route
186+
const goUpperRouteTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
187+
return (
188+
!!transactionEvent?.transaction &&
189+
transactionEvent.contexts?.trace?.op === 'navigation' &&
190+
transactionEvent.transaction === '/lazy/inner/:id/:anotherId'
191+
);
192+
});
193+
194+
const navigationToUpper = page.locator('id=navigate-to-upper');
195+
196+
await navigationToUpper.click();
197+
198+
const goUpperRouteEvent = await goUpperRouteTransactionPromise;
199+
200+
// Validate the go upper route transaction event
201+
expect(goUpperRouteEvent.transaction).toBe('/lazy/inner/:id/:anotherId');
202+
expect(goUpperRouteEvent.type).toBe('transaction');
203+
expect(goUpperRouteEvent.contexts?.trace?.op).toBe('navigation');
204+
});
205+
206+
test('Does not send any duplicate navigation transaction names browsing between different routes', async ({ page }) => {
207+
const transactionNamesList: string[] = [];
208+
209+
// Monitor and add all transaction names sent to Sentry for the navigations
210+
const allTransactionsPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
211+
if (transactionEvent?.transaction) {
212+
transactionNamesList.push(transactionEvent.transaction);
213+
}
214+
215+
if (transactionNamesList.length >= 5) {
216+
// Stop monitoring once we have enough transaction names
217+
return true;
218+
}
219+
220+
return false;
221+
});
222+
223+
// Go to root page
224+
await page.goto('/');
225+
page.waitForTimeout(1000);
226+
227+
// Navigate to inner lazy route
228+
const navigationToInner = page.locator('id=navigation');
229+
await expect(navigationToInner).toBeVisible();
230+
await navigationToInner.click();
231+
232+
// Navigate to another lazy route
233+
const navigationToAnother = page.locator('id=navigate-to-another-from-inner');
234+
await expect(navigationToAnother).toBeVisible();
235+
await page.waitForTimeout(1000);
236+
237+
// Click to navigate to another lazy route
238+
await navigationToAnother.click();
239+
const anotherLazyRouteContent = page.locator('id=another-lazy-route-deep');
240+
await expect(anotherLazyRouteContent).toBeVisible();
241+
await page.waitForTimeout(1000);
242+
243+
// Navigate back to inner lazy route
244+
await page.goBack();
245+
await expect(page.locator('id=innermost-lazy-route')).toBeVisible();
246+
await page.waitForTimeout(1000);
247+
248+
// Navigate to upper inner lazy route
249+
const navigationToUpper = page.locator('id=navigate-to-upper');
250+
await expect(navigationToUpper).toBeVisible();
251+
await navigationToUpper.click();
252+
253+
await page.waitForTimeout(1000);
254+
255+
await allTransactionsPromise;
256+
257+
expect(transactionNamesList.length).toBe(5);
258+
expect(transactionNamesList).toEqual([
259+
'/',
260+
'/lazy/inner/:id/:anotherId/:someAnotherId',
261+
'/another-lazy/sub/:id/:subId',
262+
'/lazy/inner/:id/:anotherId/:someAnotherId',
263+
'/lazy/inner/:id/:anotherId',
264+
]);
162265
});

0 commit comments

Comments
 (0)