PromucFlow_constructor/app/client/src/pages/AppViewer/PrimaryCTA.test.tsx
Ankit Srivastava a45dcfa61f
feat: Homepage experience v2 changes (#29282)
> Pull Request Template
>
> Use this template to quickly create a well written pull request.
Delete all quotes before creating the pull request.
>
## Description
> Add a TL;DR when description is extra long (helps content team)
>
> Please include a summary of the changes and which issue has been
fixed. Please also include relevant motivation
> and context. List any dependencies that are required for this change
>
> Links to Notion, Figma or any other documents that might be relevant
to the PR
>
>
#### PR fixes following issue(s)
Fixes # (issue number)
> if no issue exists, please create an issue and ask the maintainers
about this first
>
>
#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
    - Added new workspace search functionality in the search bar.
    - Introduced a help button for user assistance.
- Implemented new UI components for workspace selection and management.
    - Enhanced application card with edit permission checks.
- Integrated workspace actions for creating and fetching workspaces
directly from the UI.

- **Improvements**
    - Improved workspace and application fetching logic.
    - Enhanced Global Search with updated import paths and logic.
- Refined the layout and styling of the applications page and sub-header
components.
- Optimized workspace-related sagas and reducers for better performance
and maintainability.

- **Bug Fixes**
- Fixed tooltip functionality in "Reconnect Datasources" within
templates.
    - Corrected test logic for forking templates and applications.
    - Updated Cypress test commands for consistency and reliability.
- Addressed issues with application URL test cases and workspace import
logic.

- **Documentation**
- Updated messages and constants related to workspace and application UI
elements for clearer user communication.

- **Chores**
- Cleaned up unused code and simplified selectors across various
components and tests.
- Refactored application and workspace selectors for improved code
organization.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Dipyaman Biswas <dipyaman@appsmith.com>
Co-authored-by: Abhijeet <abhi.nagarnaik@gmail.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Goutham Pratapa <goutham@appsmith.com>
Co-authored-by: Ankita Kinger <ankita@appsmith.com>
Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Nayan <nayan@appsmith.com>
Co-authored-by: Rishabh Rathod <rishabh.rathod@appsmith.com>
2024-01-25 19:11:48 +05:30

193 lines
4.5 KiB
TypeScript

import React from "react";
import { render, screen, cleanup } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { Provider } from "react-redux";
import { ThemeProvider } from "styled-components";
import { lightTheme } from "selectors/themeSelectors";
import PrimaryCTA from "./PrimaryCTA";
import configureStore from "redux-mock-store";
jest.mock("react-router", () => ({
...jest.requireActual("react-router"),
useHistory: () => ({ push: jest.fn() }),
useLocation: () => ({
pathname: "/app/test-3/page1-63cccd44463c535b9fbc297c",
search: "?fork=true",
}),
}));
const mockDispatch = jest.fn();
jest.mock("react-redux", () => ({
...jest.requireActual("react-redux"),
useDispatch: () => mockDispatch,
}));
export const initialState: any = {
entities: {
pageList: {
applicationId: 1,
currentPageId: 1,
pages: [
{
pageId: 1,
slug: "pageSlug",
},
],
},
datasources: {
list: [],
},
actions: [],
canvasWidgets: {
main_component: {},
},
},
ui: {
gitSync: {
protectedBranches: [],
},
editor: {
isPreviewMode: false,
},
appSettingsPane: {
isOpen: false,
},
appTheming: {
selectedTheme: {
properties: {
colors: {
primaryColor: "",
},
borderRadius: {
appBorderRadius: "",
},
},
},
},
applications: {
currentApplication: {
id: "605c435a91dea93f0eaf91b8",
name: "My Application",
slug: "my-application",
workspaceId: "",
evaluationVersion: 1,
appIsExample: false,
gitApplicationMetadata: undefined,
applicationVersion: 2,
forkingEnabled: true,
isPublic: true,
},
workspaces: [],
},
workspaces: {
list: [],
},
selectedWorkspace: {
loadingStates: {
isFetchingApplications: false,
},
},
theme: {
theme: {
colors: {
applications: {
iconColor: "#f2f2f2",
},
success: {
main: "#e2e2e2",
},
},
},
},
users: {
currentUser: undefined,
},
},
};
const state = JSON.parse(JSON.stringify(initialState));
const mockStore = configureStore();
export function getStore(action?: string) {
switch (action) {
case "SET_CURRENT_USER_DETAILS":
state.ui.users.currentUser = {
username: "test",
};
break;
}
return mockStore(state);
}
export const fetchApplicationMockResponse = {
responseMeta: {
status: 200,
success: true,
},
data: {
application: {
id: "605c435a91dea93f0eaf91b8",
name: "My Application",
slug: "my-application",
workspaceId: "",
evaluationVersion: 1,
appIsExample: false,
gitApplicationMetadata: undefined,
applicationVersion: 2,
forkingEnabled: true,
isPublic: true,
},
pages: [
{
id: "605c435a91dea93f0eaf91ba",
name: "Page1",
isDefault: true,
slug: "page-1",
},
{
id: "605c435a91dea93f0eaf91bc",
name: "Page2",
isDefault: false,
slug: "page-2",
},
],
workspaceId: "",
},
};
describe("App viewer fork button", () => {
afterEach(cleanup);
it("Fork modal trigger should not be displayed until user details are fetched", () => {
render(
<Provider store={getStore()}>
<ThemeProvider theme={lightTheme}>
<PrimaryCTA
navColorStyle="solid"
primaryColor="red"
url={"/app/test-3/page1-63cccd44463c535b9fbc297c/edit"}
/>
</ThemeProvider>
</Provider>,
);
expect(screen.queryAllByTestId("fork-modal-trigger").length).toEqual(0);
expect(mockDispatch).toHaveBeenCalledTimes(0);
mockDispatch.mockClear();
});
it("Fork modal trigger should be displayed when user details are defined and user is not anonymous", () => {
render(
<Provider store={getStore("SET_CURRENT_USER_DETAILS")}>
<ThemeProvider theme={lightTheme}>
<PrimaryCTA
navColorStyle="solid"
primaryColor="red"
url={"/app/test-3/page1-63cccd44463c535b9fbc297c/edit"}
/>
</ThemeProvider>
</Provider>,
);
expect(screen.queryAllByTestId("fork-modal-trigger").length).toEqual(1);
expect(mockDispatch).toHaveBeenCalledTimes(1);
mockDispatch.mockClear();
});
});