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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@babel/core@7": "7.29.7",
"@codemirror/state": "^6.5.2",
"@codemirror/view": "^6.38.1",
"@mendix/pluggable-widgets-tools": "11.11.0",
"@mendix/pluggable-widgets-tools": "11.12.1",
"@mendix/pluggable-widgets-tools>@testing-library/react-native": "-",
"@mendix/pluggable-widgets-tools>eslint": "-",
"@mendix/pluggable-widgets-tools>eslint-config-prettier": "-",
Expand All @@ -79,7 +79,7 @@
"typescript": ">5.8.0 <6.0.0"
},
"patchedDependencies": {
"@mendix/pluggable-widgets-tools": "patches/@mendix__pluggable-widgets-tools.patch",
"@mendix/pluggable-widgets-tools@11.12.1": "patches/@mendix__pluggable-widgets-tools@11.12.1.patch",
"mime-types@2.1.35": "patches/mime-types@2.1.35.patch",
"mobx-react-lite@4.0.7": "patches/mobx-react-lite@4.0.7.patch",
"mobx@6.12.3": "patches/mobx@6.12.3.patch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { forwardRef } from "react";
import { dynamic } from "@mendix/widget-plugin-test-utils";

// Mock JsBarcode
const mockJsBarcode = jest.fn();
jest.mock("jsbarcode", () => mockJsBarcode);
jest.mock("jsbarcode", () => jest.fn());

// Mock the QRCodeSVG component
jest.mock("qrcode.react", () => ({
Expand All @@ -33,6 +32,7 @@ jest.mock("../utils/download-code", () => ({
downloadCode: jest.fn()
}));

import JsBarcode from "jsbarcode";
import {
BarcodeGeneratorContainerProps,
CodeFormatEnum,
Expand All @@ -42,6 +42,8 @@ import {
import BarcodeGenerator from "../BarcodeGenerator";
import { downloadCode } from "../utils/download-code";

const mockJsBarcode = JsBarcode as unknown as jest.Mock;

// Test utilities
function createMockWebImage(): WebImage {
return { uri: "data:image/png;base64,test123" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import { usePDFHighlightPositions } from "../utils/usePDFHighlightPositions";
import { usePDFSearch } from "../utils/usePDFSearch";
import { useZoomScale } from "../utils/useZoomScale";

const origin: string = (window.mx?.appUrl ?? window.location.origin).replace(/\/$/, "");
const options = {
cMapUrl: `${origin}/widgets/com/mendix/shared/pdfjs/cmaps/`,
standardFontDataUrl: `${origin}/widgets/com/mendix/shared/pdfjs/standard_fonts/`
};

const PDFViewer: DocRendererElement = (props: DocumentRendererProps) => {
const { file, setDocumentStatus, pdfjsWorkerUrl } = props;
const options = useMemo(() => {
const origin = (window.mx?.appUrl ?? window.location.origin).replace(/\/$/, "");
return {
cMapUrl: `${origin}/widgets/com/mendix/shared/pdfjs/cmaps/`,
standardFontDataUrl: `${origin}/widgets/com/mendix/shared/pdfjs/standard_fonts/`
};
}, []);
pdfjs.GlobalWorkerOptions.workerSrc = useMemo(() => {
if (pdfjsWorkerUrl?.status === "available") {
if (pdfjsWorkerUrl?.value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { act, fireEvent, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import { Document, pdfjs } from "react-pdf";
import PDFViewer from "../PDFViewer";
import type { DocumentRendererProps } from "../documentRenderer";
import PDFViewer from "../PDFViewer";

jest.mock("react-pdf", () => ({
Document: jest.fn((props: { children?: unknown }) => props.children ?? null),
Expand Down Expand Up @@ -42,27 +42,9 @@ describe("PDFViewer resource URL resolution", () => {
window.mx = originalMx;
});

/**
* Re-evaluates the PDFViewer module against the current `window` state and
* returns the resource `options` passed down to react-pdf's `Document`.
* The `origin` constant is computed at module load, so the module must be
* re-imported between cases for the different `window.mx` states to take effect.
*/
function loadOptions(): { cMapUrl: string; standardFontDataUrl: string } {
jest.resetModules();
// Re-require React, RTL, react-pdf and PDFViewer together so they all share
// the same freshly-evaluated React instance (resetModules resets React too).
/* eslint-disable @typescript-eslint/no-require-imports */
const { createElement } = require("react");
const { render: renderFresh } = require("@testing-library/react");
const reactPdf = require("react-pdf");
const FreshPDFViewer = require("../PDFViewer").default;
/* eslint-enable @typescript-eslint/no-require-imports */

renderFresh(createElement(FreshPDFViewer, buildProps()));

const calls = (reactPdf.Document as jest.Mock).mock.calls;
return calls[calls.length - 1][0].options;
render(<PDFViewer {...buildProps()} />);
return lastDocumentProps().options;
}

it("uses mx.appUrl to build absolute cMap and standard font URLs", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC } from "react";
import { DocumentViewerContainerProps } from "../../typings/DocumentViewerProps";

export declare const enum DocumentStatus {
export enum DocumentStatus {
available = "available",
error = "error",
loading = "loading"
Expand Down
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/dropdown-sort-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lint": "eslint src/ package.json",
"release": "pluggable-widgets-tools release:ts",
"start": "pluggable-widgets-tools start:server",
"test": "jest",
"test": "jest --projects jest.config.js",
"update-changelog": "rui-update-changelog-widget",
"verify": "rui-verify-package-format"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ describe("DatasourceUpdateProcessor", () => {
beforeEach(() => {
dsUpdater.processUpdate(new ListValueBuilder().isLoading().build());
});
});
test("'loaded' is not yet called", () => {
expect(callbacks.loaded).not.toHaveBeenCalled();

test("'loaded' is not yet called", () => {
expect(callbacks.loaded).not.toHaveBeenCalled();
});
});

describe("when called with loaded ds", () => {
Expand Down
12 changes: 4 additions & 8 deletions packages/pluggableWidgets/rich-text-web/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const base = require("@mendix/pluggable-widgets-tools/test-config/jest.config.js");

module.exports = {
...require("@mendix/pluggable-widgets-tools/test-config/jest.config.js"),
/**
* `quill` package is ESM module and because ESM is not supported by Jest yet
* we mark `nanoevents` as a module that should be transformed by ts-jest.
*/
transformIgnorePatterns: ["node_modules/(?!quill)/"],
preset: "ts-jest",
testEnvironment: "jsdom"
...base,
transformIgnorePatterns: ["node_modules/(?!quill)/"]
};
Loading
Loading