Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from "react";
import { waitFor } from "@testing-library/react";
import FormTemplateItemListPage from "../form-template-item-list-page";
import { renderWithRedux } from "../../../../utils/test-utils";
import { getFormTemplateItems } from "../../../../actions/form-template-item-actions";
import { getFormTemplate } from "../../../../actions/form-template-actions";
import { DEFAULT_CURRENT_PAGE } from "../../../../utils/constants";

jest.mock("../../../../actions/form-template-item-actions", () => ({
...jest.requireActual("../../../../actions/form-template-item-actions"),
getFormTemplateItems: jest.fn(() => () => Promise.resolve())
}));

jest.mock("../../../../actions/form-template-actions", () => ({
...jest.requireActual("../../../../actions/form-template-actions"),
getFormTemplate: jest.fn(() => () => Promise.resolve())
}));

describe("FormTemplateItemListPage", () => {
const formTemplateId = 123;
const initialPage = 2;
const perPage = 10;
const order = "name";
const orderDir = 1;
const hideArchived = false;
const buildInitialState = () => ({
currentFormTemplateItemListState: {
formTemplateItems: [],
term: "",
order,
orderDir,
currentPage: initialPage,
lastPage: 1,
perPage,
totalFormTemplateItems: 5,
hideArchived
},
currentFormTemplateState: {
entity: { id: formTemplateId, code: "FT", name: "Form Template" },
errors: {}
},
currentFormTemplateItemState: {
entity: {},
errors: {}
}
});

beforeEach(() => {
jest.clearAllMocks();
});

describe("Component", () => {
test("should request page 1 on mount when previous page is 2", async () => {
renderWithRedux(
<FormTemplateItemListPage formTemplateId={formTemplateId} />,
{
initialState: buildInitialState()
}
);

await waitFor(() => {
expect(getFormTemplate).toHaveBeenCalledWith(formTemplateId);
expect(getFormTemplateItems).toHaveBeenCalledTimes(1);
expect(getFormTemplateItems).toHaveBeenNthCalledWith(
1,
formTemplateId,
"",
DEFAULT_CURRENT_PAGE,
perPage,
order,
orderDir,
hideArchived
);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2025 OpenStack Foundation
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -80,7 +80,7 @@ const FormTemplateItemListPage = ({
getFormTemplateItems(
formTemplateId,
term,
currentPage,
DEFAULT_CURRENT_PAGE,
perPage,
order,
orderDir,
Expand Down