Skip to content

Commit 51167c0

Browse files
authored
Add signals.find test (#1174)
1 parent 9e6db28 commit 51167c0

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

packages/signals/signals-integration-tests/src/tests/signals-vanilla/index-page.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ export class IndexPage extends BasePage {
2323
return promiseTimeout(p, 2000, 'analytics.on("track") did not resolve')
2424
}
2525

26-
addUserDefinedSignal() {
27-
return this.page.evaluate(() => {
28-
window.signalsPlugin.addSignal({
29-
type: 'userDefined',
30-
data: {
31-
foo: 'bar',
32-
},
33-
})
34-
})
26+
addUserDefinedSignal(data?: Record<string, unknown>) {
27+
return this.page.evaluate(
28+
(args) => {
29+
window.signalsPlugin.addSignal({
30+
type: 'userDefined',
31+
data: {
32+
foo: 'bar',
33+
...args.data,
34+
},
35+
})
36+
},
37+
{ data }
38+
)
3539
}
3640

3741
async clickButton() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { test, expect } from '@playwright/test'
2+
import { IndexPage } from './index-page'
3+
4+
const indexPage = new IndexPage()
5+
6+
test('should find the most recent signal', async ({ page }) => {
7+
const basicEdgeFn = `const processSignal = (signal) => {
8+
if (signal.type === 'interaction' && signal.data.target.id === 'complex-button') {
9+
const mostRecentSignal = signals.find(signal, 'userDefined')
10+
if (mostRecentSignal.data.num === 2) {
11+
analytics.track('correct signal found')
12+
}
13+
}
14+
}`
15+
16+
await indexPage.loadAndWait(page, basicEdgeFn)
17+
const tapiFlush = indexPage.waitForTrackingApiFlush()
18+
await indexPage.addUserDefinedSignal({ num: 1 })
19+
await indexPage.addUserDefinedSignal({ num: 2 })
20+
await indexPage.clickComplexButton()
21+
await tapiFlush
22+
const lastEvent = indexPage.trackingAPI.lastEvent()
23+
expect(lastEvent.event).toEqual('correct signal found')
24+
})

0 commit comments

Comments
 (0)