Skip to content

Commit

Permalink
chore: add E2E for tracking script functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Aug 19, 2024
1 parent c2492f7 commit a8745f3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions tests/e2e/specs/admin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,54 @@ test.describe( 'Admin', () => {
});
expect( tiTelemetryDefined ).toBe( true );
});

test( 'check window.tiTrk functionality', async({ page, admin, context }) => {
await admin.visitAdminPage( 'admin.php?page=visualizer' );
await blockRequests( context );

// Check if window.tiTrk exists
const tiTrkExists = await page.evaluate( () => {
return 'undefined' !== typeof window.tiTrk;
});
expect( tiTrkExists ).toBe( true );

// Check if window.tiTrk has the expected methods
const tiTrkMethods = await page.evaluate( () => {
return {
hasWithMethod: 'function' === typeof window.tiTrk.with,
hasUploadEventsMethod: 'function' === typeof window.tiTrk.uploadEvents,
hasStartMethod: 'function' === typeof window.tiTrk.start,
hasStopMethod: 'function' === typeof window.tiTrk.stop
};
});
expect( tiTrkMethods ).toEqual({
hasWithMethod: true,
hasUploadEventsMethod: true,
hasStartMethod: true,
hasStopMethod: true
});

// Test adding an event
const eventAdded = await page.evaluate( () => {
const testEvent = {
slug: 'visualizer',
action: 'test-action',
feature: 'test-feature'
};
window.tiTrk.with( 'visualizer' ).add( testEvent );
return 0 < window.tiTrk.events.size;
});
expect( eventAdded ).toBe( true );

// Test uploading events (this will clear the events)
await page.evaluate( () => {
window.tiTrk.uploadEvents();
});

// Check if events were cleared after uploading
const eventsCleared = await page.evaluate( () => {
return 0 === window.tiTrk.events.size;
});
expect( eventsCleared ).toBe( true );
});
});
2 changes: 1 addition & 1 deletion tests/e2e/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const BLOCKED_URLS = [
'https://api.themeisle.com/tracking/log', // Do not send tracking data.
'https://api.themeisle.com/tracking/', // Do not send tracking data.
'https://app.formbricks.com' // Do not initialize FormBricks survey.
];

Expand Down

0 comments on commit a8745f3

Please sign in to comment.