Browse Source

feat(playwrights): add download xlsx test

pull/4581/head
Wing-Kam Wong 2 years ago
parent
commit
e0c67ae656
  1. 40
      tests/playwright/pages/Dashboard/common/Toolbar/ViewMenu.ts
  2. 20
      tests/playwright/tests/viewMenu.spec.ts

40
tests/playwright/pages/Dashboard/common/Toolbar/ViewMenu.ts

@ -4,6 +4,7 @@ import { GridPage } from '../../Grid';
import { ToolbarPage } from './index'; import { ToolbarPage } from './index';
// @ts-ignore // @ts-ignore
import fs from 'fs'; import fs from 'fs';
import XLSX from 'xlsx';
export class ToolbarViewMenuPage extends BasePage { export class ToolbarViewMenuPage extends BasePage {
readonly toolbar: ToolbarPage; readonly toolbar: ToolbarPage;
@ -46,6 +47,33 @@ export class ToolbarViewMenuPage extends BasePage {
await expect(file).toEqual(expectedData); await expect(file).toEqual(expectedData);
} }
async verifyDownloadAsXLSX({
downloadLocator,
expectedDataFile,
}: {
downloadLocator: Locator;
expectedDataFile: string;
}) {
const [download] = await Promise.all([
// Start waiting for the download
this.rootPage.waitForEvent('download'),
// Perform the action that initiates download
downloadLocator.click(),
]);
// Save downloaded file somewhere
await download.saveAs('./output/at.xlsx');
// convert xlsx to csv
const wb = XLSX.readFile('./output/at.xlsx');
XLSX.writeFile(wb, './output/at.txt', { bookType: 'csv' });
// verify downloaded content against expected content
const expectedData = fs.readFileSync(expectedDataFile, 'utf8');
const file = fs.readFileSync('./output/at.txt', 'utf8');
await expect(file).toEqual(expectedData);
}
// menu items // menu items
// Collaborative View // Collaborative View
// Download // Download
@ -68,6 +96,13 @@ export class ToolbarViewMenuPage extends BasePage {
.last(), .last(),
expectedDataFile: verificationInfo?.verificationFile ?? './fixtures/expectedBaseDownloadData.txt', expectedDataFile: verificationInfo?.verificationFile ?? './fixtures/expectedBaseDownloadData.txt',
}); });
} else if (subMenu === 'Download as XLSX') {
await this.verifyDownloadAsXLSX({
downloadLocator: await this.rootPage
.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`)
.last(),
expectedDataFile: verificationInfo?.verificationFile ?? './fixtures/expectedBaseDownloadData.txt',
});
} else { } else {
await this.rootPage.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`).last().click(); await this.rootPage.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`).last().click();
} }
@ -78,6 +113,11 @@ export class ToolbarViewMenuPage extends BasePage {
message: 'Successfully exported all table data', message: 'Successfully exported all table data',
}); });
break; break;
case 'Download as XLSX':
await this.verifyToast({
message: 'Successfully exported all table data',
});
break;
case 'Locked View': case 'Locked View':
await this.verifyToast({ await this.verifyToast({
message: 'Successfully Switched to locked view', message: 'Successfully Switched to locked view',

20
tests/playwright/tests/viewMenu.spec.ts

@ -56,4 +56,24 @@ test.describe('Grid view locked', () => {
}, },
}); });
}); });
test.only('Download XLSX', async () => {
// close 'Team & Auth' tab
await dashboard.closeTab({ title: 'Team & Auth' });
await dashboard.treeView.openTable({ title: 'Country' });
await dashboard.grid.toolbar.clickFields();
// Hide 'LastUpdate' column
await dashboard.grid.toolbar.fields.click({
title: 'LastUpdate',
});
await dashboard.grid.toolbar.viewsMenu.click({
menu: 'Download',
subMenu: 'Download as XLSX',
verificationInfo: {
verificationFile: isPg(context) ? './fixtures/expectedBaseDownloadDataPg.txt' : null,
},
});
});
}); });

Loading…
Cancel
Save