): ReactElem
{showBottomPagination && pagination}
{props.preview && props.paginationType === "loadMore" && (
- Load more
+ {loadMoreButtonCaption}
)}
- {!props.preview && Load more}
+ {!props.preview && {loadMoreButtonCaption}}
diff --git a/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx b/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx
index c64d6162b7..150b22cec9 100644
--- a/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx
+++ b/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx
@@ -4,7 +4,11 @@ import { createElement } from "react";
import { useGalleryRootScope } from "src/helpers/root-context";
export function LoadMoreButton(props: JSX.IntrinsicElements["button"]): React.ReactNode {
- return ;
+ return (
+
+ );
}
export const LoadMore = observer(function LoadMore(props: { children: React.ReactNode }): React.ReactNode {
From 03ce0fa123748083549bd7884f5710d235bf33d7 Mon Sep 17 00:00:00 2001
From: Illia Obukhau <8282906+iobuhov@users.noreply.github.com>
Date: Tue, 1 Jul 2025 10:04:23 +0200
Subject: [PATCH 4/4] test: fix unit tests
---
.../gallery-web/src/components/Gallery.tsx | 2 +-
.../gallery-web/src/components/LoadMore.tsx | 2 +-
.../src/components/__tests__/Gallery.spec.tsx | 98 +++++++++++--------
.../__snapshots__/Gallery.spec.tsx.snap | 67 +++++++++++++
.../gallery-web/src/utils/test-utils.tsx | 53 +++++++++-
5 files changed, 176 insertions(+), 46 deletions(-)
diff --git a/packages/pluggableWidgets/gallery-web/src/components/Gallery.tsx b/packages/pluggableWidgets/gallery-web/src/components/Gallery.tsx
index be5ab3b220..7b01892351 100644
--- a/packages/pluggableWidgets/gallery-web/src/components/Gallery.tsx
+++ b/packages/pluggableWidgets/gallery-web/src/components/Gallery.tsx
@@ -13,8 +13,8 @@ import { GalleryTopBar } from "./GalleryTopBar";
import { ListBox } from "./ListBox";
import { ListItem } from "./ListItem";
-import { LoadMore, LoadMoreButton as LoadMorePreview } from "src/components/LoadMore";
import { PaginationEnum, ShowPagingButtonsEnum } from "typings/GalleryProps";
+import { LoadMore, LoadMoreButton as LoadMorePreview } from "../components/LoadMore";
import { ItemEventsController } from "../typings/ItemEventsController";
export interface GalleryProps {
diff --git a/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx b/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx
index 150b22cec9..3efbf728bc 100644
--- a/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx
+++ b/packages/pluggableWidgets/gallery-web/src/components/LoadMore.tsx
@@ -1,7 +1,7 @@
import cn from "classnames";
import { observer } from "mobx-react-lite";
import { createElement } from "react";
-import { useGalleryRootScope } from "src/helpers/root-context";
+import { useGalleryRootScope } from "../helpers/root-context";
export function LoadMoreButton(props: JSX.IntrinsicElements["button"]): React.ReactNode {
return (
diff --git a/packages/pluggableWidgets/gallery-web/src/components/__tests__/Gallery.spec.tsx b/packages/pluggableWidgets/gallery-web/src/components/__tests__/Gallery.spec.tsx
index b8f54f49ef..3f6bca60bc 100644
--- a/packages/pluggableWidgets/gallery-web/src/components/__tests__/Gallery.spec.tsx
+++ b/packages/pluggableWidgets/gallery-web/src/components/__tests__/Gallery.spec.tsx
@@ -4,7 +4,7 @@ import { render, waitFor } from "@testing-library/react";
import { ObjectItem } from "mendix";
import { createElement } from "react";
import { ItemHelperBuilder } from "../../utils/builders/ItemHelperBuilder";
-import { mockItemHelperWithAction, mockProps, setup } from "../../utils/test-utils";
+import { mockItemHelperWithAction, mockProps, setup, withGalleryContext } from "../../utils/test-utils";
import { Gallery } from "../Gallery";
describe("Gallery", () => {
@@ -13,14 +13,14 @@ describe("Gallery", () => {
});
describe("DOM Structure", () => {
it("renders correctly", () => {
- const { asFragment } = render();
+ const { asFragment } = render(withGalleryContext());
expect(asFragment()).toMatchSnapshot();
});
it("renders correctly with onclick event", () => {
const { asFragment } = render(
-
+ withGalleryContext()
);
expect(asFragment()).toMatchSnapshot();
@@ -31,7 +31,7 @@ describe("Gallery", () => {
it("runs action on item click", async () => {
const execute = jest.fn();
const props = mockProps({ onClick: listAction(mock => ({ ...mock(), execute })) });
- const { user, getAllByRole } = setup();
+ const { user, getAllByRole } = setup(withGalleryContext());
const [item] = getAllByRole("listitem");
await user.click(item);
@@ -41,7 +41,7 @@ describe("Gallery", () => {
it("runs action on Enter|Space press when item is in focus", async () => {
const execute = jest.fn();
const props = mockProps({ onClick: listAction(mock => ({ ...mock(), execute })) });
- const { user, getAllByRole } = setup(} />);
+ const { user, getAllByRole } = setup(withGalleryContext(} />));
const [item] = getAllByRole("listitem");
await user.tab();
@@ -55,19 +55,19 @@ describe("Gallery", () => {
describe("with different configurations per platform", () => {
it("contains correct classes for desktop", () => {
- const { getByRole } = render();
+ const { getByRole } = render(withGalleryContext());
const list = getByRole("list");
expect(list).toHaveClass("widget-gallery-lg-12");
});
it("contains correct classes for tablet", () => {
- const { getByRole } = render();
+ const { getByRole } = render(withGalleryContext());
const list = getByRole("list");
expect(list).toHaveClass("widget-gallery-md-6");
});
it("contains correct classes for phone", () => {
- const { getByRole } = render();
+ const { getByRole } = render(withGalleryContext());
const list = getByRole("list");
expect(list).toHaveClass("widget-gallery-sm-3");
});
@@ -75,17 +75,19 @@ describe("Gallery", () => {
describe("with custom classes", () => {
it("contains correct classes in the wrapper", () => {
- const { container } = render();
+ const { container } = render(withGalleryContext());
expect(container.querySelector(".custom-class")).toBeVisible();
});
it("contains correct classes in the items", () => {
const { getAllByRole } = render(
- b.withItemClass(listExp(() => "custom-class")))}
- />
+ withGalleryContext(
+ b.withItemClass(listExp(() => "custom-class")))}
+ />
+ )
);
const [item] = getAllByRole("listitem");
@@ -96,7 +98,9 @@ describe("Gallery", () => {
describe("with pagination", () => {
it("renders correctly", () => {
const { asFragment } = render(
-
+ withGalleryContext(
+
+ )
);
expect(asFragment()).toMatchSnapshot();
@@ -105,14 +109,16 @@ describe("Gallery", () => {
it("triggers correct events on click next button", async () => {
const setPage = jest.fn();
const { user, getByLabelText } = setup(
-
+ withGalleryContext(
+
+ )
);
const next = getByLabelText("Go to next page");
@@ -124,11 +130,13 @@ describe("Gallery", () => {
describe("with empty option", () => {
it("renders correctly", () => {
const { asFragment } = render(
- renderWrapper(No items found)}
- />
+ withGalleryContext(
+ renderWrapper(No items found)}
+ />
+ )
);
expect(asFragment()).toMatchSnapshot();
@@ -138,13 +146,15 @@ describe("Gallery", () => {
describe("with accessibility properties", () => {
it("renders correctly without items", () => {
const { asFragment } = render(
- renderWrapper(No items found)}
- />
+ withGalleryContext(
+ renderWrapper(No items found)}
+ />
+ )
);
expect(asFragment()).toMatchSnapshot();
@@ -152,14 +162,16 @@ describe("Gallery", () => {
it("renders correctly with items", () => {
const { asFragment } = render(
- `title for '${item.id}'`}
- headerTitle="filter title"
- emptyMessageTitle="empty message"
- emptyPlaceholderRenderer={renderWrapper => renderWrapper(No items found)}
- />
+ withGalleryContext(
+ `title for '${item.id}'`}
+ headerTitle="filter title"
+ emptyMessageTitle="empty message"
+ emptyPlaceholderRenderer={renderWrapper => renderWrapper(No items found)}
+ />
+ )
);
expect(asFragment()).toMatchSnapshot();
@@ -169,7 +181,7 @@ describe("Gallery", () => {
describe("without filters", () => {
it("renders structure without header container", () => {
const props = { ...mockProps(), showHeader: false, header: undefined };
- const { asFragment } = render();
+ const { asFragment } = render(withGalleryContext());
expect(asFragment()).toMatchSnapshot();
});
diff --git a/packages/pluggableWidgets/gallery-web/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap b/packages/pluggableWidgets/gallery-web/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap
index 45f1262440..94c8ad9476 100644
--- a/packages/pluggableWidgets/gallery-web/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap
+++ b/packages/pluggableWidgets/gallery-web/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap
@@ -6,6 +6,9 @@ exports[`Gallery DOM Structure renders correctly 1`] = `
class="widget-gallery my-gallery"
data-focusindex="0"
>
+