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.
139 lines
5.3 KiB
139 lines
5.3 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
2 years ago
|
import { DashboardPage } from '..';
|
||
2 years ago
|
import BasePage from '../../Base';
|
||
2 years ago
|
|
||
|
export class ViewSidebarPage extends BasePage {
|
||
|
readonly project: any;
|
||
|
readonly dashboard: DashboardPage;
|
||
|
readonly createGalleryButton: Locator;
|
||
|
readonly createGridButton: Locator;
|
||
|
readonly createFormButton: Locator;
|
||
|
readonly createKanbanButton: Locator;
|
||
|
|
||
|
constructor(dashboard: DashboardPage) {
|
||
|
super(dashboard.rootPage);
|
||
|
this.dashboard = dashboard;
|
||
2 years ago
|
this.createGalleryButton = this.get().locator('.nc-create-gallery-view:visible');
|
||
|
this.createGridButton = this.get().locator('.nc-create-grid-view:visible');
|
||
|
this.createFormButton = this.get().locator('.nc-create-form-view:visible');
|
||
|
this.createKanbanButton = this.get().locator('.nc-create-kanban-view:visible');
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
2 years ago
|
return this.dashboard.get().locator('.nc-view-sidebar');
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
private async createView({ title, locator }: { title: string; locator: Locator }) {
|
||
2 years ago
|
await locator.click();
|
||
2 years ago
|
await this.rootPage.locator('input[id="form_item_title"]:visible').fill(title);
|
||
2 years ago
|
const submitAction = this.rootPage
|
||
2 years ago
|
.locator('.ant-modal-content')
|
||
2 years ago
|
.locator('button:has-text("Submit"):visible')
|
||
|
.click();
|
||
2 years ago
|
await this.waitForResponse({
|
||
2 years ago
|
httpMethodsToMatch: ['POST'],
|
||
|
requestUrlPathToMatch: '/api/v1/db/meta/tables/',
|
||
2 years ago
|
uiAction: submitAction,
|
||
2 years ago
|
responseJsonMatcher: json => json.title === title,
|
||
2 years ago
|
});
|
||
2 years ago
|
await this.verifyToast({ message: 'View created successfully' });
|
||
2 years ago
|
// Todo: Wait for view to be rendered
|
||
|
await this.rootPage.waitForTimeout(1000);
|
||
2 years ago
|
}
|
||
|
|
||
|
async createGalleryView({ title }: { title: string }) {
|
||
|
await this.createView({ title, locator: this.createGalleryButton });
|
||
|
}
|
||
|
|
||
|
async createGridView({ title }: { title: string }) {
|
||
|
await this.createView({ title, locator: this.createGridButton });
|
||
|
}
|
||
|
|
||
|
async createFormView({ title }: { title: string }) {
|
||
|
await this.createView({ title, locator: this.createFormButton });
|
||
|
}
|
||
|
|
||
2 years ago
|
async openView({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator(`[data-testid="view-sidebar-view-${title}"]`).click();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async createKanbanView({ title }: { title: string }) {
|
||
|
await this.createView({ title, locator: this.createKanbanButton });
|
||
|
}
|
||
|
|
||
2 years ago
|
// Todo: Make selection better
|
||
2 years ago
|
async verifyView({ title, index }: { title: string; index: number }) {
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
this.get().locator('[data-testid="view-item"]').nth(index).locator('[data-testid="truncate-label"]')
|
||
2 years ago
|
).toHaveText(title, { ignoreCase: true });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async verifyViewNotPresent({ title, index }: { title: string; index: number }) {
|
||
|
const viewList = this.get().locator(`.nc-views-menu`).locator('.ant-menu-title-content');
|
||
2 years ago
|
if ((await viewList.count()) <= index) {
|
||
|
return true;
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
return await expect(
|
||
2 years ago
|
this.get().locator(`.nc-views-menu`).locator('.ant-menu-title-content').nth(index)
|
||
|
).not.toHaveText(title);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async reorderViews({ sourceView, destinationView }: { sourceView: string; destinationView: string }) {
|
||
2 years ago
|
await this.dashboard
|
||
|
.get()
|
||
2 years ago
|
.locator(`[data-testid="view-sidebar-drag-handle-${sourceView}"]`)
|
||
|
.dragTo(this.get().locator(`[data-testid="view-sidebar-view-${destinationView}"]`));
|
||
2 years ago
|
}
|
||
|
|
||
|
async deleteView({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator(`[data-testid="view-sidebar-view-${title}"]`).hover();
|
||
|
await this.get()
|
||
|
.locator(`[data-testid="view-sidebar-view-actions-${title}"]`)
|
||
|
.locator('.nc-view-delete-icon')
|
||
|
.click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.rootPage.locator('.nc-modal-view-delete').locator('button:has-text("Submit"):visible').click();
|
||
2 years ago
|
|
||
2 years ago
|
// waiting for button to get detached, we will miss toast
|
||
|
// await this.rootPage
|
||
|
// .locator(".nc-modal-view-delete")
|
||
|
// .locator('button:has-text("Submit")')
|
||
|
// .waitFor({ state: "detached" });
|
||
2 years ago
|
await this.verifyToast({ message: 'View deleted successfully' });
|
||
2 years ago
|
}
|
||
|
|
||
|
async renameView({ title, newTitle }: { title: string; newTitle: string }) {
|
||
2 years ago
|
await this.get().locator(`[data-testid="view-sidebar-view-${title}"]`).dblclick();
|
||
|
await this.get().locator(`[data-testid="view-sidebar-view-${title}"]`).locator('input').fill(newTitle);
|
||
2 years ago
|
await this.get().press('Enter');
|
||
|
await this.verifyToast({ message: 'View renamed successfully' });
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async copyView({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator(`[data-testid="view-sidebar-view-${title}"]`).hover();
|
||
|
await this.get()
|
||
|
.locator(`[data-testid="view-sidebar-view-actions-${title}"]`)
|
||
|
.locator('.nc-view-copy-icon')
|
||
|
.click();
|
||
2 years ago
|
const submitAction = this.rootPage
|
||
2 years ago
|
.locator('.ant-modal-content')
|
||
2 years ago
|
.locator('button:has-text("Submit"):visible')
|
||
|
.click();
|
||
2 years ago
|
await this.waitForResponse({
|
||
2 years ago
|
httpMethodsToMatch: ['POST'],
|
||
|
requestUrlPathToMatch: '/api/v1/db/meta/tables/',
|
||
2 years ago
|
uiAction: submitAction,
|
||
|
});
|
||
2 years ago
|
await this.verifyToast({ message: 'View created successfully' });
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async validateRoleAccess(param: { role: string }) {
|
||
2 years ago
|
const count = param.role === 'creator' ? 1 : 0;
|
||
2 years ago
|
await expect(this.createGridButton).toHaveCount(count);
|
||
|
await expect(this.createGalleryButton).toHaveCount(count);
|
||
|
await expect(this.createFormButton).toHaveCount(count);
|
||
|
await expect(this.createKanbanButton).toHaveCount(count);
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|