test: download csv

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
This commit is contained in:
Raju Udava
2022-10-20 16:50:11 +05:30
committed by Muhammed Mustafa
parent dc3f150c06
commit 31917d23ab
3 changed files with 172 additions and 6 deletions

View File

@@ -2,6 +2,8 @@ import { Locator, expect } from "@playwright/test";
import BasePage from "../../../Base";
import { GridPage } from "../../Grid";
import { ToolbarPage } from "./index";
// @ts-ignore
import fs from "fs";
export class ToolbarViewMenuPage extends BasePage {
readonly toolbar: ToolbarPage;
@@ -21,6 +23,29 @@ export class ToolbarViewMenuPage extends BasePage {
return this.rootPage.locator(`[id="sub_menu_1_$$_lock-type-popup"]`);
}
async verifyDownloadAsCSV({
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("./at.txt");
// verify downloaded content against expected content
const expectedData = fs.readFileSync(expectedDataFile, "utf8");
const file = fs.readFileSync("./at.txt", "utf8");
await expect(file).toEqual(expectedData);
}
// menu items
// Collaborative View
// Download
@@ -37,11 +62,27 @@ export class ToolbarViewMenuPage extends BasePage {
.first()
.click();
if (subMenu) {
await this.getLockTypeSubMenu()
.locator(`.nc-locked-menu-item:has-text("${subMenu}")`)
.last()
.click();
// for CSV download, pass locator instead of clicking it here
if (subMenu === "Download as CSV") {
await this.verifyDownloadAsCSV({
downloadLocator: await this.rootPage
.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`)
.last(),
expectedDataFile: "./fixtures/expectedBaseDownloadData.txt",
});
} else {
await this.rootPage
.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`)
.last()
.click();
}
switch (subMenu) {
case "Download as CSV":
await this.toastWait({
message: "Successfully exported all table data",
});
break;
case "Locked View":
await this.toastWait({
message: "Successfully Switched to locked view",
@@ -75,7 +116,9 @@ export class ToolbarViewMenuPage extends BasePage {
.locator(`.nc-add-new-row-btn.nc-toolbar-btn > .nc-icon.disabled`)
).toBeVisible();
await (this.toolbar.parent as GridPage).verifyEditDisabled({ columnHeader: "Country" });
await (this.toolbar.parent as GridPage).verifyEditDisabled({
columnHeader: "Country",
});
}
async verifyCollaborativeMode() {
@@ -94,6 +137,8 @@ export class ToolbarViewMenuPage extends BasePage {
.locator(`.nc-add-new-row-btn.nc-toolbar-btn > .nc-icon`)
).toBeVisible();
await (this.toolbar.parent as GridPage).verifyEditEnabled({ columnHeader: "Country" });
await (this.toolbar.parent as GridPage).verifyEditEnabled({
columnHeader: "Country",
});
}
}