Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Sep 28, 2024
1 parent 7be67d4 commit 34a4a7a
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export class PageNetworkUtils {
body: JSON.stringify({ foo: 'bar' }),
...args.request,
})
.then(console.log)
.catch(console.error)
},
{ url, request }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Page } from '@playwright/test'
import type { Compute } from './ts'

export function waitForCondition(
conditionFn: () => boolean,
Expand Down Expand Up @@ -28,8 +29,15 @@ export function waitForCondition(
})
}

export async function fillAndBlur(page: Page, selector: string, text: string) {
await page.fill(selector, text, { timeout: 3000 })
type FillOptions = Compute<Parameters<Page['fill']>[2]>

export async function fillAndBlur(
page: Page,
selector: string,
text: string,
options: FillOptions = {}
) {
await page.fill(selector, text, options)
// Remove focus so the onChange event is triggered
await page.evaluate(
(args) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Compute<T> = { [K in keyof T]: T[K] } & {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { test, expect } from '@playwright/test'
import { waitForCondition } from '../../helpers/playwright-utils'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `const processSignal = (signal) => {}`

test('Collecting signals whenever a user enters text input', async ({
page,
}) => {
/**
* Input some text into the input field, see if the signal is emitted correctly
*/
await indexPage.loadAndWait(page, basicEdgeFn, {
disableSignalsRedaction: true,
})

await Promise.all([
indexPage.fillNameInput('John Doe'),
indexPage.waitForSignalsApiFlush(),
])

await waitForCondition(
() => indexPage.signalsAPI.getEvents('interaction').length > 0,
{ errorMessage: 'No interaction signals found' }
)
const interactionSignals = indexPage.signalsAPI.getEvents('interaction')

const data = expect.objectContaining({
eventType: 'change',
target: expect.objectContaining({
attributes: expect.objectContaining({
type: 'text',
id: 'name',
name: 'name',
}),
classList: [],
id: 'name',
labels: [
{
textContent: 'Name:',
},
],
name: 'name',
nodeName: 'INPUT',
tagName: 'INPUT',
value: 'John Doe',
}),
})
expect(interactionSignals[0]).toMatchObject({
event: 'Segment Signal Generated',
type: 'track',
properties: {
type: 'interaction',
data,
},
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ const basicEdgeFn = `const processSignal = (signal) => {}`
test('redaction enabled -> will XXX the value of text input', async ({
page,
}) => {
const data = expect.objectContaining({
eventType: 'change',
target: expect.objectContaining({
name: 'name',
type: 'text',
value: 'XXX', // redacted
}),
})

await indexPage.loadAndWait(page, basicEdgeFn, {
disableSignalsRedaction: false,
})
/**
* Click a button with nested text, ensure that that correct text shows up
*/

await Promise.all([
indexPage.fillNameInput('John Doe'),
indexPage.waitForSignalsApiFlush(),
Expand All @@ -35,6 +24,14 @@ test('redaction enabled -> will XXX the value of text input', async ({
)
const interactionSignals = indexPage.signalsAPI.getEvents('interaction')

const data = expect.objectContaining({
eventType: 'change',
target: expect.objectContaining({
name: 'name',
type: 'text',
value: 'XXX', // redacted
}),
})
expect(interactionSignals[0]).toMatchObject({
event: 'Segment Signal Generated',
type: 'track',
Expand All @@ -48,19 +45,10 @@ test('redaction enabled -> will XXX the value of text input', async ({
test('redation disabled -> will not touch the value of text input', async ({
page,
}) => {
const data = expect.objectContaining({
eventType: 'change',
target: expect.objectContaining({
value: 'John Doe', // noe redacted
}),
})

await indexPage.loadAndWait(page, basicEdgeFn, {
disableSignalsRedaction: true,
})
/**
* Click a button with nested text, ensure that that correct text shows up
*/

await Promise.all([
indexPage.fillNameInput('John Doe'),
indexPage.waitForSignalsApiFlush(),
Expand All @@ -72,6 +60,13 @@ test('redation disabled -> will not touch the value of text input', async ({
)
const interactionSignals = indexPage.signalsAPI.getEvents('interaction')

const data = expect.objectContaining({
eventType: 'change',
target: expect.objectContaining({
value: 'John Doe', // noe redacted
}),
})

expect(interactionSignals[0]).toMatchObject({
event: 'Segment Signal Generated',
type: 'track',
Expand Down
Empty file.

0 comments on commit 34a4a7a

Please sign in to comment.