Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MYALayout } from '@e2etests/types';

export default class SiteSummaryReportPage extends MYALayout {
// Main Page Locators
readonly title = this.page.getByRole('heading', {
name: 'Download the report',
});

readonly selectDatesStep = {
stepTitle: this.page.getByRole('heading', {
name: 'Select the dates and run a report',
}),
goBackButton: this.page.getByRole('link', { name: 'Go back' }),
startDateInput: this.page.getByLabel('Start date'),
endDateInput: this.page.getByLabel('End date'),
continueButton: this.page.getByRole('button', { name: 'Create report' }),
};

readonly confirmDownloadStep = {
stepTitle: this.page.getByRole('heading', { name: 'Download the report' }),
goBackButton: this.page.getByRole('link', { name: 'Go back' }),
continueButton: this.page.getByRole('button', { name: 'Export data' }),
};

async downloadReport() {
const downloadPromise = this.page.waitForEvent('download');
await this.confirmDownloadStep.continueButton.click();
return await downloadPromise;
}
}
39 changes: 27 additions & 12 deletions src/client/testing/page-objects-v2/site/site-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MYALayout } from '@e2etests/types';
import SiteDetailsPage from './details/site-details-page';
import Users from '../manage-user/users';
import { expect } from '@playwright/test';
import SiteSummaryReportPage from './details/site-summary-report-page';

export default class SitePage extends MYALayout {
title = this.page.getByRole('heading', {
Expand Down Expand Up @@ -33,12 +34,21 @@ export default class SitePage extends MYALayout {
name: 'View availability and manage appointments for your site',
});

// async clickViewAvailabilityCard(): Promise<MonthViewPage> {
// await this.viewAvailabilityAndManageAppointmentsCard.click();
// await this.page.waitForURL(`**/site/${this.site.id}/view-availability`);
readonly reportsCard: Locator = this.page
.getByRole('main')
.getByRole('link', {
name: 'Report',
});

// return new MonthViewPage(this.page, this.site);
// }
readonly topNav = {
reportsLink: this.page.getByRole('link', { name: 'Reports', exact: true }),

clickReports: async (): Promise<SiteSummaryReportPage> => {
await this.topNav.reportsLink.click();
await this.page.waitForURL(`**/reports`);
return new SiteSummaryReportPage(this.page, this.site);
},
};

async clickSiteDetailsCard(): Promise<SiteDetailsPage> {
await this.siteManagementCard.click();
Expand All @@ -47,19 +57,24 @@ export default class SitePage extends MYALayout {
return new SiteDetailsPage(this.page, this.site);
}

// async clickCreateAvailabilityCard(): Promise<CreateAvailabilityPage> {
// await this.createAvailabilityCard.click();
// await this.page.waitForURL(`**/site/${this.site.id}/create-availability`);

// return new CreateAvailabilityPage(this.page, this.site);
// }

async clickManageUsersCard(): Promise<Users> {
await this.userManagementCard.click();
await this.page.waitForURL(`**/site/${this.site?.id}/users`);
return new Users(this.page, this.site);
}

async clickReportsCard(): Promise<SiteSummaryReportPage> {
await this.reportsCard.click();
await this.page.waitForURL(`**/reports`);
return new SiteSummaryReportPage(this.page, this.site);
}

async clickSiteSummaryReportLink(): Promise<SiteSummaryReportPage> {
await this.page.getByRole('link', { name: 'Report' }).click();
await this.page.waitForURL(`**/site/${this.site?.id}/report`);
return new SiteSummaryReportPage(this.page, this.site);
}

async verifyTileVisible(
tileName:
| 'ManageAppointment'
Expand Down
107 changes: 107 additions & 0 deletions src/client/testing/tests-v2/reports/download-report.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import * as fs from 'fs';
import { test, expect } from '../../fixtures-v2';

test.describe.configure({ mode: 'serial' });

test('Navigates to the reports page via the header before selecting a site', async ({
setUpSingleSite,
}) => {
await setUpSingleSite({
features: [{ name: 'SiteSummaryReport', enabled: true }],
})
.then(async sitePageFixture => sitePageFixture.sitePage.topNav.clickReports())
.then(async reportsPage => {
await expect(reportsPage.selectDatesStep.stepTitle).toBeVisible();
});
});

test('Navigates to the reports page via a site page', async ({
setUpSingleSite,
}) => {
await setUpSingleSite({
features: [{ name: 'SiteSummaryReport', enabled: true }],
})
.then(async sitePageFixture => sitePageFixture.sitePage.clickReportsCard())
.then(async reportsPage => {
await expect(reportsPage.selectDatesStep.stepTitle).toBeVisible();
});
});

test('Downloads a site summary report', async ({ page, setUpSingleSite }) => {
const fileName = 'downloaded-test-report.csv';

await setUpSingleSite({
features: [{ name: 'SiteSummaryReport', enabled: true }],
})
.then(async sitePageFixture => sitePageFixture.sitePage.topNav.clickReports())
.then(async reportsPage => {
const today: string = new Date().toISOString().split('T')[0];
await reportsPage.selectDatesStep.startDateInput.fill(today);
await reportsPage.selectDatesStep.endDateInput.fill(today);
await reportsPage.selectDatesStep.continueButton.click();

await expect(reportsPage.confirmDownloadStep.stepTitle).toBeVisible();

const downloadPromise = page.waitForEvent('download');
await reportsPage.confirmDownloadStep.continueButton.click();
return downloadPromise;
})
.then(async download => {
expect(download.suggestedFilename()).toContain(
'GeneralSiteSummaryReport',
);
await download.saveAs(fileName);

const csvContent = fs.readFileSync(fileName, 'utf-8');
const lines = csvContent
.split('\n')
.filter(line => line.trim().length > 0);

// Normalize headers by splitting and trimming whitespace/line endings
const headers = lines[0].split(',').map(h => h.trim());

expect(lines.length).toBeGreaterThan(1);
expect(headers).toEqual(expectedFileDownloadHeaders);
})
.finally(() => {
if (fs.existsSync(fileName)) {
fs.unlinkSync(fileName);
}
});
});

const expectedFileDownloadHeaders = [
'Site Name',
'Status',
'Site Type',
'ICB',
'ICB Name',
'Region',
'Region Name',
'ODS Code',
'Longitude',
'Latitude',
'FLU:2_3 Booked',
'FLU:18_64 Booked',
'FLU:65+ Booked',
'COVID:5_11 Booked',
'COVID:12_17 Booked',
'COVID:18+ Booked',
'COVID_FLU:18_64 Booked',
'COVID_FLU:65+ Booked',
'RSV:Adult Booked',
'COVID_RSV:18+ Booked',
'Total Bookings',
'Cancelled',
'Maximum Capacity',
'FLU:2_3 Capacity',
'FLU:18_64 Capacity',
'FLU:65+ Capacity',
'COVID:5_11 Capacity',
'COVID:12_17 Capacity',
'COVID:18+ Capacity',
'COVID_FLU:18_64 Capacity',
'COVID_FLU:65+ Capacity',
'RSV:Adult Capacity',
'COVID_RSV:18+ Capacity',
];
119 changes: 0 additions & 119 deletions src/client/testing/tests/reports/download-report.spec.ts

This file was deleted.