Skip to content

Commit

Permalink
Add signals.find test (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Oct 29, 2024
1 parent 9e6db28 commit 51167c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ export class IndexPage extends BasePage {
return promiseTimeout(p, 2000, 'analytics.on("track") did not resolve')
}

addUserDefinedSignal() {
return this.page.evaluate(() => {
window.signalsPlugin.addSignal({
type: 'userDefined',
data: {
foo: 'bar',
},
})
})
addUserDefinedSignal(data?: Record<string, unknown>) {
return this.page.evaluate(
(args) => {
window.signalsPlugin.addSignal({
type: 'userDefined',
data: {
foo: 'bar',
...args.data,
},
})
},
{ data }
)
}

async clickButton() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect } from '@playwright/test'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

test('should find the most recent signal', async ({ page }) => {
const basicEdgeFn = `const processSignal = (signal) => {
if (signal.type === 'interaction' && signal.data.target.id === 'complex-button') {
const mostRecentSignal = signals.find(signal, 'userDefined')
if (mostRecentSignal.data.num === 2) {
analytics.track('correct signal found')
}
}
}`

await indexPage.loadAndWait(page, basicEdgeFn)
const tapiFlush = indexPage.waitForTrackingApiFlush()
await indexPage.addUserDefinedSignal({ num: 1 })
await indexPage.addUserDefinedSignal({ num: 2 })
await indexPage.clickComplexButton()
await tapiFlush
const lastEvent = indexPage.trackingAPI.lastEvent()
expect(lastEvent.event).toEqual('correct signal found')
})

0 comments on commit 51167c0

Please sign in to comment.