2026-02-12 08:28:00 +00:00
|
|
|
import { commonSelectors, commonWidgetSelector } from "Selectors/common";
|
2025-02-17 05:00:24 +00:00
|
|
|
import { workspaceConstantsSelectors } from "Selectors/workspaceConstants";
|
2025-09-29 05:21:52 +00:00
|
|
|
import { addAndVerifyConstants } from "Support/utils/workspaceConstants";
|
2026-02-12 08:28:00 +00:00
|
|
|
import { groupsSelector } from "Constants/selectors/manageGroups";
|
|
|
|
|
import { navigateToManageGroups } from "Support/utils/common";
|
|
|
|
|
import { versionSwitcherSelectors } from "Constants/selectors/version";
|
|
|
|
|
import { multiEnvSelector } from "Constants/selectors/eeCommon";
|
2022-07-11 08:23:39 +00:00
|
|
|
|
2025-10-17 07:08:44 +00:00
|
|
|
export const constantsOperations = {
|
2025-02-17 05:00:24 +00:00
|
|
|
createConstant: (name, value) => {
|
|
|
|
|
cy.get(commonSelectors.workspaceConstantsIcon).click();
|
2025-09-29 05:21:52 +00:00
|
|
|
addAndVerifyConstants(name, value);
|
2025-02-17 05:00:24 +00:00
|
|
|
},
|
2023-02-09 10:56:10 +00:00
|
|
|
|
2025-02-17 05:00:24 +00:00
|
|
|
deleteConstant: (name) => {
|
|
|
|
|
cy.get(workspaceConstantsSelectors.constDeleteButton(name)).click();
|
|
|
|
|
cy.get(commonSelectors.yesButton).click();
|
|
|
|
|
},
|
2022-10-31 13:38:43 +00:00
|
|
|
};
|
2022-07-18 06:26:10 +00:00
|
|
|
|
2025-02-17 05:00:24 +00:00
|
|
|
// Permission verification helpers
|
2025-10-17 07:08:44 +00:00
|
|
|
export const verifyPermissions = {
|
2025-02-17 05:00:24 +00:00
|
|
|
checkAppPermissions: (shouldExist = true) => {
|
|
|
|
|
const assertion = shouldExist ? "exist" : "not.exist";
|
|
|
|
|
cy.get(commonSelectors.appCreateButton).should(assertion);
|
|
|
|
|
},
|
2023-06-14 09:30:21 +00:00
|
|
|
|
2025-02-17 05:00:24 +00:00
|
|
|
checkFolderPermissions: (shouldExist = true) => {
|
|
|
|
|
const assertion = shouldExist ? "exist" : "not.exist";
|
|
|
|
|
cy.get(commonSelectors.createNewFolderButton).should(assertion);
|
|
|
|
|
},
|
2023-06-14 09:30:21 +00:00
|
|
|
|
2025-02-17 05:00:24 +00:00
|
|
|
checkConstantsPermissions: (shouldExist = true) => {
|
|
|
|
|
const assertion = shouldExist ? "exist" : "not.exist";
|
|
|
|
|
cy.get(commonSelectors.workspaceConstantsIcon).should(assertion);
|
|
|
|
|
},
|
2023-06-14 09:30:21 +00:00
|
|
|
|
2025-02-17 05:00:24 +00:00
|
|
|
checkSettingsAccess: (shouldExist = true) => {
|
|
|
|
|
cy.get(commonSelectors.settingsIcon).click();
|
|
|
|
|
cy.get(commonSelectors.workspaceSettings).should(
|
|
|
|
|
shouldExist ? "exist" : "not.exist"
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-17 07:08:44 +00:00
|
|
|
export const getGroupPermissionInput = (isEnterprise, flag) => {
|
|
|
|
|
return isEnterprise
|
|
|
|
|
? {
|
|
|
|
|
appCreate: flag,
|
|
|
|
|
appDelete: flag,
|
|
|
|
|
appPromote: flag,
|
|
|
|
|
appRelease: flag,
|
|
|
|
|
workflowCreate: flag,
|
|
|
|
|
workflowDelete: flag,
|
|
|
|
|
dataSourceCreate: flag,
|
|
|
|
|
dataSourceDelete: flag,
|
|
|
|
|
folderCRUD: flag,
|
|
|
|
|
orgConstantCRUD: flag,
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
appCreate: flag,
|
|
|
|
|
appDelete: flag,
|
|
|
|
|
folderCRUD: flag,
|
|
|
|
|
orgConstantCRUD: flag,
|
|
|
|
|
};
|
2025-10-21 18:55:28 +00:00
|
|
|
};
|
2025-10-17 07:08:44 +00:00
|
|
|
|
|
|
|
|
export const verifyBuilderPermissions = (
|
|
|
|
|
appName,
|
|
|
|
|
folderName,
|
|
|
|
|
constName,
|
|
|
|
|
constValue,
|
|
|
|
|
isAdmin = false
|
|
|
|
|
) => {
|
|
|
|
|
verifyBasicPermissions(true);
|
|
|
|
|
|
|
|
|
|
// App operations
|
|
|
|
|
cy.apiCreateApp(appName);
|
|
|
|
|
cy.apiDeleteApp();
|
|
|
|
|
|
|
|
|
|
// Folder operations
|
|
|
|
|
cy.apiCreateFolder(folderName);
|
|
|
|
|
cy.apiDeleteFolder();
|
|
|
|
|
|
|
|
|
|
// Constants management
|
|
|
|
|
cy.get(commonSelectors.workspaceConstantsIcon).click();
|
|
|
|
|
addAndVerifyConstants(constName, constValue);
|
|
|
|
|
cy.get(workspaceConstantsSelectors.constDeleteButton(constName)).click();
|
|
|
|
|
cy.get(commonSelectors.yesButton).click();
|
|
|
|
|
|
|
|
|
|
cy.ifEnv("Enterprise", () => {
|
2025-12-05 12:37:00 +00:00
|
|
|
cy.apiCreateDataSource(
|
2025-10-17 07:08:44 +00:00
|
|
|
`${Cypress.env("server_host")}/api/data-sources`,
|
|
|
|
|
appName,
|
|
|
|
|
"restapi",
|
|
|
|
|
[{ key: "url", value: "https://jsonplaceholder.typicode.com/users" }]
|
|
|
|
|
);
|
2025-12-05 12:37:00 +00:00
|
|
|
cy.apiDeleteDataSource(appName);
|
2025-10-17 07:08:44 +00:00
|
|
|
|
|
|
|
|
cy.apiCreateWorkflow(appName);
|
|
|
|
|
cy.apiDeleteWorkflow(appName);
|
2025-10-21 18:55:28 +00:00
|
|
|
});
|
2025-10-17 07:08:44 +00:00
|
|
|
|
|
|
|
|
verifySettingsAccess(isAdmin);
|
2026-01-12 16:29:56 +00:00
|
|
|
cy.get(commonSelectors.workspaceSettings).click();
|
|
|
|
|
cy.get(commonSelectors.manageSSOOption).should("not.exist");
|
2022-10-31 13:38:43 +00:00
|
|
|
};
|
2025-10-17 07:08:44 +00:00
|
|
|
|
|
|
|
|
export const verifyBasicPermissions = (canCreate = true) => {
|
|
|
|
|
cy.get(commonSelectors.dashboardAppCreateButton).should(
|
|
|
|
|
canCreate ? "be.enabled" : "be.disabled"
|
|
|
|
|
);
|
|
|
|
|
cy.get(commonSelectors.createNewFolderButton).should(
|
|
|
|
|
canCreate ? "exist" : "not.exist"
|
|
|
|
|
);
|
|
|
|
|
cy.get('[data-cy="database-icon"]').should(canCreate ? "exist" : "not.exist");
|
2025-10-20 08:36:37 +00:00
|
|
|
|
2025-10-17 07:08:44 +00:00
|
|
|
cy.ifEnv("Enterprise", () => {
|
|
|
|
|
cy.get(commonSelectors.globalDataSourceIcon).should(
|
|
|
|
|
canCreate ? "exist" : "not.exist"
|
|
|
|
|
);
|
2025-10-20 08:36:37 +00:00
|
|
|
cy.get(commonSelectors.workspaceConstantsIcon).should(
|
|
|
|
|
canCreate ? "exist" : "not.exist"
|
|
|
|
|
);
|
2025-10-17 07:08:44 +00:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const verifySettingsAccess = (shouldExist = true) => {
|
|
|
|
|
cy.get(commonSelectors.settingsIcon).click();
|
|
|
|
|
cy.get(commonSelectors.workspaceSettings).should(
|
|
|
|
|
shouldExist ? "exist" : "not.exist"
|
|
|
|
|
);
|
2025-10-21 18:55:28 +00:00
|
|
|
};
|
2026-02-12 08:28:00 +00:00
|
|
|
|
|
|
|
|
export const verifyEnvironmentTagsInGranularUI = (groupName, environmentTags) => {
|
|
|
|
|
navigateToManageGroups();
|
|
|
|
|
cy.get(groupsSelector.groupLink(groupName)).click();
|
|
|
|
|
cy.get(groupsSelector.permissionsLink).click();
|
|
|
|
|
cy.get(groupsSelector.granularLink).click();
|
|
|
|
|
|
|
|
|
|
cy.get(groupsSelector.granularAccessPermission).within(() => {
|
|
|
|
|
cy.get(groupsSelector.environmentTags).should('be.visible');
|
|
|
|
|
cy.get('.environment-tag').should('have.length', environmentTags.length);
|
|
|
|
|
cy.get('.environment-tag').each(($el, index) => {
|
|
|
|
|
cy.wrap($el).should('have.text', environmentTags[index]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
2026-02-16 15:01:44 +00:00
|
|
|
|
|
|
|
|
|
2026-02-12 08:28:00 +00:00
|
|
|
export const verifyEnvironmentAccess = (environments, options = {}) => {
|
|
|
|
|
const defaults = {
|
|
|
|
|
workspaceName: "my-workspace",
|
|
|
|
|
componentName: "text1",
|
|
|
|
|
canEdit: true,
|
|
|
|
|
appId: Cypress.env("appId"),
|
|
|
|
|
appName: undefined,
|
|
|
|
|
version: "v1",
|
|
|
|
|
canAllView: true,
|
|
|
|
|
allowedEnvironment: "staging"
|
|
|
|
|
};
|
|
|
|
|
const opts = {
|
|
|
|
|
...defaults,
|
|
|
|
|
...options,
|
|
|
|
|
// use nullish coalescing so false/"" are not overwritten
|
|
|
|
|
workspaceName: options.workspaceName ?? defaults.workspaceName,
|
|
|
|
|
componentName: options.componentName ?? defaults.componentName,
|
|
|
|
|
canEdit: options.canEdit ?? defaults.canEdit,
|
|
|
|
|
appId: options.appId ?? defaults.appId,
|
|
|
|
|
appName: options.appName ?? defaults.appName,
|
|
|
|
|
version: options.version ?? defaults.version,
|
|
|
|
|
canAllView: options.canAllView ?? defaults.canAllView,
|
|
|
|
|
allowedEnvironment: options.allowedEnvironment ?? defaults.allowedEnvironment
|
|
|
|
|
};
|
|
|
|
|
verifyAppBuilderAccess(environments, opts);
|
|
|
|
|
verifyPreviewAccess(environments, opts);
|
|
|
|
|
verifyPreviewURLAccess(environments, opts);
|
|
|
|
|
};
|
|
|
|
|
const assertRestrictedTooltip = (selector, env) => {
|
|
|
|
|
cy.get(selector).should("be.disabled").trigger("mouseover", { force: true });
|
|
|
|
|
cy.get("div.tooltip-inner")
|
|
|
|
|
.should("be.visible")
|
|
|
|
|
.and("contain", `Access to ${env} environment is restricted. Contact admin to know more.`);
|
|
|
|
|
cy.get(selector).trigger("mouseout", { force: true });
|
|
|
|
|
cy.get("div.tooltip-inner").should("not.exist");
|
|
|
|
|
};
|
2026-02-16 15:01:44 +00:00
|
|
|
|
|
|
|
|
|
2026-02-12 08:28:00 +00:00
|
|
|
export const verifyAppBuilderAccess = (envNames, { workspaceName, canEdit, appId }) => {
|
|
|
|
|
|
|
|
|
|
if (!canEdit) {
|
|
|
|
|
cy.visit(`/${workspaceName}/apps/${appId}`, { failOnStatusCode: false });
|
|
|
|
|
cy.url().should("match", /\/error\/restricted(-preview)?/);
|
|
|
|
|
cy.get('[data-cy="modal-header"]').should("be.visible").and("contain.text", "Restricted access");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
cy.get(versionSwitcherSelectors.versionSwitcherButton).click();
|
|
|
|
|
envNames.forEach((envName) => {
|
|
|
|
|
const envSelector = `[data-cy="${envName.name}-environment-name"]`;
|
|
|
|
|
if (envName.hasAccess) cy.get(envSelector).should("be.enabled");
|
|
|
|
|
else assertRestrictedTooltip(envSelector, envName.name);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-02-16 15:01:44 +00:00
|
|
|
|
2026-02-12 08:28:00 +00:00
|
|
|
const assertEnvRestrictedTooltip = (envButton, env) => {
|
|
|
|
|
envButton.find(multiEnvSelector.envNameDropdown)
|
|
|
|
|
.should("have.css", "cursor", "not-allowed")
|
|
|
|
|
.trigger("mouseover", { force: true });
|
|
|
|
|
|
|
|
|
|
cy.get("div.tooltip-inner")
|
|
|
|
|
.should("be.visible")
|
|
|
|
|
.and("contain", `Access to ${env} environment is restricted. Contact admin to know more.`);
|
|
|
|
|
|
|
|
|
|
envButton.trigger("mouseout", { force: true });
|
|
|
|
|
cy.get("div.tooltip-inner").should("not.exist");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const verifyPreviewAccess = (
|
|
|
|
|
envNames,
|
|
|
|
|
{ appId, componentName, canEdit, appName, version, canAllView, allowedEnvironment }
|
|
|
|
|
) => {
|
|
|
|
|
const openPreviewSettingsIfClosed = () => {
|
|
|
|
|
cy.get("body").then(($body) => {
|
|
|
|
|
if ($body.find("div.preview-settings-overlay").length === 0) {
|
|
|
|
|
cy.get(commonSelectors.previewSettings).should("be.visible").click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const openEnvDropdown = () => {
|
|
|
|
|
cy.get("body").then(($body) => {
|
|
|
|
|
if (!$body.find(multiEnvSelector.selectedEnvName).length) {
|
|
|
|
|
cy.get(multiEnvSelector.envContainer).should("be.visible").click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (canEdit) {
|
2026-02-26 06:50:53 +00:00
|
|
|
cy.get(commonWidgetSelector.editorPreviewLink).first().should("have.attr", "href");
|
2026-02-12 08:28:00 +00:00
|
|
|
cy.openInCurrentTab(commonWidgetSelector.previewButton);
|
|
|
|
|
} else {
|
|
|
|
|
if (canAllView === false) return;
|
|
|
|
|
|
|
|
|
|
// stable: go straight to preview URL, avoid hover/new-tab behavior
|
|
|
|
|
const previewUrl = `${Cypress.config("baseUrl")}/applications/${appId}/home?env=${allowedEnvironment}&version=${version}`;
|
|
|
|
|
cy.visit(previewUrl, { failOnStatusCode: false });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
envNames.forEach((envName) => {
|
|
|
|
|
openPreviewSettingsIfClosed();
|
|
|
|
|
openEnvDropdown();
|
|
|
|
|
|
|
|
|
|
const envButton = cy.contains(
|
|
|
|
|
'[data-cy="env-name-list"] button',
|
|
|
|
|
new RegExp(`^${envName.name}$`, "i")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (envName.hasAccess) {
|
|
|
|
|
envButton.should("be.enabled").click();
|
|
|
|
|
cy.get(commonWidgetSelector.draggableWidget(componentName)).should("contain", envName.name);
|
|
|
|
|
} else {
|
|
|
|
|
assertEnvRestrictedTooltip(envButton, envName.name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const verifyPreviewURLAccess = (envNames, { appId, componentName, version }) => {
|
|
|
|
|
envNames.forEach((envName) => {
|
|
|
|
|
const previewUrl = `${Cypress.config("baseUrl")}/applications/${appId}/home?env=${envName.name}&version=${version}`;
|
|
|
|
|
|
|
|
|
|
cy.visit(previewUrl);
|
|
|
|
|
|
|
|
|
|
if (envName.hasAccess) {
|
|
|
|
|
cy.url().should('include', `/applications/${appId}/home`);
|
|
|
|
|
cy.url().should('include', `env=${envName.name}`);
|
|
|
|
|
cy.get(commonWidgetSelector.draggableWidget(componentName))
|
|
|
|
|
.should("contain", `${envName.name}`);
|
|
|
|
|
} else {
|
|
|
|
|
cy.url().should("match", /\/error\/restricted(-preview)?/);
|
|
|
|
|
|
|
|
|
|
cy.get('[data-cy="modal-header"]')
|
|
|
|
|
.should('be.visible')
|
|
|
|
|
.and('contain.text', 'Restricted access');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|