Added signup form attribution tests

no issue

Added some tests for the signup form attribution when on an external site or on the Ghost site.
This commit is contained in:
Simon Backx 2023-06-14 15:50:04 +02:00
parent 4da658e72a
commit 5bb4a94444
2 changed files with 46 additions and 4 deletions

View File

@ -2,8 +2,12 @@ import {expect} from '@playwright/test';
import {initialize} from '../utils/e2e';
import {test} from '@playwright/test';
async function testHistory({page, path, referrer, urlHistory}: {page: any, path: string, urlHistory: any[]}) {
const {frame, lastApiRequest} = await initialize({page, title: 'Sign up', path});
async function testHistory({page, embeddedOnUrl, path, urlHistory, localStorageHistory}: {page: any, embeddedOnUrl?: string, path: string, urlHistory: any[], localStorageHistory?: any[]}) {
const {frame, lastApiRequest} = await initialize({page, title: 'Sign up', embeddedOnUrl, path});
await page.evaluate((history) => {
localStorage.setItem('ghost-history', JSON.stringify(history));
}, localStorageHistory);
// Fill out the form
const emailInput = frame.getByTestId('input');
@ -54,5 +58,43 @@ test.describe('Attribution', async () => {
]}
);
});
test('uses current localStorage history', async ({page}) => {
// Save history as localstorage item 'ghost-history'
const history = [
{path: '/p/573d2c92-183a-435f-b0e7-34595e1ceae7/', time: 1686667443580, referrerSource: null, referrerMedium: null, referrerUrl: 'http://admin.ghost/'},
{path: '/', time: 1686748392078, referrerSource: null, referrerMedium: null, referrerUrl: null}
];
await testHistory({
page,
path: '/my-custom-path/123?ref=ghost',
urlHistory: history,
localStorageHistory: history
});
});
test('does not use current localStorage history if on external site', async ({page}) => {
// Save history as localstorage item 'ghost-history'
const history = [
{path: '/p/573d2c92-183a-435f-b0e7-34595e1ceae7/', time: 1686667443580, referrerSource: null, referrerMedium: null, referrerUrl: 'http://admin.ghost/'},
{path: '/', time: 1686748392078, referrerSource: null, referrerMedium: null, referrerUrl: null}
];
await testHistory({
page,
embeddedOnUrl: 'https://example.com',
path: '/my-custom-path/123?ref=ghost',
urlHistory: [
{
referrerMedium: 'Embed',
referrerSource: 'example.com',
referrerUrl: 'https://example.com/my-custom-path/123',
time: expect.any(Number)
}
],
localStorageHistory: history
});
});
});

View File

@ -7,8 +7,8 @@ type LastApiRequest = {
body: null | any
};
export async function initialize({page, path, apiStatus, ...options}: {page: Page, path?: string; title?: string, description?: string, icon?: string, backgroundColor?: string, buttonColor?: string, site?: string, 'label-1'?: string, 'label-2'?: string, apiStatus?: number}) {
const sitePath = `${MOCKED_SITE_URL}${path ?? ''}`;
export async function initialize({page, path, apiStatus, embeddedOnUrl, ...options}: {page: Page, embeddedOnUrl?: string, path?: string; title?: string, description?: string, icon?: string, backgroundColor?: string, buttonColor?: string, site?: string, 'label-1'?: string, 'label-2'?: string, apiStatus?: number}) {
const sitePath = `${embeddedOnUrl ?? MOCKED_SITE_URL}${path ?? ''}`;
await page.route(sitePath, async (route) => {
await route.fulfill({
status: 200,