Skip to content

Commit

Permalink
ref: Ensure window.open works
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jun 13, 2023
1 parent b9a7507 commit ddd1efe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ <h1 id="h2">Bottom</h1>
}, 3001);
});
document.getElementById('windowOpenButton').addEventListener('click', () => {
setTimeout(() => {
window.open('.');
}, 3001);
window.open('https://example.com/', '_self');
});

// Do nothing on these elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ sentryTest('window.open() is considered for slow click', async ({ getLocalTestUr
const reqPromise1 = waitForReplayRequest(page, (event, res) => {
const { breadcrumbs } = getCustomRecordingEvents(res);

return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.slowClickDetected');
return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click');
});

await page.click('#windowOpenButton');
const navPromise = page.waitForURL('https://example.com/');

const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1);

const slowClickBreadcrumbs = breadcrumbs.filter(breadcrumb => breadcrumb.category === 'ui.slowClickDetected');

expect(slowClickBreadcrumbs).toEqual([
expect(breadcrumbs).toEqual([
{
category: 'ui.slowClickDetected',
category: 'ui.click',
data: {
endReason: 'window.open',
node: {
attributes: {
id: 'windowOpenButton',
Expand All @@ -49,14 +47,15 @@ sentryTest('window.open() is considered for slow click', async ({ getLocalTestUr
textContent: '****** ****',
},
nodeId: expect.any(Number),
timeAfterClickMs: expect.any(Number),
url: 'http://sentry-test.io/index.html',
},
message: 'body > button#windowOpenButton',
timestamp: expect.any(Number),
type: 'default',
},
]);

expect(slowClickBreadcrumbs[0]?.data?.timeAfterClickMs).toBeGreaterThan(3000);
expect(slowClickBreadcrumbs[0]?.data?.timeAfterClickMs).toBeLessThan(3100);
await navPromise;

// Ensure window.open() still works as expected
expect(await page.url()).toBe('https://example.com/');
});

0 comments on commit ddd1efe

Please sign in to comment.