Skip to content

Commit

Permalink
Test code for visual regression testing of PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Aug 27, 2024
1 parent f5b5e92 commit 4cf61d5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1816,4 +1816,4 @@
"zod-to-json-schema": "^3.23.0"
},
"packageManager": "[email protected]"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## `reporting/reports` folder

`x-pack/test/functional/apps/dashboard/group?/reporting/reports/__snapshots__`: this folder contains snapshots
(PNG files) used for PDF visual regression testing. In the testing library we use, "pdf-visual-diff", it is
necessary to convert PDF files to PNG, and compare the result to the snapshots located in this folder.

`x-pack/test/functional/apps/dashboard/group?/reporting/reports/baseline`: this folder contains the snapshots
for PNG regression testing via "pngjs"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import expect from '@kbn/expect';
import path from 'path';
import { comparePdfToSnapshot } from 'pdf-visual-diff';
import { FtrProviderContext } from '../../../../ftr_provider_context';

const REPORTS_FOLDER = path.resolve(__dirname, 'reports');
Expand Down Expand Up @@ -199,6 +200,40 @@ export default function ({

await PageObjects.dashboard.navigateToApp();
await PageObjects.dashboard.loadSavedDashboard('[K7.6-eCommerce] Revenue Dashboard');
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/ecommerce_76');
await kibanaServer.importExport.unload(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce_76.json'
);
});

it('PDF file matches the baseline image', async function () {
this.timeout(300000);

await PageObjects.reporting.openExportTab();
await testSubjects.click('printablePdfV2-radioOption');
await PageObjects.reporting.forceSharedItemsContainerSize({ width: 1405 });
await PageObjects.reporting.clickGenerateReportButton();
await PageObjects.reporting.removeForceSharedItemsContainerSize();

const url = await PageObjects.reporting.getReportURL(60000);
const reportData = await PageObjects.reporting.getRawReportData(url ?? '');
sessionReportPath = await PageObjects.reporting.writeSessionReport(
reportFileName,
'pdf',
reportData,
REPORTS_FOLDER
);
const x = await comparePdfToSnapshot(sessionReportPath, REPORTS_FOLDER, reportFileName, {
tolerance: 0.035,
});
expect(x).to.be(true);
});

it('PNG file matches the baseline image', async function () {
this.timeout(300000);

await PageObjects.reporting.openExportTab();
await testSubjects.click('pngV2-radioOption');
Expand All @@ -219,17 +254,6 @@ export default function ({
'png',
REPORTS_FOLDER
);
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/ecommerce_76');
await kibanaServer.importExport.unload(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce_76.json'
);
});

it('PNG file matches the baseline image', async function () {
this.timeout(300000);
const percentDiff = await png.compareAgainstBaseline(
sessionReportPath,
baselinePath,
Expand Down

0 comments on commit 4cf61d5

Please sign in to comment.