Browse Source

test: share base

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3848/head
Raju Udava 2 years ago committed by Muhammed Mustafa
parent
commit
dd2858c9bb
  1. 2
      packages/nc-gui/components/tabs/auth/user-management/ShareBase.vue
  2. 68
      scripts/playwright/pages/Dashboard/Settings/Teams.ts
  3. 12
      scripts/playwright/pages/Dashboard/TreeView.ts
  4. 14
      scripts/playwright/pages/Dashboard/common/Toolbar/index.ts
  5. 29
      scripts/playwright/pages/Dashboard/index.ts
  6. 17
      scripts/playwright/pages/LoginPage/index.ts
  7. 92
      scripts/playwright/tests/baseShare.spec.ts

2
packages/nc-gui/components/tabs/auth/user-management/ShareBase.vue

@ -136,7 +136,7 @@ onMounted(() => {
</script> </script>
<template> <template>
<div class="flex flex-col w-full"> <div class="flex flex-col w-full" data-pw="nc-share-base-sub-modal">
<div class="flex flex-row items-center space-x-0.5 pl-2 h-[0.8rem]"> <div class="flex flex-row items-center space-x-0.5 pl-2 h-[0.8rem]">
<MdiOpenInNew /> <MdiOpenInNew />

68
scripts/playwright/pages/Dashboard/Settings/Teams.ts

@ -24,6 +24,10 @@ export class TeamsPage extends BasePage {
.locator(`[pw-data="nc-settings-subtab-Users Management"]`); .locator(`[pw-data="nc-settings-subtab-Users Management"]`);
} }
getSharedBaseSubModal() {
return this.rootPage.locator(`[data-pw="nc-share-base-sub-modal"]`);
}
async invite({ email, role }: { email: string; role: string }) { async invite({ email, role }: { email: string; role: string }) {
await this.inviteTeamBtn.click(); await this.inviteTeamBtn.click();
await this.inviteTeamModal await this.inviteTeamModal
@ -41,7 +45,7 @@ export class TeamsPage extends BasePage {
async closeInvite() { async closeInvite() {
// two btn-icon-only in invite modal: close & copy url // two btn-icon-only in invite modal: close & copy url
await this.inviteTeamModal await this.inviteTeamModal
.locator(`button.ant-btn-icon-only`) .locator(`button.ant-btn-icon-only:visible`)
.first() .first()
.click(); .click();
} }
@ -51,4 +55,66 @@ export class TeamsPage extends BasePage {
.locator(`button:has-text("Invite More")`) .locator(`button:has-text("Invite More")`)
.click(); .click();
} }
async toggleSharedBase({ toggle }: { toggle: boolean }) {
const toggleBtn = await this.getSharedBaseSubModal().locator(
`.nc-disable-shared-base`
);
const toggleBtnText = await toggleBtn.first().innerText();
const disabledBase = toggleBtnText.includes("Disable");
if (disabledBase) {
if (toggle) {
// if share base was disabled && request was to enable
await toggleBtn.click();
const modal = await this.rootPage.locator(
`.nc-dropdown-shared-base-toggle`
);
await modal.locator(`.ant-dropdown-menu-title-content`).click();
}
} else {
if (!toggle) {
// if share base was enabled && request was to disable
await toggleBtn.click();
const modal = await this.rootPage.locator(
`.nc-dropdown-shared-base-toggle`
);
await modal.locator(`.ant-dropdown-menu-title-content`).click();
}
}
}
async getSharedBaseUrl() {
const url = await this.getSharedBaseSubModal()
.locator(`.nc-url:visible`)
.innerText();
return url;
}
async sharedBaseActions({ action }: { action: string }) {
let actionMenu = ["reload", "copy url", "open tab", "copy embed code"];
let index = actionMenu.indexOf(action);
await this.getSharedBaseSubModal()
.locator(`button.ant-btn-icon-only`)
.nth(index)
.click();
}
async sharedBaseRole({ role }: { role: string }) {
// editor | viewer
// await this.getSharedBaseSubModal()
// .locator(`.nc-shared-base-role`)
// .waitFor();
await this.getSharedBaseSubModal()
.locator(`.nc-shared-base-role:visible`)
.click();
const userRoleModal = await this.rootPage.locator(
`.nc-dropdown-share-base-role:visible`
);
await userRoleModal
.locator(`.ant-select-item-option-content:has-text("${role}"):visible`)
.click();
}
} }

12
scripts/playwright/pages/Dashboard/TreeView.ts

@ -6,12 +6,14 @@ export class TreeViewPage extends BasePage {
readonly dashboard: DashboardPage; readonly dashboard: DashboardPage;
readonly project: any; readonly project: any;
readonly quickImportButton: Locator; readonly quickImportButton: Locator;
readonly inviteTeamButton: Locator;
constructor(dashboard: DashboardPage, project: any) { constructor(dashboard: DashboardPage, project: any) {
super(dashboard.rootPage); super(dashboard.rootPage);
this.dashboard = dashboard; this.dashboard = dashboard;
this.project = project; this.project = project;
this.quickImportButton = dashboard.get().locator(".nc-import-menu"); this.quickImportButton = dashboard.get().locator(".nc-import-menu");
this.inviteTeamButton = dashboard.get().locator(".nc-share-base");
} }
get() { get() {
@ -24,7 +26,13 @@ export class TreeViewPage extends BasePage {
// assumption: first view rendered is always GRID // assumption: first view rendered is always GRID
// //
async openTable({ title }: { title: string }) { async openTable({
title,
mode = "standard",
}: {
title: string;
mode?: string;
}) {
if ((await this.get().locator(".active.nc-project-tree-tbl").count()) > 0) { if ((await this.get().locator(".active.nc-project-tree-tbl").count()) > 0) {
if ( if (
(await this.get() (await this.get()
@ -42,7 +50,7 @@ export class TreeViewPage extends BasePage {
requestUrlPathToMatch: `/api/v1/db/meta/tables/`, requestUrlPathToMatch: `/api/v1/db/meta/tables/`,
responseJsonMatcher: (json) => json.title === title, responseJsonMatcher: (json) => json.title === title,
}); });
await this.dashboard.waitForTabRender({ title }); await this.dashboard.waitForTabRender({ title, mode });
} }
async createTable({ title }: { title: string }) { async createTable({ title }: { title: string }) {

14
scripts/playwright/pages/Dashboard/common/Toolbar/index.ts

@ -139,7 +139,7 @@ export class ToolbarPage extends BasePage {
await this.get().locator(`.nc-kanban-add-edit-stack-menu-btn`).click(); await this.get().locator(`.nc-kanban-add-edit-stack-menu-btn`).click();
} }
async validateViewsMenu(param: { role: string }) { async validateViewsMenu(param: { role: string; mode?: string }) {
let menuItems = { let menuItems = {
creator: [ creator: [
"Download", "Download",
@ -154,6 +154,15 @@ export class ToolbarPage extends BasePage {
viewer: ["Download as CSV", "Download as XLSX"], viewer: ["Download as CSV", "Download as XLSX"],
}; };
if (param.mode === "shareBase") {
menuItems = {
creator: [],
editor: ["Download", "Upload", "ERD View"],
commenter: [],
viewer: ["Download as CSV", "Download as XLSX"],
};
}
let vMenu = await this.rootPage.locator( let vMenu = await this.rootPage.locator(
".nc-dropdown-actions-menu:visible" ".nc-dropdown-actions-menu:visible"
); );
@ -163,10 +172,11 @@ export class ToolbarPage extends BasePage {
} }
} }
async validateRoleAccess(param: { role: string }) { async validateRoleAccess(param: { role: string; mode?: string }) {
await this.clickActions(); await this.clickActions();
await this.validateViewsMenu({ await this.validateViewsMenu({
role: param.role, role: param.role,
mode: param.mode,
}); });
let menuItems = { let menuItems = {

29
scripts/playwright/pages/Dashboard/index.ts

@ -85,7 +85,13 @@ export class DashboardPage extends BasePage {
await this.rootPage.locator('[data-cy="nc-noco-brand-icon"]').click(); await this.rootPage.locator('[data-cy="nc-noco-brand-icon"]').click();
} }
async waitForTabRender({ title }: { title: string }) { async waitForTabRender({
title,
mode = "standard",
}: {
title: string;
mode?: string;
}) {
await this.get().locator('[pw-data="grid-id-column"]').waitFor(); await this.get().locator('[pw-data="grid-id-column"]').waitFor();
await this.tabBar await this.tabBar
@ -107,9 +113,11 @@ export class DashboardPage extends BasePage {
.locator('[pw-data="grid-load-spinner"]') .locator('[pw-data="grid-load-spinner"]')
.waitFor({ state: "hidden" }); .waitFor({ state: "hidden" });
await expect(this.rootPage).toHaveURL( if (mode === "standard") {
`/#/nc/${this.project.id}/table/${title}` await expect(this.rootPage).toHaveURL(
); `/#/nc/${this.project.id}/table/${title}`
);
}
} }
// Project page language menu // Project page language menu
@ -215,7 +223,7 @@ export class DashboardPage extends BasePage {
await this.rootPage await this.rootPage
.locator('div.nc-project-menu-item:has-text("Sign Out"):visible') .locator('div.nc-project-menu-item:has-text("Sign Out"):visible')
.click(); .click();
await this.rootPage.locator('[data-cy="nc-form-signin"]').waitFor(); await this.rootPage.locator('[data-cy="nc-form-signin"]:visible').waitFor();
} }
async signUp({ email, password }: { email: string; password: string }) { async signUp({ email, password }: { email: string; password: string }) {
@ -269,7 +277,7 @@ export class DashboardPage extends BasePage {
).toBe(0); ).toBe(0);
} }
async validateProjectMenu(param: { role: string }) { async validateProjectMenu(param: { role: string; mode?: string }) {
await this.rootPage.locator('[pw-data="nc-project-menu"]').click(); await this.rootPage.locator('[pw-data="nc-project-menu"]').click();
let pMenu = this.rootPage.locator(`.nc-dropdown-project-menu:visible`); let pMenu = this.rootPage.locator(`.nc-dropdown-project-menu:visible`);
@ -301,6 +309,15 @@ export class DashboardPage extends BasePage {
viewer: ["Copy Project Info", "Copy Auth Token", "Language", "Account"], viewer: ["Copy Project Info", "Copy Auth Token", "Language", "Account"],
}; };
if (param?.mode === "shareBase") {
menuItems = {
creator: [],
commenter: [],
editor: ["Language"],
viewer: ["Language"],
};
}
// common items // common items
for (let item of menuItems[param.role]) { for (let item of menuItems[param.role]) {

17
scripts/playwright/pages/LoginPage/index.ts

@ -3,13 +3,12 @@ import { expect, Page } from "@playwright/test";
import BasePage from "../Base"; import BasePage from "../Base";
export class LoginPage extends BasePage { export class LoginPage extends BasePage {
constructor(rootPage: Page) { constructor(rootPage: Page) {
super(rootPage); super(rootPage);
} }
goto() { goto() {
return this.rootPage.goto('/#/signin'); return this.rootPage.goto("/#/signin");
} }
get() { get() {
@ -17,17 +16,25 @@ export class LoginPage extends BasePage {
} }
async fillEmail(email: string) { async fillEmail(email: string) {
await this.get().locator(`[pw-data="nc-form-signin__email"]`).waitFor();
await this.get().locator(`[pw-data="nc-form-signin__email"]`).fill(email); await this.get().locator(`[pw-data="nc-form-signin__email"]`).fill(email);
} }
async fillPassword(password: string) { async fillPassword(password: string) {
await this.get().locator(`[pw-data="nc-form-signin__password"]`).fill(password); await this.get()
.locator(`[pw-data="nc-form-signin__password"]`)
.fill(password);
} }
async submit() { async submit() {
await this.get().locator(`[pw-data="nc-form-signin__submit"]`).click(); await this.get().locator(`[pw-data="nc-form-signin__submit"]`).click();
await expect(this.rootPage).toHaveURL("http://localhost:3000/#/");
await expect(this.rootPage).toHaveURL('http://localhost:3000/#/');
} }
async signIn({ email, password }: { email: string; password: string }) {
await this.goto();
await this.fillEmail(email);
await this.fillPassword(password);
await this.submit();
}
} }

92
scripts/playwright/tests/baseShare.spec.ts

@ -0,0 +1,92 @@
import { test } from "@playwright/test";
import { DashboardPage } from "../pages/Dashboard";
import setup from "../setup";
import { ToolbarPage } from "../pages/Dashboard/common/Toolbar";
import { LoginPage } from "../pages/LoginPage";
test.describe("Shared base", () => {
let dashboard: DashboardPage;
let toolbar: ToolbarPage;
let context: any;
let loginPage: LoginPage;
async function roleTest(role: string) {
console.log("project menu");
await dashboard.validateProjectMenu({
role: role.toLowerCase(),
mode: "shareBase",
});
await dashboard.treeView.openTable({ title: "Country", mode: "shareBase" });
console.log("shareBase: view sidebar");
await dashboard.viewSidebar.validateRoleAccess({
role: role.toLowerCase(),
});
console.log("shareBase: toolbar");
await toolbar.validateRoleAccess({
role: role.toLowerCase(),
mode: "shareBase",
});
console.log("shareBase: tree view");
await dashboard.treeView.validateRoleAccess({
role: role.toLowerCase(),
});
console.log("shareBase: grid");
await dashboard.grid.validateRoleAccess({
role: role.toLowerCase(),
});
await dashboard.grid.openExpandedRow({ index: 0 });
console.log("shareBase: expanded row");
await dashboard.expandedForm.validateRoleAccess({
role: role.toLowerCase(),
});
}
test.beforeEach(async ({ page }) => {
context = await setup({ page });
dashboard = new DashboardPage(page, context.project);
toolbar = dashboard.grid.toolbar;
loginPage = new LoginPage(page);
});
test("#1", async () => {
// close 'Team & Auth' tab
await dashboard.closeTab({ title: "Team & Auth" });
await dashboard.treeView.inviteTeamButton.click();
await dashboard.settings.teams.toggleSharedBase({ toggle: true });
await dashboard.settings.teams.sharedBaseRole({ role: "editor" });
let url = await dashboard.settings.teams.getSharedBaseUrl();
await dashboard.settings.teams.closeInvite();
// access shared base link
await dashboard.signOut();
await dashboard.rootPage.goto(url);
await roleTest("editor");
await loginPage.signIn({
email: "user@nocodb.com",
password: "Password123.",
});
await dashboard.openProject({ title: "externalREST0" });
await dashboard.closeTab({ title: "Team & Auth" });
await dashboard.treeView.inviteTeamButton.click();
await dashboard.settings.teams.toggleSharedBase({ toggle: true });
await dashboard.settings.teams.sharedBaseRole({ role: "viewer" });
url = await dashboard.settings.teams.getSharedBaseUrl();
await dashboard.settings.teams.closeInvite();
// access shared base link
await dashboard.signOut();
await dashboard.rootPage.goto(url);
await roleTest("viewer");
});
});
Loading…
Cancel
Save