2025-01-15 11:55:24 +00:00
|
|
|
|
import { commonSelectors, commonWidgetSelector } from "Selectors/common";
|
2025-06-30 09:41:11 +00:00
|
|
|
|
import { appPromote } from "Support/utils/platform/multiEnv";
|
2025-01-15 11:55:24 +00:00
|
|
|
|
|
|
|
|
|
|
const slugValidations = [
|
2025-06-30 09:41:11 +00:00
|
|
|
|
{ input: "", error: "App slug can't be empty" },
|
|
|
|
|
|
{ input: "_2#", error: "Special characters are not accepted." },
|
|
|
|
|
|
{ input: "t ", error: "Cannot contain spaces" },
|
|
|
|
|
|
{ input: "T", error: "Only lowercase letters are accepted." },
|
2025-01-15 11:55:24 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
export const verifySlugValidations = (inputSelector) => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
slugValidations.forEach(({ input, error }) => {
|
|
|
|
|
|
cy.get(inputSelector).clear();
|
|
|
|
|
|
if (input) cy.clearAndType(inputSelector, input);
|
|
|
|
|
|
cy.wait(500);
|
|
|
|
|
|
cy.get(commonWidgetSelector.appSlugErrorLabel).verifyVisibleElement(
|
|
|
|
|
|
"have.text",
|
|
|
|
|
|
error
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
2025-01-15 11:55:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const verifySuccessfulSlugUpdate = (workspaceId, slug) => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
const host = resolveHost();
|
|
|
|
|
|
cy.get('[data-cy="app-slug-accepted-label"]').verifyVisibleElement(
|
|
|
|
|
|
"have.text",
|
|
|
|
|
|
"Slug accepted!"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
cy.wait(500);
|
|
|
|
|
|
// cy.get(commonWidgetSelector.appLinkSucessLabel).should('be.visible');
|
|
|
|
|
|
cy.get(commonWidgetSelector.appLinkSucessLabel).should(
|
|
|
|
|
|
"have.text",
|
|
|
|
|
|
"Link updated successfully!"
|
|
|
|
|
|
);
|
|
|
|
|
|
cy.get(commonWidgetSelector.appLinkField).verifyVisibleElement(
|
|
|
|
|
|
"have.text",
|
|
|
|
|
|
`${host}/${workspaceId}/apps/${slug}`
|
|
|
|
|
|
);
|
2025-01-15 11:55:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const verifyURLs = (workspaceId, slug, page) => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
const baseUrl = Cypress.config("baseUrl");
|
2025-01-15 11:55:24 +00:00
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.url().should(
|
|
|
|
|
|
"eq",
|
|
|
|
|
|
page
|
|
|
|
|
|
? `${baseUrl}/${workspaceId}/apps/${slug}/home`
|
|
|
|
|
|
: `${baseUrl}/${workspaceId}/apps/${slug}`
|
|
|
|
|
|
);
|
2025-01-15 11:55:24 +00:00
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.openInCurrentTab(commonWidgetSelector.previewButton);
|
|
|
|
|
|
cy.ifEnv("Community", () => {
|
2025-01-27 06:40:35 +00:00
|
|
|
|
cy.url().should("eq", `${baseUrl}/applications/${slug}/home?version=v1`);
|
2025-06-30 09:41:11 +00:00
|
|
|
|
});
|
|
|
|
|
|
cy.ifEnv("Enterprise", () => {
|
|
|
|
|
|
cy.url().should(
|
|
|
|
|
|
"eq",
|
|
|
|
|
|
`${baseUrl}/applications/${slug}/home?env=production&version=v1`
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
2025-01-15 11:55:24 +00:00
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.visit("/my-workspace");
|
|
|
|
|
|
cy.visitSlug({
|
|
|
|
|
|
actualUrl: `${baseUrl}/applications/${slug}`,
|
|
|
|
|
|
});
|
|
|
|
|
|
cy.url().should("eq", `${baseUrl}/applications/${slug}`);
|
2025-01-15 11:55:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const setUpSlug = (slug) => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.get(commonWidgetSelector.shareAppButton).click();
|
|
|
|
|
|
cy.clearAndType(commonWidgetSelector.appNameSlugInput, slug);
|
|
|
|
|
|
cy.get('[data-cy="app-slug-accepted-label"]')
|
|
|
|
|
|
.should("be.visible")
|
|
|
|
|
|
.and("have.text", "Slug accepted!");
|
|
|
|
|
|
cy.get(commonWidgetSelector.modalCloseButton).click();
|
2025-01-15 11:55:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const setupAppWithSlug = (appName, slug) => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.apiCreateApp(appName);
|
|
|
|
|
|
cy.apiAddComponentToApp(appName, "text1");
|
|
|
|
|
|
|
|
|
|
|
|
cy.ifEnv("Enterprise", () => {
|
|
|
|
|
|
cy.openApp(
|
|
|
|
|
|
"",
|
|
|
|
|
|
Cypress.env("workspaceId"),
|
|
|
|
|
|
Cypress.env("appId"),
|
|
|
|
|
|
commonWidgetSelector.draggableWidget("text1")
|
|
|
|
|
|
);
|
|
|
|
|
|
appPromote("development", "production");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
cy.apiReleaseApp(appName);
|
|
|
|
|
|
cy.apiAddAppSlug(appName, slug);
|
2025-01-15 11:55:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const verifyRestrictedAccess = () => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.get('[data-cy="modal-header"]').should("have.text", "Restricted access");
|
|
|
|
|
|
cy.get('[data-cy="modal-description"]')
|
|
|
|
|
|
.invoke("text")
|
|
|
|
|
|
.then((text) => {
|
|
|
|
|
|
const normalizedText = text.replace(/’/g, "'");
|
|
|
|
|
|
expect(normalizedText).to.equal(
|
|
|
|
|
|
"You don't have access to this app. Kindly contact admin to know more."
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
cy.get('[data-cy="back-to-home-button"]').verifyVisibleElement(
|
|
|
|
|
|
"have.text",
|
|
|
|
|
|
"Back to home page"
|
|
|
|
|
|
);
|
2025-01-15 11:55:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const onboardUserFromAppLink = (
|
2025-06-30 09:41:11 +00:00
|
|
|
|
email,
|
|
|
|
|
|
slug,
|
|
|
|
|
|
workspaceName = "My workspace",
|
|
|
|
|
|
isNonExistingUser = true
|
2025-01-15 11:55:24 +00:00
|
|
|
|
) => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
const dbConfig = Cypress.env("app_db");
|
2025-01-15 11:55:24 +00:00
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
const query = isNonExistingUser
|
|
|
|
|
|
? `
|
2025-01-15 11:55:24 +00:00
|
|
|
|
SELECT u.invitation_token, o.id AS workspace_id, ou.invitation_token AS organization_token
|
|
|
|
|
|
FROM users u
|
|
|
|
|
|
JOIN organization_users ou ON u.id = ou.user_id
|
|
|
|
|
|
JOIN organizations o ON ou.organization_id = o.id
|
|
|
|
|
|
WHERE u.email = '${email}' AND o.name = '${workspaceName}';
|
|
|
|
|
|
`
|
2025-06-30 09:41:11 +00:00
|
|
|
|
: `
|
2025-01-15 11:55:24 +00:00
|
|
|
|
SELECT ou.invitation_token, o.id AS workspace_id
|
|
|
|
|
|
FROM users u
|
|
|
|
|
|
JOIN organization_users ou ON u.id = ou.user_id
|
|
|
|
|
|
JOIN organizations o ON ou.organization_id = o.id
|
|
|
|
|
|
WHERE u.email = '${email}' AND o.name = '${workspaceName}';
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
cy.task("dbConnection", { dbconfig: dbConfig, sql: query }).then((resp) => {
|
|
|
|
|
|
if (!resp.rows || resp.rows.length === 0) {
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
|
`No records found for email: ${email} and workspace: ${workspaceName}`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { invitation_token, workspace_id, organization_token } = resp.rows[0];
|
|
|
|
|
|
const token = isNonExistingUser ? organization_token : invitation_token;
|
|
|
|
|
|
const url = isNonExistingUser
|
|
|
|
|
|
? `${Cypress.config("baseUrl")}/invitations/${invitation_token}/workspaces/${organization_token}?oid=${workspace_id}&redirectTo=%2Fapplications%2F${slug}`
|
|
|
|
|
|
: `${Cypress.config("baseUrl")}/organization-invitations/${token}?oid=${workspace_id}&redirectTo=%2Fapplications%2F${slug}`;
|
|
|
|
|
|
|
|
|
|
|
|
cy.visit(url);
|
|
|
|
|
|
});
|
2025-01-27 06:40:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const resolveHost = () => {
|
2025-06-30 09:41:11 +00:00
|
|
|
|
const baseUrl = Cypress.config("baseUrl");
|
2025-02-17 05:00:24 +00:00
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
const urlMapping = {
|
|
|
|
|
|
"http://localhost:8082": "http://localhost:8082",
|
|
|
|
|
|
"http://localhost:3000": "http://localhost:3000",
|
|
|
|
|
|
"http://localhost:3000/apps": "http://localhost:3000/apps",
|
|
|
|
|
|
"http://localhost:4001": "http://localhost:3000",
|
|
|
|
|
|
"http://localhost:4001/apps": "http://localhost:3000/apps",
|
|
|
|
|
|
};
|
2025-02-17 05:00:24 +00:00
|
|
|
|
|
2025-06-30 09:41:11 +00:00
|
|
|
|
return urlMapping[baseUrl];
|
2025-01-27 06:40:35 +00:00
|
|
|
|
};
|