Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signals.find test #1174

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
Loading