File tree Expand file tree Collapse file tree 2 files changed +37
-9
lines changed
packages/signals/signals-integration-tests/src/tests/signals-vanilla Expand file tree Collapse file tree 2 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,19 @@ export class IndexPage extends BasePage {
23
23
return promiseTimeout ( p , 2000 , 'analytics.on("track") did not resolve' )
24
24
}
25
25
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
+ )
35
39
}
36
40
37
41
async clickButton ( ) {
Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments