|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { IncrementalSource } from '@sentry-internal/rrweb'; |
| 3 | +import type { inputData } from '@sentry-internal/rrweb/typings/types'; |
| 4 | + |
| 5 | +import { sentryTest } from '../../../utils/fixtures'; |
| 6 | +import { IncrementalRecordingSnapshot, getCustomRecordingEvents } from '../../../utils/replayHelpers'; |
| 7 | +import { |
| 8 | + getIncrementalRecordingSnapshots, |
| 9 | + shouldSkipReplayTest, |
| 10 | + waitForReplayRequest, |
| 11 | +} from '../../../utils/replayHelpers'; |
| 12 | + |
| 13 | +function isInputMutation( |
| 14 | + snap: IncrementalRecordingSnapshot, |
| 15 | +): snap is IncrementalRecordingSnapshot & { data: inputData } { |
| 16 | + return snap.data.source == IncrementalSource.Input; |
| 17 | +} |
| 18 | + |
| 19 | +sentryTest('captures keyboard events', async ({ forceFlushReplay, getLocalTestPath, page }) => { |
| 20 | + if (shouldSkipReplayTest()) { |
| 21 | + sentryTest.skip(); |
| 22 | + } |
| 23 | + |
| 24 | + const reqPromise0 = waitForReplayRequest(page, 0); |
| 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 getLocalTestPath({ testDir: __dirname }); |
| 35 | + |
| 36 | + await page.goto(url); |
| 37 | + await reqPromise0; |
| 38 | + await forceFlushReplay(); |
| 39 | + |
| 40 | + const reqPromise1 = waitForReplayRequest(page, (event, res) => { |
| 41 | + return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.keyDown'); |
| 42 | + }); |
| 43 | + |
| 44 | + // Trigger keyboard unfocused |
| 45 | + await page.keyboard.press('a'); |
| 46 | + await page.keyboard.press('Control+A'); |
| 47 | + |
| 48 | + // Type unfocused |
| 49 | + await page.keyboard.type('Hello', { delay: 10 }); |
| 50 | + |
| 51 | + // Type focused |
| 52 | + await page.locator('#input').focus(); |
| 53 | + |
| 54 | + await page.keyboard.press('Control+A'); |
| 55 | + await page.keyboard.type('Hello', { delay: 10 }); |
| 56 | + |
| 57 | + await forceFlushReplay(); |
| 58 | + const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); |
| 59 | + |
| 60 | + expect(breadcrumbs).toEqual([ |
| 61 | + { |
| 62 | + timestamp: expect.any(Number), |
| 63 | + type: 'default', |
| 64 | + category: 'ui.keyDown', |
| 65 | + message: 'body', |
| 66 | + data: { |
| 67 | + nodeId: expect.any(Number), |
| 68 | + node: { |
| 69 | + attributes: {}, |
| 70 | + id: expect.any(Number), |
| 71 | + tagName: 'body', |
| 72 | + textContent: '', |
| 73 | + }, |
| 74 | + metaKey: false, |
| 75 | + shiftKey: false, |
| 76 | + ctrlKey: true, |
| 77 | + altKey: false, |
| 78 | + key: 'Control', |
| 79 | + }, |
| 80 | + }, |
| 81 | + { |
| 82 | + timestamp: expect.any(Number), |
| 83 | + type: 'default', |
| 84 | + category: 'ui.keyDown', |
| 85 | + message: 'body', |
| 86 | + data: { |
| 87 | + nodeId: expect.any(Number), |
| 88 | + node: { attributes: {}, id: expect.any(Number), tagName: 'body', textContent: '' }, |
| 89 | + metaKey: false, |
| 90 | + shiftKey: false, |
| 91 | + ctrlKey: true, |
| 92 | + altKey: false, |
| 93 | + key: 'A', |
| 94 | + }, |
| 95 | + }, |
| 96 | + { |
| 97 | + timestamp: expect.any(Number), |
| 98 | + type: 'default', |
| 99 | + category: 'ui.input', |
| 100 | + message: 'body > input#input', |
| 101 | + data: { |
| 102 | + nodeId: expect.any(Number), |
| 103 | + node: { |
| 104 | + attributes: { id: 'input' }, |
| 105 | + id: expect.any(Number), |
| 106 | + tagName: 'input', |
| 107 | + textContent: '', |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + ]); |
| 112 | +}); |
0 commit comments