Skip to content

Commit f2c3125

Browse files
authored
chore: adds automation for request templates component (#37140)
## Description This was done manually by QA team. This unit test ensures that a valid URL is present for requesting template and is opens correctly. Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Templates" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11592781616> > Commit: 9a48f05 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11592781616&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Templates` > Spec: > <hr>Wed, 30 Oct 2024 12:27:43 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new test suite for the `RequestTemplate` component to validate its behavior and user interactions. - `REQUEST_TEMPLATE_URL` and `RequestTemplateProps` are now exported for use in other modules. - **Bug Fixes** - Enhanced testing to ensure correct message display and button functionality within the `RequestTemplate`. - **Documentation** - Updated import statements for better organization and clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 72670ae commit f2c3125

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { createMessage } from "@appsmith/ads-old";
2+
import "@testing-library/jest-dom";
3+
import { fireEvent, render } from "@testing-library/react";
4+
import {
5+
REQUEST_BUILDING_BLOCK,
6+
REQUEST_TEMPLATE,
7+
} from "ee/constants/messages";
8+
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
9+
import { unitTestBaseMockStore } from "layoutSystems/common/dropTarget/unitTestUtils";
10+
import React from "react";
11+
import { Provider } from "react-redux";
12+
import configureStore from "redux-mock-store";
13+
import { lightTheme } from "selectors/themeSelectors";
14+
import { ThemeProvider } from "styled-components";
15+
import RequestTemplate, {
16+
REQUEST_TEMPLATE_URL,
17+
type RequestTemplateProps,
18+
} from "./RequestTemplate";
19+
const mockStore = configureStore([]);
20+
21+
const BaseComponentRender = (
22+
props: RequestTemplateProps,
23+
storeToUse = unitTestBaseMockStore,
24+
) => (
25+
<Provider store={mockStore(storeToUse)}>
26+
<ThemeProvider theme={lightTheme}>
27+
<RequestTemplate {...props} />
28+
</ThemeProvider>
29+
</Provider>
30+
);
31+
32+
describe("RequestTemplate", () => {
33+
it("should display correct message based on isBuildingBlock prop", () => {
34+
const { getByText } = render(
35+
BaseComponentRender({ isBuildingBlock: true }),
36+
);
37+
38+
expect(
39+
getByText(createMessage(REQUEST_BUILDING_BLOCK)),
40+
).toBeInTheDocument();
41+
});
42+
it("should open REQUEST_TEMPLATE_URL in a new window when button is clicked", () => {
43+
const openSpy = jest.spyOn(window, "open");
44+
const { getByText } = render(
45+
BaseComponentRender({ isBuildingBlock: false }),
46+
);
47+
const button = getByText(createMessage(REQUEST_TEMPLATE));
48+
49+
fireEvent.click(button);
50+
expect(openSpy).toHaveBeenCalledWith(REQUEST_TEMPLATE_URL);
51+
});
52+
53+
it('should trigger AnalyticsUtil logEvent with "REQUEST_NEW_TEMPLATE" when button is clicked', () => {
54+
const logEventSpy = jest.spyOn(AnalyticsUtil, "logEvent");
55+
const { getByText } = render(
56+
BaseComponentRender({ isBuildingBlock: false }),
57+
);
58+
const button = getByText(createMessage(REQUEST_TEMPLATE));
59+
60+
fireEvent.click(button);
61+
expect(logEventSpy).toHaveBeenCalledWith("REQUEST_NEW_TEMPLATE");
62+
});
63+
});

app/client/src/pages/Templates/Template/RequestTemplate.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React from "react";
2-
import styled from "styled-components";
3-
import { Text, TextType } from "@appsmith/ads-old";
41
import { Button } from "@appsmith/ads";
2+
import { Text, TextType } from "@appsmith/ads-old";
53
import RequestTemplateSvg from "assets/images/request-template.svg";
64
import {
75
COULDNT_FIND_TEMPLATE,
8-
createMessage,
96
COULDNT_FIND_TEMPLATE_DESCRIPTION,
10-
REQUEST_TEMPLATE,
7+
createMessage,
118
REQUEST_BUILDING_BLOCK,
9+
REQUEST_TEMPLATE,
1210
} from "ee/constants/messages";
1311
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
12+
import React from "react";
13+
import styled from "styled-components";
1414

1515
const Wrapper = styled.div`
1616
border: 1px solid var(--ads-v2-color-border);
@@ -48,10 +48,10 @@ const StyledImage = styled.img`
4848
border-radius: var(--ads-v2-border-radius);
4949
`;
5050

51-
const REQUEST_TEMPLATE_URL =
51+
export const REQUEST_TEMPLATE_URL =
5252
"https://app.appsmith.com/app/request-templates/request-list-6241c12fc99df2369931a714";
5353

54-
interface RequestTemplateProps {
54+
export interface RequestTemplateProps {
5555
isBuildingBlock?: boolean;
5656
}
5757

0 commit comments

Comments
 (0)