|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { TEST_HOST, sentryTest } from '../../../utils/fixtures'; |
| 4 | +import { envelopeRequestParser, getEnvelopeType, shouldSkipFeedbackTest } from '../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => { |
| 7 | + if (shouldSkipFeedbackTest()) { |
| 8 | + sentryTest.skip(); |
| 9 | + } |
| 10 | + |
| 11 | + const feedbackRequestPromise = page.waitForResponse(res => { |
| 12 | + const req = res.request(); |
| 13 | + |
| 14 | + const postData = req.postData(); |
| 15 | + if (!postData) { |
| 16 | + return false; |
| 17 | + } |
| 18 | + |
| 19 | + try { |
| 20 | + return getEnvelopeType(req) === 'feedback'; |
| 21 | + } catch (err) { |
| 22 | + return false; |
| 23 | + } |
| 24 | + }); |
| 25 | + |
| 26 | + await page.route('https://dsn.ingest.sentry.io/**/*', route => { |
| 27 | + return route.fulfill({ |
| 28 | + status: 200, |
| 29 | + contentType: 'application/json', |
| 30 | + body: JSON.stringify({ id: 'test-id' }), |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 35 | + |
| 36 | + await page.goto(url); |
| 37 | + await page.getByText('Report a Bug').click(); |
| 38 | + expect(await page.locator(':visible:text-is("Report a Bug")').count()).toEqual(1); |
| 39 | + await page.locator('[name="name"]').fill('Jane Doe'); |
| 40 | + await page.locator('[name="email"]').fill('[email protected]'); |
| 41 | + await page.locator('[name="message"]').fill('my example feedback'); |
| 42 | + await page.locator('[data-sentry-feedback] .btn--primary').click(); |
| 43 | + |
| 44 | + const feedbackEvent = envelopeRequestParser((await feedbackRequestPromise).request()); |
| 45 | + expect(feedbackEvent).toEqual({ |
| 46 | + type: 'feedback', |
| 47 | + breadcrumbs: expect.any(Array), |
| 48 | + contexts: { |
| 49 | + feedback: { |
| 50 | + contact_email: '[email protected]', |
| 51 | + message: 'my example feedback', |
| 52 | + name: 'Jane Doe', |
| 53 | + source: 'widget', |
| 54 | + url: `${TEST_HOST}/index.html`, |
| 55 | + }, |
| 56 | + trace: { |
| 57 | + trace_id: expect.stringMatching(/\w{32}/), |
| 58 | + span_id: expect.stringMatching(/\w{16}/), |
| 59 | + }, |
| 60 | + }, |
| 61 | + level: 'info', |
| 62 | + tags: { |
| 63 | + from: 'integration init', |
| 64 | + }, |
| 65 | + timestamp: expect.any(Number), |
| 66 | + event_id: expect.stringMatching(/\w{32}/), |
| 67 | + environment: 'production', |
| 68 | + sdk: { |
| 69 | + integrations: expect.arrayContaining(['Feedback']), |
| 70 | + version: expect.any(String), |
| 71 | + name: 'sentry.javascript.browser', |
| 72 | + packages: expect.anything(), |
| 73 | + }, |
| 74 | + request: { |
| 75 | + url: `${TEST_HOST}/index.html`, |
| 76 | + headers: { |
| 77 | + 'User-Agent': expect.stringContaining(''), |
| 78 | + }, |
| 79 | + }, |
| 80 | + platform: 'javascript', |
| 81 | + }); |
| 82 | + const cspContainer = await page.locator('#csp-violation'); |
| 83 | + expect(cspContainer).not.toContainText('CSP Violation'); |
| 84 | +}); |
0 commit comments