Skip to content

Commit

Permalink
add visualize test for tsvb
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed May 4, 2022
1 parent 7c7e00d commit 366a28a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 29 deletions.
2 changes: 1 addition & 1 deletion x-pack/test/examples/reporting_examples/capture_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await PageObjects.reporting.clickGenerateReportButton();
const url = await PageObjects.reporting.getReportURL(60000);
const captureData = await PageObjects.reporting.getRawPdfReportData(url);
const captureData = await PageObjects.reporting.getRawScreenshotReportData(url);

const pngSessionFilePath = await compareImages.writeToSessionFile(
'capture_test_baseline_a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.reporting.removeForceSharedItemsContainerSize();

const url = await PageObjects.reporting.getReportURL(60000);
const reportData = await PageObjects.reporting.getRawPdfReportData(url);
const reportData = await PageObjects.reporting.getRawScreenshotReportData(url);
const reportFileName = 'small_dashboard_preserve_layout';
const sessionReportPath = await PageObjects.reporting.writeSessionReport(
reportFileName,
Expand Down Expand Up @@ -190,7 +190,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.reporting.removeForceSharedItemsContainerSize();

const url = await PageObjects.reporting.getReportURL(200000);
const reportData = await PageObjects.reporting.getRawPdfReportData(url);
const reportData = await PageObjects.reporting.getRawScreenshotReportData(url);
const reportFileName = 'large_dashboard_preserve_layout';
const sessionReportPath = await PageObjects.reporting.writeSessionReport(
reportFileName,
Expand Down Expand Up @@ -285,7 +285,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.reporting.removeForceSharedItemsContainerSize();

const url = await PageObjects.reporting.getReportURL(60000);
const reportData = await PageObjects.reporting.getRawPdfReportData(url);
const reportData = await PageObjects.reporting.getRawScreenshotReportData(url);
sessionReportPath = await PageObjects.reporting.writeSessionReport(
reportFileName,
'png',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/maps/reports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
// helper function to check the difference between the new image and the baseline
const measurePngDifference = async (fileName: string) => {
const url = await PageObjects.reporting.getReportURL(60000);
const reportData = await PageObjects.reporting.getRawPdfReportData(url);
const reportData = await PageObjects.reporting.getRawScreenshotReportData(url);

const sessionReportPath = await PageObjects.reporting.writeSessionReport(
fileName,
Expand Down
109 changes: 87 additions & 22 deletions x-pack/test/functional/apps/visualize/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
*/

import expect from '@kbn/expect';
import path from 'path';
import { FtrProviderContext } from '../../ftr_provider_context';

const REPORTS_FOLDER = path.resolve(__dirname, 'reports');

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const es = getService('es');
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const log = getService('log');
const config = getService('config');
const kibanaServer = getService('kibanaServer');
const ecommerceSOPath = 'x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce.json';
const reporting = getService('reporting');

const PageObjects = getPageObjects([
'reporting',
Expand All @@ -26,28 +30,42 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
]);

describe('Visualize Reporting Screenshots', () => {
before('initialize tests', async () => {
log.debug('ReportingPage:initTests');
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/reporting/ecommerce');
await kibanaServer.importExport.load(ecommerceSOPath);
before(async () => {
await browser.setWindowSize(1600, 850);
await kibanaServer.uiSettings.replace({
'timepicker:timeDefaults':
'{ "from": "2019-04-27T23:56:51.374Z", "to": "2019-08-23T16:18:51.821Z"}',
});
});
after('clean up archives', async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/ecommerce');
await kibanaServer.importExport.unload(ecommerceSOPath);
after(async () => {
await es.deleteByQuery({
index: '.reporting-*',
refresh: true,
body: { query: { match_all: {} } },
});
await kibanaServer.uiSettings.unset('timepicker:timeDefaults');
});

describe('Print PDF button', () => {
const ecommerceSOPath =
'x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce.json';

before('initialize tests', async () => {
log.debug('ReportingPage:initTests');
await esArchiver.load('x-pack/test/functional/es_archives/reporting/ecommerce');
await kibanaServer.importExport.load(ecommerceSOPath);
await kibanaServer.uiSettings.replace({
'timepicker:timeDefaults':
'{ "from": "2019-04-27T23:56:51.374Z", "to": "2019-08-23T16:18:51.821Z"}',
defaultIndex: '5193f870-d861-11e9-a311-0fa548c5f953',
});
});
after('clean up archives', async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/ecommerce');
await kibanaServer.importExport.unload(ecommerceSOPath);
await es.deleteByQuery({
index: '.reporting-*',
refresh: true,
body: { query: { match_all: {} } },
});
await kibanaServer.uiSettings.unset('timepicker:timeDefaults');
});

it('is available if new', async () => {
await PageObjects.common.navigateToUrl('visualize', 'new', { useActualUrl: true });
await PageObjects.visualize.clickAggBasedVisualizations();
Expand All @@ -65,21 +83,68 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.reporting.openPdfReportingPanel();
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be(null);
});
});

it('downloaded PDF has OK status', async function () {
// Generating and then comparing reports can take longer than the default 60s timeout
this.timeout(180000);
describe('PNG reports: sample data created in 7.6', () => {
const reportFileName = 'tsvb';
let sessionReportPath: string;

await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.loadSavedDashboard('Ecom Dashboard');
await PageObjects.reporting.openPdfReportingPanel();
before(async () => {
await kibanaServer.uiSettings.replace({
defaultIndex: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f',
});

await esArchiver.load('x-pack/test/functional/es_archives/reporting/ecommerce_76');
await kibanaServer.importExport.load(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce_76.json'
);

log.debug('navigate to visualize');
await PageObjects.common.navigateToApp('visualize');
log.debug('load saved visualization');
await PageObjects.visualize.loadSavedVisualization(
'[K7.6-eCommerce] Sold Products per Day',
{ navigateToVisualize: false }
);
log.debug('set time range');
await PageObjects.timePicker.setAbsoluteRange(
'Apr 15, 2022 @ 00:00:00.000',
'May 22, 2022 @ 00:00:00.000'
);

log.debug('open png reporting panel');
await PageObjects.reporting.openPngReportingPanel();
log.debug('click generate report button');
await PageObjects.reporting.clickGenerateReportButton();

log.debug('get the report download URL');
const url = await PageObjects.reporting.getReportURL(60000);
const res = await PageObjects.reporting.getResponse(url);
log.debug('download the report');
const reportData = await PageObjects.reporting.getRawScreenshotReportData(url);
sessionReportPath = await PageObjects.reporting.writeSessionReport(
reportFileName,
'png',
reportData,
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 () {
const percentDiff = await reporting.checkIfPngsMatch(
sessionReportPath,
PageObjects.reporting.getBaselineReportPath(reportFileName, 'png', REPORTS_FOLDER),
config.get('screenshots.directory'),
log
);

expect(res.status).to.equal(200);
expect(res.get('content-type')).to.equal('application/pdf');
expect(percentDiff).to.be.lessThan(0.09);
});
});
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions x-pack/test/functional/page_objects/reporting_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class ReportingPageObject extends FtrService {
return res;
}

async getRawPdfReportData(url: string): Promise<Buffer> {
this.log.debug(`getRawPdfReportData for ${url}`);
async getRawScreenshotReportData(url: string): Promise<Buffer> {
this.log.debug(`getRawScreenshotReportData for ${url}`);
const response = await this.getResponse(url);
expect(response.body).to.be.a(Buffer);
return response.body as Buffer;
Expand Down

0 comments on commit 366a28a

Please sign in to comment.