Browse Source

test: project menu role access

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5897/head
Raju Udava 1 year ago
parent
commit
80421fbaa1
  1. 7
      packages/nc-gui/pages/index/index/index.vue
  2. 36
      tests/playwright/pages/ProjectsPage/index.ts
  3. 12
      tests/playwright/tests/db/rolesCreate.spec.ts

7
packages/nc-gui/pages/index/index/index.vue

@ -247,7 +247,7 @@ const copyProjectMeta = async () => {
<a-table-column key="title" :title="$t('general.title')" data-index="title"> <a-table-column key="title" :title="$t('general.title')" data-index="title">
<template #default="{ text, record }"> <template #default="{ text, record }">
<div class="flex items-center"> <div class="flex items-center">
<div @click.stop class="w-2"> <div class="w-2" @click.stop>
<a-menu class="!border-0 !m-0 !p-0" trigger-sub-menu-action="click"> <a-menu class="!border-0 !m-0 !p-0" trigger-sub-menu-action="click">
<template v-if="isUIAllowed('projectTheme') || isUIAllowed('projectTheme', true, record.roles)"> <template v-if="isUIAllowed('projectTheme') || isUIAllowed('projectTheme', true, record.roles)">
<a-sub-menu key="theme" popup-class-name="custom-color"> <a-sub-menu key="theme" popup-class-name="custom-color">
@ -310,14 +310,15 @@ const copyProjectMeta = async () => {
:is="iconMap.edit" :is="iconMap.edit"
v-if="isUIAllowed('projectUpdate', true) || isUIAllowed('projectUpdate', true, record.roles)" v-if="isUIAllowed('projectUpdate', true) || isUIAllowed('projectUpdate', true, record.roles)"
v-e="['c:project:edit:rename']" v-e="['c:project:edit:rename']"
class="nc-action-btn" class="nc-action-btn nc-edit-project"
:data-testid="`edit-project-${record.title}`"
@click.stop="navigateTo(`/${text}`)" @click.stop="navigateTo(`/${text}`)"
/> />
<component <component
:is="iconMap.delete" :is="iconMap.delete"
v-if="isUIAllowed('projectDelete', true) || isUIAllowed('projectDelete', true, record.roles)" v-if="isUIAllowed('projectDelete', true) || isUIAllowed('projectDelete', true, record.roles)"
class="nc-action-btn" class="nc-action-btn nc-delete-project"
:data-testid="`delete-project-${record.title}`" :data-testid="`delete-project-${record.title}`"
@click.stop="deleteProject(record)" @click.stop="deleteProject(record)"
/> />

36
tests/playwright/pages/ProjectsPage/index.ts

@ -1,10 +1,21 @@
import { expect, Page } from '@playwright/test'; import { expect, Locator, Page } from '@playwright/test';
import BasePage from '../Base'; import BasePage from '../Base';
import { DashboardPage } from '../Dashboard'; import { DashboardPage } from '../Dashboard';
export class ProjectsPage extends BasePage { export class ProjectsPage extends BasePage {
readonly buttonEditProject: Locator;
readonly buttonDeleteProject: Locator;
readonly buttonMoreActions: Locator;
readonly buttonNewProject: Locator;
readonly buttonColorSelector: Locator;
constructor(rootPage: Page) { constructor(rootPage: Page) {
super(rootPage); super(rootPage);
this.buttonEditProject = this.get().locator('.nc-action-btn.nc-edit-project');
this.buttonDeleteProject = this.get().locator('.nc-action-btn.nc-delete-project');
this.buttonMoreActions = this.get().locator('.nc-import-menu');
this.buttonNewProject = this.get().locator('.nc-new-project-menu');
this.buttonColorSelector = this.get().locator('div.color-selector');
} }
prefixTitle(title: string) { prefixTitle(title: string) {
@ -236,4 +247,27 @@ export class ProjectsPage extends BasePage {
async waitForRender() { async waitForRender() {
await this.rootPage.locator('.nc-project-page-title:has-text("My Projects")').waitFor(); await this.rootPage.locator('.nc-project-page-title:has-text("My Projects")').waitFor();
} }
async validateRoleAccess(param: { role: string }) {
// new user; by default org level permission is to viewer (can't create project)
await expect(await this.buttonNewProject).toBeVisible({ visible: false });
// role specific permissions
switch (param.role) {
case 'creator':
await expect(await this.buttonColorSelector).toBeVisible();
await expect(await this.buttonEditProject).toBeVisible();
await expect(await this.buttonDeleteProject).toBeVisible();
await expect(await this.buttonMoreActions).toBeVisible();
break;
case 'editor':
case 'commenter':
case 'viewer':
await expect(await this.buttonColorSelector).toBeVisible({ visible: false });
await expect(await this.buttonEditProject).toBeVisible({ visible: false });
await expect(await this.buttonDeleteProject).toBeVisible({ visible: false });
await expect(await this.buttonMoreActions).toBeVisible({ visible: false });
break;
}
}
} }

12
tests/playwright/tests/db/rolesCreate.spec.ts

@ -103,6 +103,18 @@ test.describe('User roles', () => {
title: 'CustomerList', title: 'CustomerList',
exists: roleDb[roleIdx].role === 'creator' ? true : false, exists: roleDb[roleIdx].role === 'creator' ? true : false,
}); });
// Project page validation
await dashboard.clickHome();
await projectsPage.validateRoleAccess({
role: roleDb[roleIdx].role,
});
await projectsPage.openProject({
title: context.project.title,
waitForAuthTab: roleDb[roleIdx].role === 'creator',
withoutPrefix: true,
});
} }
async function roleSignup(roleIdx: number) { async function roleSignup(roleIdx: number) {

Loading…
Cancel
Save