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. 214
      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. 16
      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">
<MdiLogout class="group-hover:(!text-accent)" />&nbsp;
<span class="prose-sm">
<span class="prose-sm nc-user-menu-signout">
{{ $t('general.signOut') }}
</span>
</div>

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

@ -23,13 +23,32 @@ export const genTest = (apiType, dbType) => {
describe("Static user creations (different roles)", () => {
before(() => {
cy.fileHook();
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)
cy.saveLocalStorage();
});
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) => {
@ -96,69 +115,77 @@ export const genTest = (apiType, dbType) => {
const roleValidation = (roleType) => {
describe(`User role validation`, () => {
before(() => {
cy.fileHook();
// cy.restoreLocalStorage();
cy.visit(mainPage.roleURL[roleType])
cy.wait(5000);
cy.get('button:contains("SIGN UP")').should('exist')
cy.get('input[type="text"]', { timeout: 20000 }).type(
roles[roleType].credentials.username
);
cy.get('input[type="password"]').type(roles[roleType].credentials.password);
cy.get('button:contains("SIGN UP")').click();
cy.wait(3000);
cy.get('.nc-project-page-title').contains("My Projects").should("be.visible");
if (dbType === "xcdb") {
if ("rest" == apiType)
projectsPage.openProject(
staticProjects.sampleREST.basic.name
);
else
projectsPage.openProject(
staticProjects.sampleGQL.basic.name
);
} else if (dbType === "mysql") {
if ("rest" == apiType)
projectsPage.openProject(
staticProjects.externalREST.basic.name
);
else
projectsPage.openProject(
staticProjects.externalGQL.basic.name
);
} else if (dbType === "postgres") {
if ("rest" == apiType)
projectsPage.openProject(
staticProjects.pgExternalREST.basic.name
);
else
projectsPage.openProject(
staticProjects.pgExternalGQL.basic.name
);
}
if (roleType === "creator") {
// 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.fileHook();
cy.restoreLocalStorage();
});
if (roleType != "owner") {
it(`[${roles[roleType].name}] SignIn, Open project`, () => {
cy.log(mainPage.roleURL[roleType]);
cy.visit(mainPage.roleURL[roleType], {
baseUrl: null,
});
cy.wait(5000);
// Redirected to new URL, feed details
//
cy.get('input[type="text"]')
.should("exist")
.type(roles[roleType].credentials.username);
cy.get('input[type="password"]').type(
roles[roleType].credentials.password
);
cy.get('button:contains("SIGN")').click();
// cy.url({ timeout: 6000 }).should("contain", "#/project");
cy.get('nc-project-page-title').contains("My Projects").should("be.visible");
if (dbType === "xcdb") {
if ("rest" == apiType)
projectsPage.openProject(
staticProjects.sampleREST.basic.name
);
else
projectsPage.openProject(
staticProjects.sampleGQL.basic.name
);
} else if (dbType === "mysql") {
if ("rest" == apiType)
projectsPage.openProject(
staticProjects.externalREST.basic.name
);
else
projectsPage.openProject(
staticProjects.externalGQL.basic.name
);
} else if (dbType === "postgres") {
if ("rest" == apiType)
projectsPage.openProject(
staticProjects.pgExternalREST.basic.name
);
else
projectsPage.openProject(
staticProjects.pgExternalGQL.basic.name
);
}
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();
if (roleType != "creator") {
cy.closeTableTab("Actor");
}
});
}
cy.wait(5000);
cy.get('button:contains("SIGN")').should('exist')
});
///////////////////////////////////////////////////////
// Test suite
@ -205,45 +232,44 @@ export const genTest = (apiType, dbType) => {
_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`, () => {
// viewer & commenter doesn't contain hideField option in ncv2
// #ID, City, LastUpdate, City => Address, Country <= City, +
mainPage.hideField("LastUpdate");
const verifyCsv = (retrievedRecords) => {
// expected output, statically configured
let storedRecords = [
`City,Address List,Country`,
`A Corua (La Corua),939 Probolinggo Loop,Spain`,
`Abha,733 Mandaluyong Place,Saudi Arabia`,
`Abu Dhabi,535 Ahmadnagar Manor,United Arab Emirates`,
`Acua,1789 Saint-Denis Parkway,Mexico`,
];
// skip if xcdb
if (!isXcdb()) {
for (let i = 0; i < storedRecords.length; i++) {
// cy.log(retrievedRecords[i])
expect(retrievedRecords[i]).to.be.equal(
storedRecords[i]
);
// to be fixed
if(roleType === 'commenter' || roleType === 'viewer') {}
else {
// viewer & commenter doesn't contain hideField option in ncv2
// #ID, City, LastUpdate, City => Address, Country <= City, +
mainPage.hideField("LastUpdate");
const verifyCsv = (retrievedRecords) => {
// expected output, statically configured
let storedRecords = [
`City,Address List,Country`,
`A Corua (La Corua),939 Probolinggo Loop,Spain`,
`Abha,733 Mandaluyong Place,Saudi Arabia`,
`Abu Dhabi,535 Ahmadnagar Manor,United Arab Emirates`,
`Acua,1789 Saint-Denis Parkway,Mexico`,
];
// skip if xcdb
if (!isXcdb()) {
for (let i = 0; i < storedRecords.length; i++) {
// cy.log(retrievedRecords[i])
expect(retrievedRecords[i]).to.be.equal(
storedRecords[i]
);
}
}
}
};
};
// download & verify
mainPage.downloadAndVerifyCsv(
`City_exported_1.csv`,
verifyCsv
);
mainPage.unhideField("LastUpdate");
// download & verify
mainPage.downloadAndVerifyCsv(
`City_exported_1.csv`,
verifyCsv,
roleType
);
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) {
let columnName = "City";
let validationString =
true == roles[roleType].validations.editSchema ? "exist" : "not.exist";
true === roles[roleType].validations.editSchema ? "exist" : "not.exist";
cy.openTableTab(columnName, 25);
// create table
cy.get(`.nc-add-import-btn`).should(validationString);
cy.get(`.nc-add-new-table`).should(validationString);
// delete table option
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("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
@ -73,6 +74,15 @@ export function _editSchema(roleType, mode) {
// update column (edit/ delete menu)
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) {
@ -82,20 +92,17 @@ export function _editData(roleType, mode) {
cy.openTableTab(columnName, 25);
// add row
// add row button
cy.get('.nc-add-new-row-btn:visible').should(validationString);
// add button at bottom of page
mainPage.getCell(columnName, 25).scrollIntoView();
// cy.get('.nc-grid-add-new-cell').scrollIntoView();
cy.get('.nc-grid-add-new-cell:visible').should(validationString);
// update row option (right click)
//
mainPage.getCell("City", 5).rightclick();
cy.wait(1000);
cy.wait(100);
cy.get(".ant-dropdown-content:visible").should(validationString);
if (validationString === "exist") {
@ -183,7 +190,7 @@ export function _editComment(roleType, mode) {
.click();
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();
}
@ -200,54 +207,57 @@ export function _editComment(roleType, mode) {
export function _viewMenu(roleType, mode) {
let columnName = "City";
// Download CSV, Excel
let actionsMenuItemsCnt = 2;
// Lock, Download, Upload
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.wait(1000);
let validationString =
true === roles[roleType].validations.shareView ? "exist" : "not.exist";
if (roleType === "owner" || roleType === "creator") {
// Download CSV / Download XLSX / Upload CSV / Shared View List / Webhook
actionsMenuItemsCnt = 5;
} else if (roleType == "editor") {
// Download CSV / Upload CSV / Download XLSX
actionsMenuItemsCnt = 2;
if (roleType === "editor") {
// Download / Upload CSV
menuWithSubmenuCount = 2;
menuWithoutSubmenuCount = 0
} else if (roleType === "commenter" || roleType === "viewer") {
// Download CSV & Download excel
menuWithSubmenuCount = 0;
menuWithoutSubmenuCount = 2
}
// view list field (default GRID view)
cy.get(`.nc-view-item`).should("exist");
// view create option, exists only for owner/ creator
cy.get(`.nc-create-1-view`).should(validationString);
cy.get(`.nc-create-2-view`).should(validationString);
cy.get(`.nc-create-3-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);
cy.get(`.nc-create-grid-view`).should(validationString);
cy.get(`.nc-create-gallery-view`).should(validationString);
cy.get(`.nc-create-form-view`).should(validationString);
// share view permissions are role specific
// actions menu (more), only download csv should be visible for non-previlaged users
cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu()
.find('.nc-project-menu-item')
.should("have.length", actionsMenuItemsCnt);
.find('.ant-dropdown-menu-submenu:visible')
.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) {
// kludge; download csv menu persists until clicked
let columnName = "City";
cy.closeTableTab(columnName);
cy.openTableTab(columnName, 25);
// cy.closeTableTab(columnName);
// cy.openTableTab(columnName, 25);
let validationString =
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();
// kludge to make new tab active
cy.get('.ant-tabs-tab-btn')
.contains(tn)
.should('exist')
.click();
// cy.get('.ant-tabs-tab-btn')
// .contains(tn)
// .should('exist')
// .click();
cy.wait(3000);
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_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) => {
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) => {
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", () => {
return cy.get(".ant-modal-content:visible").last()
});

16
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
// if it exists, verify it against 'expectedRecords' passed in as parameter
//
downloadAndVerifyCsv = (filename, verifyCsv) => {
cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu().find('.nc-project-menu-item').contains('Download').click();
cy.wait(1000);
cy.get('.nc-project-menu-item').contains('Download as CSV').should('exist').click();
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.getActiveMenu().find('.nc-project-menu-item').contains('Download').click();
cy.wait(1000);
cy.get('.nc-project-menu-item').contains('Download as CSV').should('exist').click();
}
cy.toastWait("Successfully exported all table data").then(() => {
// download folder path, read from config file

Loading…
Cancel
Save