mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-25 03:45:41 +00:00
feat(testing): Added all tests for attachment and added download file support
This commit is contained in:
@@ -66,4 +66,26 @@ export default abstract class BasePage {
|
||||
]);
|
||||
await fileChooser.setFiles(filePath);
|
||||
}
|
||||
|
||||
async downloadAndGetFile({downloadUIAction}:{ downloadUIAction: Promise<any>,}) {
|
||||
const [ download ] = await Promise.all([
|
||||
// It is important to call waitForEvent before click to set up waiting.
|
||||
this.rootPage.waitForEvent('download'),
|
||||
// Triggers the download.
|
||||
downloadUIAction,
|
||||
]);
|
||||
// wait for download to complete
|
||||
if(await download.failure()) {
|
||||
throw new Error('Download failed');
|
||||
}
|
||||
|
||||
const file = await download.createReadStream();
|
||||
const data = await new Promise((resolve, reject) => {
|
||||
let data = '';
|
||||
file?.on('data', chunk => data += chunk);
|
||||
file?.on('end', () => resolve(data));
|
||||
file?.on('error', reject);
|
||||
});
|
||||
return data as any;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,28 @@ export class CellPageObject extends BasePage {
|
||||
index,
|
||||
columnHeader,
|
||||
}: {
|
||||
index: number;
|
||||
index?: number;
|
||||
columnHeader: string;
|
||||
}) {
|
||||
return this.get({ index, columnHeader }).dblclick();
|
||||
}
|
||||
|
||||
async fillText({
|
||||
index,
|
||||
columnHeader,
|
||||
text
|
||||
}: {
|
||||
index?: number;
|
||||
columnHeader: string;
|
||||
text: string;
|
||||
}) {
|
||||
await this.dblclick({
|
||||
index,
|
||||
columnHeader,
|
||||
});
|
||||
await this.get({ index, columnHeader }).locator("input").fill(text);
|
||||
}
|
||||
|
||||
async inCellExpand({
|
||||
index,
|
||||
columnHeader,
|
||||
|
||||
@@ -19,4 +19,8 @@ export class ToolbarActionsPage extends BasePage {
|
||||
async click(label: string) {
|
||||
await this.get().locator(`span:has-text("${label}")`).click();
|
||||
}
|
||||
|
||||
async clickDownloadSubmenu(label: string) {
|
||||
await this.rootPage.locator(`div[class="nc-project-menu-item"]:has-text("${label}")`).click();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,16 @@ export class SharedFormPage extends BasePage {
|
||||
}
|
||||
|
||||
async submit() {
|
||||
await this.get().locator('[pw-data="shared-form-submit-button"]').click();
|
||||
await this.waitForResponse({
|
||||
uiAction:this.get().locator('[pw-data="shared-form-submit-button"]').click(),
|
||||
httpMethodsToMatch: ["POST"],
|
||||
requestUrlPathToMatch: '/rows'
|
||||
});
|
||||
}
|
||||
|
||||
async verifySuccessMessage() {
|
||||
await expect(await this.get().locator('.ant-alert-success', {
|
||||
hasText: 'Successfully submitted form data'
|
||||
})).toBeVisible();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test } from "@playwright/test";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { DashboardPage } from "../pages/Dashboard";
|
||||
import { SharedFormPage } from "../pages/SharedForm";
|
||||
import setup from "../setup";
|
||||
@@ -12,7 +12,7 @@ test.describe("Attachment column", () => {
|
||||
dashboard = new DashboardPage(page, context.project);
|
||||
});
|
||||
|
||||
test("Create duration column", async ({page, context}) => {
|
||||
test.only("Create and verify atttachent column, verify it in shared form,", async ({page, context}) => {
|
||||
await dashboard.treeView.openTable({title: "Country"});
|
||||
await dashboard.grid.column.create({
|
||||
title: "testAttach",
|
||||
@@ -29,11 +29,34 @@ test.describe("Attachment column", () => {
|
||||
});
|
||||
await dashboard.form.toolbar.clickShareView();
|
||||
const sharedFormUrl = await dashboard.form.toolbar.shareView.getShareLink();
|
||||
await dashboard.form.toolbar.shareView.close();
|
||||
await dashboard.viewSidebar.openView({title: "Country"});
|
||||
|
||||
const newPage = await context.newPage()
|
||||
await newPage.goto(sharedFormUrl);
|
||||
|
||||
const sharedForm = new SharedFormPage(newPage);
|
||||
await sharedForm.cell.fillText({index: 0, columnHeader: "Country", text: "test"});
|
||||
await sharedForm.cell.attachment.addFile({columnHeader: 'testAttach', filePath: `${process.cwd()}/fixtures/sampleFiles/1.json`});
|
||||
await sharedForm.submit();
|
||||
await sharedForm.verifySuccessMessage();
|
||||
await newPage.close();
|
||||
|
||||
await dashboard.grid.toolbar.clickFields()
|
||||
await dashboard.grid.toolbar.fields.click({title: "LastUpdate"});
|
||||
await dashboard.grid.toolbar.clickActions();
|
||||
await dashboard.grid.toolbar.actions.click('Download');
|
||||
|
||||
const csvFileData: string = await dashboard.downloadAndGetFile({
|
||||
downloadUIAction: dashboard.grid.toolbar.actions.clickDownloadSubmenu('Download as CSV')
|
||||
});
|
||||
const csvArray = csvFileData.split('\r\n');
|
||||
const columns = csvArray[0];
|
||||
const rows = csvArray.slice(1);
|
||||
const cells = rows[4].split(',');
|
||||
|
||||
expect(columns).toBe('Country,City List,testAttach');
|
||||
expect(cells[0]).toBe('Anguilla');
|
||||
expect(cells[1]).toBe('South Hill');
|
||||
expect(cells[2].includes('4.json(http://localhost:8080/download/')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user