-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/browser-integration-tests/suites/replay/keyboardEvents/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 1000, | ||
flushMaxDelay: 1000, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/browser-integration-tests/suites/replay/keyboardEvents/template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<input id="input" /> | ||
</body> | ||
</html> |
112 changes: 112 additions & 0 deletions
112
packages/browser-integration-tests/suites/replay/keyboardEvents/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { expect } from '@playwright/test'; | ||
import { IncrementalSource } from '@sentry-internal/rrweb'; | ||
import type { inputData } from '@sentry-internal/rrweb/typings/types'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { IncrementalRecordingSnapshot, getCustomRecordingEvents } from '../../../utils/replayHelpers'; | ||
import { | ||
getIncrementalRecordingSnapshots, | ||
shouldSkipReplayTest, | ||
waitForReplayRequest, | ||
} from '../../../utils/replayHelpers'; | ||
|
||
function isInputMutation( | ||
snap: IncrementalRecordingSnapshot, | ||
): snap is IncrementalRecordingSnapshot & { data: inputData } { | ||
return snap.data.source == IncrementalSource.Input; | ||
} | ||
|
||
sentryTest('captures keyboard events', async ({ forceFlushReplay, getLocalTestPath, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await reqPromise0; | ||
await forceFlushReplay(); | ||
|
||
const reqPromise1 = waitForReplayRequest(page, (event, res) => { | ||
return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.keyDown'); | ||
}); | ||
|
||
// Trigger keyboard unfocused | ||
await page.keyboard.press('a'); | ||
await page.keyboard.press('Control+A'); | ||
|
||
// Type unfocused | ||
await page.keyboard.type('Hello', { delay: 10 }); | ||
|
||
// Type focused | ||
await page.locator('#input').focus(); | ||
|
||
await page.keyboard.press('Control+A'); | ||
await page.keyboard.type('Hello', { delay: 10 }); | ||
|
||
await forceFlushReplay(); | ||
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); | ||
|
||
expect(breadcrumbs).toEqual([ | ||
{ | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
category: 'ui.keyDown', | ||
message: 'body', | ||
data: { | ||
nodeId: expect.any(Number), | ||
node: { | ||
attributes: {}, | ||
id: expect.any(Number), | ||
tagName: 'body', | ||
textContent: '', | ||
}, | ||
metaKey: false, | ||
shiftKey: false, | ||
ctrlKey: true, | ||
altKey: false, | ||
key: 'Control', | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
category: 'ui.keyDown', | ||
message: 'body', | ||
data: { | ||
nodeId: expect.any(Number), | ||
node: { attributes: {}, id: expect.any(Number), tagName: 'body', textContent: '' }, | ||
metaKey: false, | ||
shiftKey: false, | ||
ctrlKey: true, | ||
altKey: false, | ||
key: 'A', | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
category: 'ui.input', | ||
message: 'body > input#input', | ||
data: { | ||
nodeId: expect.any(Number), | ||
node: { | ||
attributes: { id: 'input' }, | ||
id: expect.any(Number), | ||
tagName: 'input', | ||
textContent: '', | ||
}, | ||
}, | ||
}, | ||
]); | ||
}); |