mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
e61b62e6be
refs https://github.com/TryGhost/Product/issues/3349 - added a download handler for the analytics download button. - wired up the download api endpoint <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 46054be</samp> This pull request adds a feature to export post analytics as a csv file from the membership analytics dashboard. It implements a new query hook, a download function, and a response handler in the `apps/admin-x-settings` app, and adds a test case for the feature.
57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
import {expect, test} from '@playwright/test';
|
|
import {globalDataRequests, mockApi, updatedSettingsResponse} from '../../utils/e2e';
|
|
|
|
test.describe('Analytics settings', async () => {
|
|
test('Supports toggling analytics settings', async ({page}) => {
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
...globalDataRequests,
|
|
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
|
|
{key: 'members_track_sources', value: false},
|
|
{key: 'email_track_opens', value: false},
|
|
{key: 'email_track_clicks', value: false},
|
|
{key: 'outbound_link_tagging', value: false}
|
|
])}
|
|
}});
|
|
|
|
await page.goto('/');
|
|
|
|
const section = page.getByTestId('analytics');
|
|
|
|
await expect(section.getByLabel(/Newsletter opens/)).toBeChecked();
|
|
await expect(section.getByLabel(/Newsletter clicks/)).toBeChecked();
|
|
await expect(section.getByLabel(/Member sources/)).toBeChecked();
|
|
await expect(section.getByLabel(/Outbound link tagging/)).toBeChecked();
|
|
|
|
await section.getByLabel(/Newsletter opens/).uncheck();
|
|
await section.getByLabel(/Newsletter clicks/).uncheck();
|
|
await section.getByLabel(/Member sources/).uncheck();
|
|
await section.getByLabel(/Outbound link tagging/).uncheck();
|
|
|
|
await section.getByRole('button', {name: 'Save'}).click();
|
|
|
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
|
settings: [
|
|
{key: 'members_track_sources', value: false},
|
|
{key: 'email_track_opens', value: false},
|
|
{key: 'email_track_clicks', value: false},
|
|
{key: 'outbound_link_tagging', value: false}
|
|
]
|
|
});
|
|
});
|
|
|
|
test('Supports downloading analytics csv export', async ({page}) => {
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
...globalDataRequests,
|
|
postsExport: {method: 'GET', path: '/posts/export/?limit=1000', response: 'csv data'}
|
|
}});
|
|
|
|
await page.goto('/');
|
|
|
|
const section = page.getByTestId('analytics');
|
|
|
|
await section.getByRole('button', {name: 'Export analytics'}).click();
|
|
|
|
const hasDownloadUrl = lastApiRequests.postsExport?.url?.includes('/posts/export/?limit=1000');
|
|
expect(hasDownloadUrl).toBe(true);
|
|
});
|
|
});
|