Skip to content

Commit

Permalink
test: add coverage for changes in response component
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushpahwa committed Feb 24, 2025
1 parent 2051228 commit afe8491
Showing 1 changed file with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const defaultProps = {
responseTabHeight: 200,
};

// mock the postrunactionmap
jest.mock("ee/components/PostActionRunComponents", () => ({
PostRunActionComponentMap: {
test_modal: () => <div data-testid="t--post-run-action-test-modal-form" />,
},
}));

const storeData = getIDETestState({});

describe("Response", () => {
Expand All @@ -36,6 +43,7 @@ describe("Response", () => {

beforeEach(() => {
store = mockStore(storeData);
jest.clearAllMocks();
});

/** Test use prepared statement warning **/
Expand Down Expand Up @@ -208,4 +216,152 @@ describe("Response", () => {
container.querySelector("[data-testid='t--prepared-statement-warning']"),
).toBeNull();
});

it("6. Should show post run action container when post run action exists", () => {
const postRunAction = {
type: "FORM",
name: "test_modal",
};
const actionResponse = {
isExecutionSuccess: true,
body: [{ key: "value" }],
postRunAction,
dataTypes: [{ dataType: "JSON" }],
responseDisplayFormat: "JSON",
} as unknown as ActionResponse;

store = mockStore({
...storeData,
entities: {
...storeData.entities,
actions: [
{
config: {
id: "test-action-id",
name: "Test Action",
},
isLoading: false,
data: actionResponse,
},
],
},
});

const props = {
...defaultProps,
actionResponse,
currentContentType: "JSON",
};

const { getByTestId } = render(
<Provider store={store}>
<ThemeProvider theme={lightTheme}>
<Router>
<Response {...props} />
</Router>
</ThemeProvider>
</Provider>,
);

// Check if post run action container is showing
expect(getByTestId("t--post-run-action-container")).not.toBeNull();
expect(getByTestId("t--post-run-action-test-modal-form")).not.toBeNull();
});

it("7. Should not show post run action container when post run action doesn't exist", () => {
const actionResponse = {
isExecutionSuccess: true,
body: [{ key: "value" }],
dataTypes: [{ dataType: "JSON" }],
responseDisplayFormat: "JSON",
} as unknown as ActionResponse;

store = mockStore({
...storeData,
entities: {
...storeData.entities,
actions: [
{
config: {
id: "test-action-id",
name: "Test Action",
},
isLoading: false,
data: actionResponse,
},
],
},
});

const props = {
...defaultProps,
actionResponse,
};

const { container } = render(
<Provider store={store}>
<ThemeProvider theme={lightTheme}>
<Router>
<Response {...props} />
</Router>
</ThemeProvider>
</Provider>,
);

// Check if post run action container is not showing
expect(
container.querySelector("[data-testid='t--post-run-action-container']"),
).toBeNull();
});

it("8. Should not show post run action container when correct mapping is not found", () => {
const postRunAction = {
type: "FORM",
name: "invalid_modal",
};
const actionResponse = {
isExecutionSuccess: true,
body: [{ key: "value" }],
postRunAction,
dataTypes: [{ dataType: "JSON" }],
responseDisplayFormat: "JSON",
} as unknown as ActionResponse;

store = mockStore({
...storeData,
entities: {
...storeData.entities,
actions: [
{
config: {
id: "test-action-id",
name: "Test Action",
},
isLoading: false,
data: actionResponse,
},
],
},
});

const props = {
...defaultProps,
actionResponse,
};

const { container } = render(
<Provider store={store}>
<ThemeProvider theme={lightTheme}>
<Router>
<Response {...props} />
</Router>
</ThemeProvider>
</Provider>,
);

// Check if post run action container is not showing
expect(
container.querySelector("[data-testid='t--post-run-action-container']"),
).toBeNull();
});
});

0 comments on commit afe8491

Please sign in to comment.