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
6 changes: 2 additions & 4 deletions src/actions/page-template-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ export const savePageTemplate = (entity) => async (dispatch) => {
html: T.translate("page_template_list.page_crud.page_saved")
})
);
getPageTemplates()(dispatch);
})
.catch((err) => {
console.error(err);
throw err;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are already returning the promise so this throw is redundant

})
.finally(() => {
dispatch(stopLoading());
Expand All @@ -200,10 +199,9 @@ export const savePageTemplate = (entity) => async (dispatch) => {
html: T.translate("page_template_list.page_crud.page_created")
})
);
getPageTemplates()(dispatch);
})
.catch((err) => {
console.error(err);
throw err;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are already returning the promise so this throw is redundant

})
.finally(() => {
dispatch(stopLoading());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ const PageTemplateListPage = ({
setOpenCloneDialog(true);
};

const handleSavePageTemplate = (entity) => {
savePageTemplate(entity).then(() => setOpenPageDialog(false));
};
const handleSavePageTemplate = (entity) =>
Comment thread
tomrndom marked this conversation as resolved.
savePageTemplate(entity).then(() => {
getPageTemplates(
term,
DEFAULT_CURRENT_PAGE,
perPage,
order,
orderDir,
showArchived
).catch(() => {});
});

const handleArchive = (item) =>
item.is_archived
Expand Down Expand Up @@ -285,6 +293,7 @@ const PageTemplateListPage = ({
pageTemplate={pageTemplate}
onClose={handleClosePageDialog}
onSave={handleSavePageTemplate}
isGlobal
/>
)}
{openCloneDialog && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import "@testing-library/jest-dom";
import PageModules from "./page-template-modules-form";
import showConfirmDialog from "../../../../components/mui/showConfirmDialog";
import showConfirmDialog from "openstack-uicore-foundation/lib/components/mui/show-confirm-dialog";
import PageModules from "../page-template-modules-form";
import {
PAGES_MODULE_KINDS,
PAGE_MODULES_MEDIA_TYPES
} from "../../../../utils/constants";
} from "../../../../../utils/constants";

const mockStore = configureStore([thunk]);

// Mocks
jest.mock("../../../../components/mui/showConfirmDialog", () => jest.fn());
jest.mock("../../../../actions/media-file-type-actions", () => ({
jest.mock(
"openstack-uicore-foundation/lib/components/mui/show-confirm-dialog",
() => jest.fn()
);
jest.mock("../../../../../actions/media-file-type-actions", () => ({
getAllMediaFileTypes: jest.fn(() => () => Promise.resolve())
}));

jest.mock(
"../../../../components/inputs/formik-text-editor",
"openstack-uicore-foundation/lib/components/mui/formik-inputs/texteditor",
() =>
function MockFormikTextEditor({ name }) {
return <textarea data-testid={`text-editor-${name}`} />;
Expand All @@ -38,15 +41,15 @@ jest.mock(
);

jest.mock(
"../../../../components/mui/formik-inputs/mui-formik-textfield",
"openstack-uicore-foundation/lib/components/mui/formik-inputs/textfield",
() =>
function MockMuiFormikTextField({ name }) {
return <input data-testid={`textfield-${name}`} />;
}
);

jest.mock(
"../../../../components/mui/formik-inputs/mui-formik-select",
"openstack-uicore-foundation/lib/components/mui/formik-inputs/select",
() =>
function MockMuiFormikSelect({ name, children }) {
return <select data-testid={`select-${name}`}>{children}</select>;
Expand All @@ -62,25 +65,17 @@ jest.mock(
);

jest.mock(
"../../../../components/mui/formik-inputs/mui-formik-radio-group",
"openstack-uicore-foundation/lib/components/mui/formik-inputs/radio-group",
() =>
function MockMuiFormikRadioGroup({ name }) {
return <div data-testid={`radio-group-${name}`} />;
}
);

jest.mock(
"../../../../components/mui/formik-inputs/mui-formik-async-select",
() =>
function MockMuiFormikAsyncSelect({ name }) {
return <select data-testid={`async-select-${name}`} />;
}
);

// Mock DragAndDropList to capture onReorder
let capturedOnReorder = null;
jest.mock(
"../../../../components/mui/dnd-list",
"openstack-uicore-foundation/lib/components/mui/dnd-list",
() =>
function MockDragAndDropList({ items, renderItem, onReorder }) {
capturedOnReorder = onReorder;
Expand All @@ -97,7 +92,10 @@ jest.mock(
);

// Helper function to render the component with Formik and Redux
const renderWithFormik = (initialValues = { modules: [] }) => {
const renderWithFormik = (
initialValues = { modules: [] },
isGlobal = false
) => {
const store = mockStore({
mediaUploadState: {
media_file_types: []
Expand All @@ -107,7 +105,7 @@ const renderWithFormik = (initialValues = { modules: [] }) => {
<Provider store={store}>
<Formik initialValues={initialValues} onSubmit={jest.fn()}>
<Form>
<PageModules name="modules" />
<PageModules name="modules" isGlobal={isGlobal} />
</Form>
</Formik>
</Provider>
Expand Down Expand Up @@ -173,6 +171,26 @@ describe("PageModules", () => {
});
});

describe("isGlobal", () => {
test("shows the upload deadline datepicker for a MEDIA module when isGlobal is false", () => {
const modules = [createModule(PAGES_MODULE_KINDS.MEDIA, 0, 1)];
renderWithFormik({ modules }, false);

expect(
screen.getByTestId("datepicker-modules[0].upload_deadline")
).toBeInTheDocument();
});

test("hides the upload deadline datepicker for a MEDIA module when isGlobal is true", () => {
const modules = [createModule(PAGES_MODULE_KINDS.MEDIA, 0, 1)];
renderWithFormik({ modules }, true);

expect(
screen.queryByTestId("datepicker-modules[0].upload_deadline")
).not.toBeInTheDocument();
});
});

describe("Module ordering", () => {
test("renders modules in the order they appear in the array", () => {
const modules = [
Expand Down
Loading
Loading