Browse Source

test: cy updates for user roles

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3375/head
Raju Udava 2 years ago
parent
commit
4788bd253c
  1. 2
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue
  2. 98
      scripts/cypress-v2/integration/common/5a_user_role.js
  3. 74
      scripts/cypress-v2/integration/spec/roleValidation.spec.js
  4. 36
      scripts/cypress-v2/support/commands.js
  5. 8
      scripts/cypress-v2/support/page_objects/mainPage.js

2
packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue

@ -397,7 +397,7 @@ const copyAuthToken = async () => {
<div v-t="['a:navbar:user:sign-out']" class="nc-project-menu-item group" @click="logout"> <div v-t="['a:navbar:user:sign-out']" class="nc-project-menu-item group" @click="logout">
<MdiLogout class="group-hover:(!text-accent)" />&nbsp; <MdiLogout class="group-hover:(!text-accent)" />&nbsp;
<span class="prose-sm"> <span class="prose-sm nc-user-menu-signout">
{{ $t('general.signOut') }} {{ $t('general.signOut') }}
</span> </span>
</div> </div>

98
scripts/cypress-v2/integration/common/5a_user_role.js

@ -23,13 +23,32 @@ export const genTest = (apiType, dbType) => {
describe("Static user creations (different roles)", () => { describe("Static user creations (different roles)", () => {
before(() => { before(() => {
cy.fileHook();
mainPage.tabReset(); mainPage.tabReset();
// kludge: wait for page load to finish
cy.wait(4000);
// close team & auth tab
cy.get('button.ant-tabs-tab-remove').should('exist').click();
cy.wait(1000);
settingsPage.openMenu(settingsPage.TEAM_N_AUTH) settingsPage.openMenu(settingsPage.TEAM_N_AUTH)
cy.saveLocalStorage();
}); });
beforeEach(() => { beforeEach(() => {
cy.fileHook(); cy.restoreLocalStorage();
});
after(() => {
// sign out
cy.visit(`/`);
cy.wait(5000);
cy.get('.nc-menu-accounts').should('exist').click();
cy.getActiveMenu().find('.ant-dropdown-menu-item').eq(1).click();
cy.wait(5000);
cy.get('button:contains("SIGN")').should('exist')
}); });
const addUser = (user) => { const addUser = (user) => {
@ -96,34 +115,22 @@ export const genTest = (apiType, dbType) => {
const roleValidation = (roleType) => { const roleValidation = (roleType) => {
describe(`User role validation`, () => { describe(`User role validation`, () => {
before(() => {
cy.fileHook();
})
beforeEach(() => {
cy.fileHook();
});
if (roleType != "owner") { before(() => {
it(`[${roles[roleType].name}] SignIn, Open project`, () => { // cy.restoreLocalStorage();
cy.log(mainPage.roleURL[roleType]); cy.visit(mainPage.roleURL[roleType])
cy.visit(mainPage.roleURL[roleType], {
baseUrl: null,
});
cy.wait(5000); cy.wait(5000);
// Redirected to new URL, feed details cy.get('button:contains("SIGN UP")').should('exist')
// cy.get('input[type="text"]', { timeout: 20000 }).type(
cy.get('input[type="text"]') roles[roleType].credentials.username
.should("exist")
.type(roles[roleType].credentials.username);
cy.get('input[type="password"]').type(
roles[roleType].credentials.password
); );
cy.get('button:contains("SIGN")').click(); cy.get('input[type="password"]').type(roles[roleType].credentials.password);
cy.get('button:contains("SIGN UP")').click();
// cy.url({ timeout: 6000 }).should("contain", "#/project"); cy.wait(3000);
cy.get('nc-project-page-title').contains("My Projects").should("be.visible");
cy.get('.nc-project-page-title').contains("My Projects").should("be.visible");
if (dbType === "xcdb") { if (dbType === "xcdb") {
if ("rest" == apiType) if ("rest" == apiType)
@ -154,11 +161,31 @@ export const genTest = (apiType, dbType) => {
); );
} }
if (roleType != "creator") { if (roleType === "creator") {
cy.closeTableTab("Actor"); // kludge: wait for page load to finish
// close team & auth tab
cy.wait(2000);
cy.get('button.ant-tabs-tab-remove').should('exist').click();
cy.wait(1000);
} }
cy.saveLocalStorage();
})
beforeEach(() => {
cy.restoreLocalStorage();
});
after(() => {
// sign out
cy.visit(`/`);
cy.wait(5000);
cy.get('.nc-menu-accounts').should('exist').click();
cy.getActiveMenu().find('.ant-dropdown-menu-item').eq(1).click();
cy.wait(5000);
cy.get('button:contains("SIGN")').should('exist')
}); });
}
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// Test suite // Test suite
@ -205,14 +232,11 @@ export const genTest = (apiType, dbType) => {
_viewMenu(roleType, "userRole"); _viewMenu(roleType, "userRole");
}); });
it(`[${roles[roleType].name}] Top Right Menu bar`, () => {
// Share button is conditional
// Rest are static/ mandatory
//
_topRightMenu(roleType, "userRole");
});
it(`[${roles[roleType].name}] Download files`, () => { it(`[${roles[roleType].name}] Download files`, () => {
// to be fixed
if(roleType === 'commenter' || roleType === 'viewer') {}
else {
// viewer & commenter doesn't contain hideField option in ncv2 // viewer & commenter doesn't contain hideField option in ncv2
// #ID, City, LastUpdate, City => Address, Country <= City, + // #ID, City, LastUpdate, City => Address, Country <= City, +
mainPage.hideField("LastUpdate"); mainPage.hideField("LastUpdate");
@ -241,9 +265,11 @@ export const genTest = (apiType, dbType) => {
// download & verify // download & verify
mainPage.downloadAndVerifyCsv( mainPage.downloadAndVerifyCsv(
`City_exported_1.csv`, `City_exported_1.csv`,
verifyCsv verifyCsv,
roleType
); );
mainPage.unhideField("LastUpdate"); mainPage.unhideField("LastUpdate");
}
}); });
}); });
}; };

74
scripts/cypress-v2/integration/spec/roleValidation.spec.js

@ -49,12 +49,12 @@ export function _advSettings(roleType, mode) {
export function _editSchema(roleType, mode) { export function _editSchema(roleType, mode) {
let columnName = "City"; let columnName = "City";
let validationString = let validationString =
true == roles[roleType].validations.editSchema ? "exist" : "not.exist"; true === roles[roleType].validations.editSchema ? "exist" : "not.exist";
cy.openTableTab(columnName, 25); cy.openTableTab(columnName, 25);
// create table // create table
cy.get(`.nc-add-import-btn`).should(validationString); cy.get(`.nc-add-new-table`).should(validationString);
// delete table option // delete table option
cy.get(`.nc-project-tree-tbl-City`).should("exist").rightclick(); cy.get(`.nc-project-tree-tbl-City`).should("exist").rightclick();
@ -64,7 +64,8 @@ export function _editSchema(roleType, mode) {
cy.getActiveMenu().find('[role="menuitem"]').contains("Delete").should("exist"); cy.getActiveMenu().find('[role="menuitem"]').contains("Delete").should("exist");
cy.getActiveMenu().find('[role="menuitem"]').contains("Rename").should("exist"); cy.getActiveMenu().find('[role="menuitem"]').contains("Rename").should("exist");
mainPage.getCell(columnName, 1).click(); // click on a cell to close table context menu
mainPage.getCell(columnName, 3).click();
} }
// add new column option // add new column option
@ -73,6 +74,15 @@ export function _editSchema(roleType, mode) {
// update column (edit/ delete menu) // update column (edit/ delete menu)
cy.get('.nc-ui-dt-dropdown').should(validationString) cy.get('.nc-ui-dt-dropdown').should(validationString)
if(validationString === "exist"){
cy.get('.nc-import-menu').should('exist').click();
cy.getActiveMenu().should('exist')
cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Airtable')
cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('CSV file')
cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('JSON file')
cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Microsoft Excel')
}
} }
export function _editData(roleType, mode) { export function _editData(roleType, mode) {
@ -82,20 +92,17 @@ export function _editData(roleType, mode) {
cy.openTableTab(columnName, 25); cy.openTableTab(columnName, 25);
// add row // add row button
cy.get('.nc-add-new-row-btn:visible').should(validationString); cy.get('.nc-add-new-row-btn:visible').should(validationString);
// add button at bottom of page
mainPage.getCell(columnName, 25).scrollIntoView(); mainPage.getCell(columnName, 25).scrollIntoView();
// cy.get('.nc-grid-add-new-cell').scrollIntoView();
cy.get('.nc-grid-add-new-cell:visible').should(validationString); cy.get('.nc-grid-add-new-cell:visible').should(validationString);
// update row option (right click) // update row option (right click)
// //
mainPage.getCell("City", 5).rightclick(); mainPage.getCell("City", 5).rightclick();
cy.wait(100);
cy.wait(1000);
cy.get(".ant-dropdown-content:visible").should(validationString); cy.get(".ant-dropdown-content:visible").should(validationString);
if (validationString === "exist") { if (validationString === "exist") {
@ -183,7 +190,7 @@ export function _editComment(roleType, mode) {
.click(); .click();
cy.getActiveDrawer().find(".nc-comment-box").should('exist').type("Comment-1{enter}"); cy.getActiveDrawer().find(".nc-comment-box").should('exist').type("Comment-1{enter}");
cy.toastWait('Comment added successfully') // cy.toastWait('Comment added successfully')
cy.getActiveDrawer().find(".nc-toggle-comments").click(); cy.getActiveDrawer().find(".nc-toggle-comments").click();
} }
@ -200,54 +207,57 @@ export function _editComment(roleType, mode) {
export function _viewMenu(roleType, mode) { export function _viewMenu(roleType, mode) {
let columnName = "City"; let columnName = "City";
// Download CSV, Excel // Lock, Download, Upload
let actionsMenuItemsCnt = 2; let menuWithSubmenuCount = 3;
cy.openTableTab(columnName, 25); // share view list, webhook
let menuWithoutSubmenuCount = 2;
cy.wait(1000); cy.openTableTab(columnName, 25);
// temporary!
cy.get('.nc-toggle-right-navbar').click(); cy.get('.nc-toggle-right-navbar').click();
cy.wait(1000); cy.wait(1000);
let validationString = let validationString =
true === roles[roleType].validations.shareView ? "exist" : "not.exist"; true === roles[roleType].validations.shareView ? "exist" : "not.exist";
if (roleType === "owner" || roleType === "creator") { if (roleType === "editor") {
// Download CSV / Download XLSX / Upload CSV / Shared View List / Webhook // Download / Upload CSV
actionsMenuItemsCnt = 5; menuWithSubmenuCount = 2;
} else if (roleType == "editor") { menuWithoutSubmenuCount = 0
// Download CSV / Upload CSV / Download XLSX } else if (roleType === "commenter" || roleType === "viewer") {
actionsMenuItemsCnt = 2; // Download CSV & Download excel
menuWithSubmenuCount = 0;
menuWithoutSubmenuCount = 2
} }
// view list field (default GRID view) // view list field (default GRID view)
cy.get(`.nc-view-item`).should("exist"); cy.get(`.nc-view-item`).should("exist");
// view create option, exists only for owner/ creator // view create option, exists only for owner/ creator
cy.get(`.nc-create-1-view`).should(validationString); cy.get(`.nc-create-grid-view`).should(validationString);
cy.get(`.nc-create-2-view`).should(validationString); cy.get(`.nc-create-gallery-view`).should(validationString);
cy.get(`.nc-create-3-view`).should(validationString); cy.get(`.nc-create-form-view`).should(validationString);
// share view & automations, exists only for owner/creator
// cy.get(".nc-btn-share-view").should(validationString);
// cy.get(`.nc-webhook-btn`).should(validationString);
// share view permissions are role specific // share view permissions are role specific
// actions menu (more), only download csv should be visible for non-previlaged users // actions menu (more), only download csv should be visible for non-previlaged users
cy.get(".nc-actions-menu-btn").click(); cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu() cy.getActiveMenu()
.find('.nc-project-menu-item') .find('.ant-dropdown-menu-submenu:visible')
.should("have.length", actionsMenuItemsCnt); .should("have.length", menuWithSubmenuCount);
cy.getActiveMenu()
.find('.ant-dropdown-menu-item:visible')
.should("have.length", menuWithoutSubmenuCount);
// click again to close menu
cy.get(".nc-actions-menu-btn").click();
} }
export function _topRightMenu(roleType, mode) { export function _topRightMenu(roleType, mode) {
// kludge; download csv menu persists until clicked // kludge; download csv menu persists until clicked
let columnName = "City"; let columnName = "City";
cy.closeTableTab(columnName); // cy.closeTableTab(columnName);
cy.openTableTab(columnName, 25); // cy.openTableTab(columnName, 25);
let validationString = let validationString =
true == roles[roleType].validations.shareView ? "exist" : "not.exist"; true == roles[roleType].validations.shareView ? "exist" : "not.exist";

36
scripts/cypress-v2/support/commands.js

@ -161,10 +161,11 @@ Cypress.Commands.add("openTableTab", (tn, rc) => {
.click(); .click();
// kludge to make new tab active // kludge to make new tab active
cy.get('.ant-tabs-tab-btn') // cy.get('.ant-tabs-tab-btn')
.contains(tn) // .contains(tn)
.should('exist') // .should('exist')
.click(); // .click();
cy.wait(3000);
cy.get('.xc-row-table.nc-grid').should('exist'); cy.get('.xc-row-table.nc-grid').should('exist');
@ -230,14 +231,32 @@ Cypress.Commands.add("openOrCreateGqlProject", (_args) => {
}); });
let LOCAL_STORAGE_MEMORY = {}; let LOCAL_STORAGE_MEMORY = {};
let LOCAL_STORAGE_MEMORY_v2 = {};
Cypress.Commands.add("saveLocalStorage", (name) => {
if(name) {
cy.task('log', `[saveLocalStorage] ${name}`);
LOCAL_STORAGE_MEMORY_v2[name] = {}
Object.keys(localStorage).forEach((key) => {
LOCAL_STORAGE_MEMORY_v2[name][key] = localStorage[key];
});
return;
}
Cypress.Commands.add("saveLocalStorage", () => {
Object.keys(localStorage).forEach((key) => { Object.keys(localStorage).forEach((key) => {
LOCAL_STORAGE_MEMORY[key] = localStorage[key]; LOCAL_STORAGE_MEMORY[key] = localStorage[key];
}); });
}); });
Cypress.Commands.add("restoreLocalStorage", () => { Cypress.Commands.add("restoreLocalStorage", (name) => {
if(name) {
cy.task('log', `[restoreLocalStorage] ${name}`);
Object.keys(LOCAL_STORAGE_MEMORY_v2[name]).forEach((key) => {
localStorage.setItem(key, LOCAL_STORAGE_MEMORY_v2[name][key]);
});
return;
}
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => { Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]); localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
}); });
@ -249,6 +268,11 @@ Cypress.Commands.add("deleteLocalStorage", () => {
}); });
}); });
Cypress.Commands.add('printLocalStorage', () => {
cy.task('log', `[printLocalStorage]`);
cy.task('log', JSON.stringify(localStorage, null, 2));
})
Cypress.Commands.add("getActiveModal", () => { Cypress.Commands.add("getActiveModal", () => {
return cy.get(".ant-modal-content:visible").last() return cy.get(".ant-modal-content:visible").last()
}); });

8
scripts/cypress-v2/support/page_objects/mainPage.js

@ -382,11 +382,17 @@ export class _mainPage {
// wait for a while & check in configured download folder for the intended file // wait for a while & check in configured download folder for the intended file
// if it exists, verify it against 'expectedRecords' passed in as parameter // if it exists, verify it against 'expectedRecords' passed in as parameter
// //
downloadAndVerifyCsv = (filename, verifyCsv) => { downloadAndVerifyCsv = (filename, verifyCsv, role) => {
if(role === 'commenter' || role === 'viewer') {
cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu().find('.nc-project-menu-item').contains('Download as CSV').click();
} else {
cy.get(".nc-actions-menu-btn").click(); cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu().find('.nc-project-menu-item').contains('Download').click(); cy.getActiveMenu().find('.nc-project-menu-item').contains('Download').click();
cy.wait(1000); cy.wait(1000);
cy.get('.nc-project-menu-item').contains('Download as CSV').should('exist').click(); cy.get('.nc-project-menu-item').contains('Download as CSV').should('exist').click();
}
cy.toastWait("Successfully exported all table data").then(() => { cy.toastWait("Successfully exported all table data").then(() => {
// download folder path, read from config file // download folder path, read from config file

Loading…
Cancel
Save