mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
6.0 KiB
181 lines
6.0 KiB
2 years ago
|
import { expect } from '@playwright/test';
|
||
|
import BasePage from '../../../Base';
|
||
|
import { ToolbarFieldsPage } from './Fields';
|
||
|
import { ToolbarSortPage } from './Sort';
|
||
|
import { ToolbarFilterPage } from './Filter';
|
||
|
import { ToolbarShareViewPage } from './ShareView';
|
||
|
import { ToolbarViewMenuPage } from './ViewMenu';
|
||
|
import * as fs from 'fs';
|
||
|
import { GridPage } from '../../Grid';
|
||
|
import { ToolbarActionsPage } from './Actions';
|
||
|
import { GalleryPage } from '../../Gallery';
|
||
|
import { KanbanPage } from '../../Kanban';
|
||
|
import { FormPage } from '../../Form';
|
||
|
import { ToolbarStackbyPage } from './StackBy';
|
||
|
import { ToolbarAddEditStackPage } from './AddEditKanbanStack';
|
||
2 years ago
|
|
||
|
export class ToolbarPage extends BasePage {
|
||
2 years ago
|
readonly parent: GridPage | GalleryPage | FormPage | KanbanPage;
|
||
2 years ago
|
readonly fields: ToolbarFieldsPage;
|
||
|
readonly sort: ToolbarSortPage;
|
||
|
readonly filter: ToolbarFilterPage;
|
||
2 years ago
|
readonly shareView: ToolbarShareViewPage;
|
||
2 years ago
|
readonly viewsMenu: ToolbarViewMenuPage;
|
||
2 years ago
|
readonly actions: ToolbarActionsPage;
|
||
2 years ago
|
readonly stackBy: ToolbarStackbyPage;
|
||
2 years ago
|
readonly addEditStack: ToolbarAddEditStackPage;
|
||
2 years ago
|
|
||
2 years ago
|
constructor(parent: GridPage | GalleryPage | FormPage | KanbanPage) {
|
||
2 years ago
|
super(parent.rootPage);
|
||
|
this.parent = parent;
|
||
2 years ago
|
this.fields = new ToolbarFieldsPage(this);
|
||
|
this.sort = new ToolbarSortPage(this);
|
||
|
this.filter = new ToolbarFilterPage(this);
|
||
2 years ago
|
this.shareView = new ToolbarShareViewPage(this);
|
||
2 years ago
|
this.viewsMenu = new ToolbarViewMenuPage(this);
|
||
2 years ago
|
this.actions = new ToolbarActionsPage(this);
|
||
2 years ago
|
this.stackBy = new ToolbarStackbyPage(this);
|
||
2 years ago
|
this.addEditStack = new ToolbarAddEditStackPage(this);
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
|
return this.rootPage.locator(`.nc-table-toolbar`);
|
||
|
}
|
||
|
|
||
2 years ago
|
async clickActions() {
|
||
|
const menuOpen = await this.actions.get().isVisible();
|
||
|
|
||
|
await this.get().locator(`button.nc-actions-menu-btn`).click();
|
||
|
|
||
|
// Wait for the menu to close
|
||
2 years ago
|
if (menuOpen) await this.fields.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async clickFields() {
|
||
2 years ago
|
const menuOpen = await this.fields.get().isVisible();
|
||
|
|
||
2 years ago
|
await this.get().locator(`button.nc-fields-menu-btn`).click();
|
||
2 years ago
|
|
||
|
// Wait for the menu to close
|
||
2 years ago
|
if (menuOpen) await this.fields.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
|
|
||
|
async clickSort() {
|
||
2 years ago
|
const menuOpen = await this.sort.get().isVisible();
|
||
|
|
||
2 years ago
|
await this.get().locator(`button.nc-sort-menu-btn`).click();
|
||
2 years ago
|
|
||
|
// Wait for the menu to close
|
||
2 years ago
|
if (menuOpen) await this.sort.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
|
|
||
|
async clickFilter() {
|
||
2 years ago
|
const menuOpen = await this.filter.get().isVisible();
|
||
|
|
||
2 years ago
|
await this.get().locator(`button.nc-filter-menu-btn`).click();
|
||
2 years ago
|
|
||
|
// Wait for the menu to close
|
||
2 years ago
|
if (menuOpen) await this.filter.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async clickShareView() {
|
||
2 years ago
|
const menuOpen = await this.shareView.get().isVisible();
|
||
2 years ago
|
await this.get().locator(`button.nc-btn-share-view `).click();
|
||
2 years ago
|
|
||
|
// Wait for the menu to close
|
||
2 years ago
|
if (menuOpen) await this.shareView.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async clickStackByField() {
|
||
2 years ago
|
await this.get().locator(`.nc-toolbar-btn.nc-kanban-stacked-by-menu-btn`).click();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async clickAddNewRow() {
|
||
2 years ago
|
await this.get().locator(`.nc-toolbar-btn.nc-add-new-row-btn`).click();
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async clickDownload(type: string, verificationFile = 'expectedData.txt') {
|
||
2 years ago
|
await this.get().locator(`.nc-toolbar-btn.nc-actions-menu-btn`).click();
|
||
|
|
||
|
const [download] = await Promise.all([
|
||
|
// Start waiting for the download
|
||
2 years ago
|
this.rootPage.waitForEvent('download'),
|
||
2 years ago
|
// Perform the action that initiates download
|
||
|
this.rootPage
|
||
|
.locator(`.nc-dropdown-actions-menu`)
|
||
|
.locator(`li.ant-dropdown-menu-item:has-text("${type}")`)
|
||
|
.click(),
|
||
|
]);
|
||
|
|
||
|
// Save downloaded file somewhere
|
||
2 years ago
|
await download.saveAs('./output/at.txt');
|
||
2 years ago
|
|
||
|
// verify downloaded content against expected content
|
||
2 years ago
|
const expectedData = fs.readFileSync(`./fixtures/${verificationFile}`, 'utf8');
|
||
2 years ago
|
const file = fs.readFileSync('./output/at.txt', 'utf8');
|
||
2 years ago
|
await expect(file).toEqual(expectedData);
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async verifyStackByButton({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator(`.nc-toolbar-btn.nc-kanban-stacked-by-menu-btn`).waitFor({ state: 'visible' });
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
await this.get().locator(`.nc-toolbar-btn.nc-kanban-stacked-by-menu-btn:has-text("${title}")`)
|
||
2 years ago
|
).toBeVisible();
|
||
|
}
|
||
|
|
||
2 years ago
|
async verifyDownloadDisabled() {
|
||
2 years ago
|
await this.get().locator(`.nc-toolbar-btn.nc-actions-menu-btn`).waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async clickAddEditStack() {
|
||
|
await this.get().locator(`.nc-kanban-add-edit-stack-menu-btn`).click();
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async validateViewsMenu(param: { role: string; mode?: string }) {
|
||
2 years ago
|
let menuItems = {
|
||
2 years ago
|
creator: ['Download', 'Upload', 'Shared View List', 'Webhooks', 'Get API Snippet', 'ERD View'],
|
||
|
editor: ['Download', 'Upload', 'Get API Snippet', 'ERD View'],
|
||
|
commenter: ['Download as CSV', 'Download as XLSX'],
|
||
|
viewer: ['Download as CSV', 'Download as XLSX'],
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
if (param.mode === 'shareBase') {
|
||
2 years ago
|
menuItems = {
|
||
|
creator: [],
|
||
2 years ago
|
editor: ['Download', 'Upload', 'ERD View'],
|
||
2 years ago
|
commenter: [],
|
||
2 years ago
|
viewer: ['Download as CSV', 'Download as XLSX'],
|
||
2 years ago
|
};
|
||
|
}
|
||
|
|
||
2 years ago
|
const vMenu = await this.rootPage.locator('.nc-dropdown-actions-menu:visible');
|
||
2 years ago
|
|
||
2 years ago
|
for (const item of menuItems[param.role]) {
|
||
2 years ago
|
await expect(vMenu).toContainText(item);
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
async validateRoleAccess(param: { role: string; mode?: string }) {
|
||
2 years ago
|
await this.clickActions();
|
||
|
await this.validateViewsMenu({
|
||
|
role: param.role,
|
||
2 years ago
|
mode: param.mode,
|
||
2 years ago
|
});
|
||
|
|
||
2 years ago
|
const menuItems = {
|
||
|
creator: ['Fields', 'Filter', 'Sort', 'Share View'],
|
||
|
editor: ['Fields', 'Filter', 'Sort'],
|
||
|
commenter: ['Fields', 'Filter', 'Sort', 'Download'],
|
||
|
viewer: ['Fields', 'Filter', 'Sort', 'Download'],
|
||
2 years ago
|
};
|
||
|
|
||
2 years ago
|
for (const item of menuItems[param.role]) {
|
||
2 years ago
|
await expect(this.get()).toContainText(item);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
await expect(this.get().locator('.nc-add-new-row-btn')).toHaveCount(
|
||
|
param.role === 'creator' || param.role === 'editor' ? 1 : 0
|
||
2 years ago
|
);
|
||
|
}
|
||
2 years ago
|
}
|