* create basic button for forking * added menu item for fork, opens a basic modal. TODO: Add functionality to fork * clicking fork app enables organization select and forks across applications * added close modal functionality. TODO: add tests, optimise code, remove duplicate and use exportswhere possible * removed unused code * Added cypress tests to check that fork app creates an app with same dsl. Tests Failing, needs fixing * tests fixed, but needs unexpected login from cy * Resolved bug with login by using correct cypress selectors * Added tests to check that dsls match, added documentation and removed unused code * remove unused fork function and directly dispatch from modal * refactor code * revert * removed unused code and refactored tests * feature/fork-apps-across-orgs-refactor * make code prettier * renamed components correctly * refactored modal code into single file. TODO: fix warnings, test and remove unused code * pass setModalClose to dialog component to maintain global modal state * Added types for fork modal props * update tests and remove unused code * Removed isDeployedApp and instead passed trigger as a prop * remove console logs and revert imports to small case * rename files as components * minor changes * cleanup * mock dispatch for jest * move jest mocks to component tests
149 lines
4.1 KiB
TypeScript
149 lines
4.1 KiB
TypeScript
import { unmountComponentAtNode } from "react-dom";
|
|
import { render } from "test/testUtils";
|
|
import GetAppViewerHeaderCTA from "./GetAppViewerHeaderCTA";
|
|
import { waitFor } from "@testing-library/dom";
|
|
import { ANONYMOUS_USERNAME } from "constants/userConstants";
|
|
|
|
jest.mock("react-redux", () => ({
|
|
...jest.requireActual("react-redux"),
|
|
useDispatch: () => jest.fn(),
|
|
}));
|
|
|
|
const sampleProps = {
|
|
url:
|
|
"/applications/606ad816c7a35467ac887f87/pages/606ad816c7a35467ac887f89/edit",
|
|
canEdit: true,
|
|
currentApplicationDetails: {
|
|
id: "606ad816c7a35467ac887f87",
|
|
userPermissions: [
|
|
"manage:applications",
|
|
"canComment:applications",
|
|
"read:applications",
|
|
"publish:applications",
|
|
"makePublic:applications",
|
|
],
|
|
name: "Untitled application 1",
|
|
organizationId: "606ad7eec7a35467ac887f84",
|
|
isPublic: false,
|
|
pages: [
|
|
{
|
|
id: "606ad816c7a35467ac887f89",
|
|
isDefault: true,
|
|
default: true,
|
|
},
|
|
],
|
|
appIsExample: false,
|
|
color: "#C03C3C",
|
|
icon: "flag",
|
|
new: false,
|
|
},
|
|
currentUser: {
|
|
userPermissions: [],
|
|
email: "b1@appsmith.com",
|
|
source: "FORM",
|
|
isEnabled: true,
|
|
currentOrganizationId: "606ad7eec7a35467ac887f84",
|
|
organizationIds: ["606ad7eec7a35467ac887f84"],
|
|
groupIds: [],
|
|
permissions: [],
|
|
isAnonymous: false,
|
|
username: "b1@appsmith.com",
|
|
accountNonExpired: true,
|
|
accountNonLocked: true,
|
|
credentialsNonExpired: true,
|
|
claims: {},
|
|
enabled: true,
|
|
address: {},
|
|
new: true,
|
|
},
|
|
forkUrl:
|
|
"/user/login?redirectUrl=https://dev.appsmith.com/applications/606ad816c7a35467ac887f87/pages/606ad816c7a35467ac887f89/fork",
|
|
loginUrl:
|
|
"/user/login?redirectUrl=https://dev.appsmith.com/applications/606ad816c7a35467ac887f87/pages/606ad816c7a35467ac887f89",
|
|
};
|
|
|
|
let container: any = null;
|
|
describe("get app viewer header CTA", () => {
|
|
beforeEach(async () => {
|
|
// setup a DOM element as a render target
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
});
|
|
it("renders the edit app button and does not render the fork app button", async () => {
|
|
const CTA = GetAppViewerHeaderCTA(sampleProps);
|
|
if (CTA) {
|
|
render(CTA);
|
|
const result = await waitFor(() =>
|
|
document.querySelector(".t--back-to-editor"),
|
|
);
|
|
expect(!!result).toBeTruthy();
|
|
|
|
const forkButton = await waitFor(() =>
|
|
document.querySelector(".t--fork-app"),
|
|
);
|
|
expect(!!forkButton).toBeFalsy();
|
|
}
|
|
});
|
|
it("renders the fork app button", async () => {
|
|
const CTA = GetAppViewerHeaderCTA({
|
|
...sampleProps,
|
|
canEdit: false,
|
|
currentApplicationDetails: {
|
|
...sampleProps.currentApplicationDetails,
|
|
forkingEnabled: true,
|
|
isPublic: true,
|
|
},
|
|
currentUser: {
|
|
...sampleProps.currentUser,
|
|
username: ANONYMOUS_USERNAME,
|
|
},
|
|
});
|
|
if (CTA) {
|
|
render(CTA);
|
|
const result = await waitFor(() =>
|
|
document.querySelector(".t--fork-app"),
|
|
);
|
|
expect(!!result).toBeTruthy();
|
|
}
|
|
});
|
|
it("renders the fork app link", async () => {
|
|
const CTA = GetAppViewerHeaderCTA({
|
|
...sampleProps,
|
|
canEdit: false,
|
|
currentApplicationDetails: {
|
|
...sampleProps.currentApplicationDetails,
|
|
forkingEnabled: true,
|
|
isPublic: true,
|
|
},
|
|
});
|
|
if (CTA) {
|
|
render(CTA);
|
|
const result = await waitFor(() =>
|
|
document.querySelector(".t--fork-btn-wrapper"),
|
|
);
|
|
expect(!!result).toBeTruthy();
|
|
}
|
|
});
|
|
it("renders the sign in link", async () => {
|
|
const CTA = GetAppViewerHeaderCTA({
|
|
...sampleProps,
|
|
canEdit: false,
|
|
currentApplicationDetails: {
|
|
...sampleProps.currentApplicationDetails,
|
|
isPublic: true,
|
|
},
|
|
});
|
|
if (CTA) {
|
|
render(CTA);
|
|
const result = await waitFor(() => document.querySelector(".t--sign-in"));
|
|
expect(!!result).toBeTruthy();
|
|
}
|
|
});
|
|
afterEach(() => {
|
|
// cleanup on exiting
|
|
unmountComponentAtNode(container);
|
|
container.remove();
|
|
container = null;
|
|
});
|
|
});
|