11import { test , expect } from '@playwright/test'
22import { waitForCondition } from '../../helpers/playwright-utils'
33import { IndexPage } from './index-page'
4+ import type { SegmentEvent } from '@segment/analytics-next'
45
56const basicEdgeFn = `const processSignal = (signal) => {}`
67
@@ -9,33 +10,28 @@ test('Collecting signals whenever a user selects an item', async ({ page }) => {
910 disableSignalsRedaction : true ,
1011 enableSignalsIngestion : true ,
1112 } )
12- const fillAndConfirm = async ( selector : string , text : string ) => {
13- await page . getByTestId ( selector ) . fill ( text )
14- await page . getByTestId ( selector ) . press ( 'Enter' )
13+
14+ const filterClick = ( e : SegmentEvent ) : boolean => {
15+ return (
16+ e . properties ! . data . eventType === 'click' &&
17+ e . properties ! . data . target . textContent ?. includes ( 'Mint' )
18+ )
1519 }
16- await Promise . all ( [
17- fillAndConfirm ( 'aria-text-field' , 'John Doe' ) ,
18- waitForCondition (
19- ( ) => indexPage . signalsAPI . getEvents ( 'interaction' ) . length > 0 ,
20- { errorMessage : 'No interaction signals found' }
21- ) ,
22- ] )
23- const interactionSignals = indexPage . signalsAPI . getEvents ( 'interaction' )
2420
25- const data = expect . objectContaining ( {
26- eventType : 'change' ,
27- listener : 'mutation' ,
28- change : {
29- value : 'John Doe' ,
21+ const waitForInteraction = waitForCondition (
22+ ( ) => {
23+ const events = indexPage . signalsAPI . getEvents ( 'interaction' )
24+ return events . some ( filterClick )
3025 } ,
31- target : expect . objectContaining ( {
32- attributes : expect . objectContaining ( {
33- type : 'text' ,
34- value : 'John Doe' ,
35- } ) ,
36- tagName : 'INPUT' ,
37- value : 'John Doe' ,
38- } ) ,
39- } )
40- expect ( interactionSignals [ 0 ] . properties ! . data ) . toMatchObject ( data )
26+ { errorMessage : 'No interaction signals found' }
27+ )
28+ await page . click ( '#select button' )
29+ await page . getByRole ( 'option' , { name : 'Mint' } ) . click ( )
30+
31+ await waitForInteraction
32+ const signals = indexPage . signalsAPI
33+ . getEvents ( 'interaction' )
34+ . filter ( filterClick )
35+
36+ expect ( signals ) . toHaveLength ( 1 )
4137} )
0 commit comments