forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for RequestTemplate component
- Loading branch information
1 parent
764d8f3
commit 9a48f05
Showing
2 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
app/client/src/pages/Templates/Template/RequestTemplate.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { createMessage } from "@appsmith/ads-old"; | ||
import "@testing-library/jest-dom"; | ||
import { fireEvent, render } from "@testing-library/react"; | ||
import { | ||
REQUEST_BUILDING_BLOCK, | ||
REQUEST_TEMPLATE, | ||
} from "ee/constants/messages"; | ||
import AnalyticsUtil from "ee/utils/AnalyticsUtil"; | ||
import { unitTestBaseMockStore } from "layoutSystems/common/dropTarget/unitTestUtils"; | ||
import React from "react"; | ||
import { Provider } from "react-redux"; | ||
import configureStore from "redux-mock-store"; | ||
import { lightTheme } from "selectors/themeSelectors"; | ||
import { ThemeProvider } from "styled-components"; | ||
import RequestTemplate, { | ||
REQUEST_TEMPLATE_URL, | ||
type RequestTemplateProps, | ||
} from "./RequestTemplate"; | ||
const mockStore = configureStore([]); | ||
|
||
const BaseComponentRender = ( | ||
props: RequestTemplateProps, | ||
storeToUse = unitTestBaseMockStore, | ||
) => ( | ||
<Provider store={mockStore(storeToUse)}> | ||
<ThemeProvider theme={lightTheme}> | ||
<RequestTemplate {...props} /> | ||
</ThemeProvider> | ||
</Provider> | ||
); | ||
|
||
describe("RequestTemplate", () => { | ||
it("should display correct message based on isBuildingBlock prop", () => { | ||
const { getByText } = render( | ||
BaseComponentRender({ isBuildingBlock: true }), | ||
); | ||
|
||
expect( | ||
getByText(createMessage(REQUEST_BUILDING_BLOCK)), | ||
).toBeInTheDocument(); | ||
}); | ||
it("should open REQUEST_TEMPLATE_URL in a new window when button is clicked", () => { | ||
const openSpy = jest.spyOn(window, "open"); | ||
const { getByText } = render( | ||
BaseComponentRender({ isBuildingBlock: false }), | ||
); | ||
const button = getByText(createMessage(REQUEST_TEMPLATE)); | ||
|
||
fireEvent.click(button); | ||
expect(openSpy).toHaveBeenCalledWith(REQUEST_TEMPLATE_URL); | ||
}); | ||
|
||
it('should trigger AnalyticsUtil logEvent with "REQUEST_NEW_TEMPLATE" when button is clicked', () => { | ||
const logEventSpy = jest.spyOn(AnalyticsUtil, "logEvent"); | ||
const { getByText } = render( | ||
BaseComponentRender({ isBuildingBlock: false }), | ||
); | ||
const button = getByText(createMessage(REQUEST_TEMPLATE)); | ||
|
||
fireEvent.click(button); | ||
expect(logEventSpy).toHaveBeenCalledWith("REQUEST_NEW_TEMPLATE"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters