Skip to content

Commit

Permalink
only obfuscate values
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Sep 27, 2024
1 parent bfb8e22 commit 60373e5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export class BasePage {
* and wait for analytics and signals to be initialized
*/
async loadAndWait(...args: Parameters<BasePage['load']>) {
await this.load(...args)
await this.waitForSignalsAssets()
return this
await Promise.all([this.load(...args), this.waitForSettings()])
}

/**
Expand All @@ -52,9 +50,9 @@ export class BasePage {

/**
* Wait for analytics and signals to be initialized
* We could do the same thing with analytics.ready() and signalsPlugin.ready()
*/
async waitForSignalsAssets() {
// this is kind of an approximation of full initialization
async waitForSettings() {
return Promise.all([
this.waitForCDNSettingsResponse(),
this.waitForEdgeFunctionResponse(),
Expand All @@ -72,7 +70,6 @@ export class BasePage {
({ signalSettings }) => {
window.signalsPlugin = new window.SignalsPlugin({
disableSignalsRedaction: true,
flushInterval: 1000,
...signalSettings,
})
window.analytics.load({
Expand Down Expand Up @@ -241,15 +238,17 @@ export class BasePage {
})
}

waitForEdgeFunctionResponse() {
waitForEdgeFunctionResponse(timeout = 10000) {
return this.page.waitForResponse(
`https://cdn.edgefn.segment.com/MY-WRITEKEY/**`
`https://cdn.edgefn.segment.com/MY-WRITEKEY/**`,
{ timeout }
)
}

waitForCDNSettingsResponse() {
async waitForCDNSettingsResponse(timeout = 10000) {
return this.page.waitForResponse(
'https://cdn.segment.com/v1/projects/*/settings'
'https://cdn.segment.com/v1/projects/*/settings',
{ timeout }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test('Should dispatch events from signals that occurred before analytics was ins
// add a user defined signal before analytics is instantiated
void indexPage.addUserDefinedSignal()

await indexPage.waitForSignalsAssets()
await indexPage.waitForSettings()

await Promise.all([
indexPage.waitForSignalsApiFlush(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@ import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `
// this is a process signal function
const processSignal = (signal) => {}`
const basicEdgeFn = `const processSignal = (signal) => {}`

test.beforeEach(async ({ page }) => {
await indexPage.loadAndWait(page, basicEdgeFn)
})

test('button click (complex, with nested items)', async () => {
const data = {
eventType: 'click',
target: {
attributes: {
id: 'complex-button',
},
classList: [],
id: 'complex-button',
labels: [],
name: '',
nodeName: 'BUTTON',
tagName: 'BUTTON',
title: '',
type: 'submit',
innerText: 'Other Example Button with Nested Text',
textContent: 'Other Example Button with Nested Text',
value: '',
},
}

test('clicking a button with nested content', async () => {
/**
* Click a button with nested text, ensure that that correct text shows up
*/
Expand All @@ -22,28 +40,28 @@ test('button click (complex, with nested items)', async () => {

const interactionSignals = indexPage.signalsAPI.getEvents('interaction')
expect(interactionSignals).toHaveLength(1)
const data = {
eventType: 'click',
target: {
attributes: {
id: 'complex-button',
},
classList: [],
id: 'complex-button',
labels: [],
name: '',
nodeName: 'BUTTON',
tagName: 'BUTTON',
title: '',
type: 'submit',
innerText: expect.any(String),
textContent: expect.stringContaining(
'Other Example Button with Nested Text'
),
value: '',

expect(interactionSignals[0]).toMatchObject({
event: 'Segment Signal Generated',
type: 'track',
properties: {
type: 'interaction',
data,
},
}
})
})

test('clicking the h1 tag inside a button', async () => {
/**
* Click the nested text, ensure that that correct text shows up
*/
await Promise.all([
indexPage.clickInsideComplexButton(),
indexPage.waitForSignalsApiFlush(),
])

const interactionSignals = indexPage.signalsAPI.getEvents('interaction')
expect(interactionSignals).toHaveLength(1)
expect(interactionSignals[0]).toMatchObject({
event: 'Segment Signal Generated',
type: 'track',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export class IndexPage extends BasePage {
async clickComplexButton() {
return this.page.click('#complex-button')
}

async clickInsideComplexButton() {
return this.page.click('#complex-button h1')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `
// this is a process signal function
const processSignal = (signal) => {
if (signal.type === 'interaction') {
const eventName = signal.data.eventType + ' ' + '[' + signal.type + ']'
analytics.track(eventName, signal.data)
}
}`
const basicEdgeFn = `const processSignal = (signal) => {}`

test('network signals allow and disallow list', async ({ page }) => {
await indexPage.loadAndWait(page, basicEdgeFn, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { test, expect } from '@playwright/test'
import { IndexPage } from './index-page'

const basicEdgeFn = `
// this is a process signal function
const processSignal = (signal) => {
if (signal.type === 'interaction') {
const eventName = signal.data.eventType + ' ' + '[' + signal.type + ']'
analytics.track(eventName, signal.data)
}
}`
const basicEdgeFn = `const processSignal = (signal) => {}`

test.describe('XHR Tests', () => {
let indexPage: IndexPage
Expand Down

0 comments on commit 60373e5

Please sign in to comment.