diff --git a/jest.config.js b/jest.config.js index 204da674..41e840f9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,28 +1,41 @@ -// Sync object -/** @type {import('@jest/types').Config.InitialOptions} */ -const config = { - verbose: true, - collectCoverage: true, - coverageThreshold: { - global: { - branches: 10, - functions: 10, - lines: 10, - }, - }, - coverageReporters: ["json-summary", "lcov"], - collectCoverageFrom: ["./src/forms/**", "!./src/components/**/*.snap"], +/** + * @returns {Promise} + */ +module.exports = { transform: { - "^.+\\.tsx?$": "@swc/jest", + "^.+\\.(j|t)sx?$": "@swc/jest", }, transformIgnorePatterns: ["/node_modules/(?!@openmrs)"], moduleNameMapper: { "\\.(s?css)$": "identity-obj-proxy", "@openmrs/esm-framework": "@openmrs/esm-framework/mock", - "react-i18next": "/__mocks__/react-i18next.js", - "lodash-es": "lodash", - "react-markdown": "/__mocks__/react-markdown.tsx", + "^lodash-es/(.*)$": "lodash/$1", + "^uuid$": "/node_modules/uuid/dist/index.js", + "^dexie$": require.resolve("dexie"), + }, + collectCoverageFrom: [ + "**/src/**/*.component.tsx", + "!**/node_modules/**", + "!**/vendor/**", + "!**/src/**/*.test.*", + "!**/src/declarations.d.tsx", + "!**/e2e/**", + ], + coverageThreshold: { + global: { + statements: 80, + branches: 80, + functions: 80, + lines: 80, + }, + }, + setupFilesAfterEnv: ["/src/setup-tests.ts"], + testPathIgnorePatterns: [ + "/packages/esm-form-entry-app", + "/e2e", + ], + testEnvironment: "jsdom", + testEnvironmentOptions: { + url: "http://localhost/", }, }; - -module.exports = config; diff --git a/src/components/lazy-cell/lazy-cell.test.tsx b/src/components/lazy-cell/lazy-cell.test.tsx new file mode 100644 index 00000000..f48d04a1 --- /dev/null +++ b/src/components/lazy-cell/lazy-cell.test.tsx @@ -0,0 +1,14 @@ +import React from "react"; +import { render, waitFor } from "@testing-library/react"; +import { LazyCell } from "./lazy-cell.component"; + +describe("LazyCell", () => { + test("renders the resolved value after the promise is resolved", async () => { + const { container } = render( + + ); + await waitFor(() => + expect(container.firstChild).toHaveTextContent("Lazy cell") + ); + }); +}); diff --git a/src/views/error-state/error-state.test.tsx b/src/views/error-state/error-state.test.tsx new file mode 100644 index 00000000..173d5188 --- /dev/null +++ b/src/views/error-state/error-state.test.tsx @@ -0,0 +1,25 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import { ErrorState } from "./error-state.component"; + +describe("ErrorState component", () => { + test("renders error message and header title", () => { + const error = { + response: { + status: 404, + statusText: "Not Found", + }, + }; + const headerTitle = "Error State"; + + render(); + + const errorMessage = screen.getByText("Error 404: Not Found"); + const errorCopy = screen.getByText( + "Sorry, there was a problem displaying this information. You can try to reload this page, or contact the site administrator and quote the error code above." + ); + + expect(errorMessage).toBeInTheDocument(); + expect(errorCopy).toBeInTheDocument(); + }); +});