Skip to content

Commit f48b3c7

Browse files
committed
Add integration test for checking a click interaction uses the annotated component name
1 parent cbda225 commit f48b3c7

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

packages/browser-integration-tests/suites/tracing/browsertracing/interactions/assets/script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ const delay = e => {
1414
};
1515

1616
document.querySelector('[data-test-id=interaction-button]').addEventListener('click', delay);
17+
document.querySelector('[data-test-id=annotated-button]').addEventListener('click', delay);

packages/browser-integration-tests/suites/tracing/browsertracing/interactions/template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<body>
77
<div>Rendered Before Long Task</div>
88
<button data-test-id="interaction-button">Click Me</button>
9+
<button data-test-id="annotated-button" data-component="AnnotatedButton">Click Me</button>
910
<script src="https://example.com/path/to/script.js"></script>
1011
</body>
1112
</html>

packages/browser-integration-tests/suites/tracing/browsertracing/interactions/test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,35 @@ sentryTest(
8080
}
8181
},
8282
);
83+
84+
sentryTest(
85+
'should use the component name for a clicked element when it is available',
86+
async ({ browserName, getLocalTestPath, page }) => {
87+
const supportedBrowsers = ['chromium', 'firefox'];
88+
89+
if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) {
90+
sentryTest.skip();
91+
}
92+
93+
await page.route('**/path/to/script.js', (route: Route) =>
94+
route.fulfill({ path: `${__dirname}/assets/script.js` }),
95+
);
96+
97+
const url = await getLocalTestPath({ testDir: __dirname });
98+
99+
await page.goto(url);
100+
await getFirstSentryEnvelopeRequest<Event>(page);
101+
102+
await page.locator('[data-test-id=annotated-button]').click();
103+
104+
const envelopes = await getMultipleSentryEnvelopeRequests<TransactionJSON>(page, 1);
105+
expect(envelopes).toHaveLength(1);
106+
const eventData = envelopes[0];
107+
108+
expect(eventData.spans).toHaveLength(1);
109+
110+
const interactionSpan = eventData.spans![0];
111+
expect(interactionSpan.op).toBe('ui.interaction.click');
112+
expect(interactionSpan.description).toBe('AnnotatedButton');
113+
},
114+
);

packages/utils/test/browser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSDOM } from 'jsdom';
22

3-
import { getDomElement, getElementIdentifier, htmlTreeAsString } from '../src/browser';
3+
import { getDomElement, htmlTreeAsString } from '../src/browser';
44

55
beforeAll(() => {
66
const dom = new JSDOM();

0 commit comments

Comments
 (0)