@trackunit/react-test-setup 1.0.4 → 1.0.6-alpha-0614a19af4e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -4,10 +4,33 @@ var failOnConsole = require('jest-fail-on-console');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var reactGoogleMaps = require('@vis.gl/react-google-maps');
6
6
  var jestMocks = require('@googlemaps/jest-mocks');
7
+ require('@okta/okta-react');
7
8
  require('@testing-library/jest-dom');
8
9
  var react = require('@testing-library/react');
9
10
  var polyfill = require('@js-temporal/polyfill');
10
11
  var web = require('@react-spring/web');
12
+ var react$1 = require('react');
13
+ var reactI18next = require('react-i18next');
14
+ var webStreamsPolyfill = require('web-streams-polyfill');
15
+
16
+ function _interopNamespaceDefault(e) {
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var reactI18next__namespace = /*#__PURE__*/_interopNamespaceDefault(reactI18next);
11
34
 
12
35
  /**
13
36
  * Sets up a mock implementation for HTML Canvas API in testing environments.
@@ -488,8 +511,74 @@ const setupTimeAndLanguage = () => {
488
511
  * setupTranslations();
489
512
  */
490
513
  const setupTranslations = () => {
491
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
492
- require("./setupTranslationsImpl").setupTranslations();
514
+ const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
515
+ const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
516
+ const renderNodes = (reactNodes) => {
517
+ if (typeof reactNodes === "string") {
518
+ return reactNodes;
519
+ }
520
+ return Object.keys(reactNodes).map((key, i) => {
521
+ const child = reactNodes[key];
522
+ const isElement = react$1.isValidElement(child);
523
+ if (typeof child === "string") {
524
+ return child;
525
+ }
526
+ if (hasChildren(child)) {
527
+ const inner = renderNodes(getChildren(child));
528
+ return react$1.cloneElement(child, { ...child.props, key: i }, inner);
529
+ }
530
+ if (typeof child === "object" && !isElement) {
531
+ return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
532
+ }
533
+ return child;
534
+ });
535
+ };
536
+ const i18n = { language: "en", exists: () => true };
537
+ const useMock = [
538
+ (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
539
+ i18n,
540
+ ];
541
+ useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
542
+ useMock.i18n = i18n;
543
+ const useTranslation = () => useMock;
544
+ const Trans = ({ i18nKey, components, children }) => {
545
+ const result = [];
546
+ result.push(renderNodes([i18nKey]));
547
+ if (Array.isArray(children)) {
548
+ result.push(...renderNodes(children));
549
+ }
550
+ else if (children && "toArray" in children) {
551
+ result.push(...renderNodes(children.toArray()));
552
+ }
553
+ else {
554
+ result.push(...renderNodes([children]));
555
+ }
556
+ if (components) {
557
+ result.push(...Object.keys(components).map(key => jsxRuntime.jsx("span", { children: components[key] }, key)));
558
+ }
559
+ return jsxRuntime.jsx(jsxRuntime.Fragment, { children: result });
560
+ };
561
+ const Translation = ({ children }) => children((k) => k, { i18n });
562
+ jest.doMock("react-i18next", () => {
563
+ return {
564
+ // this mock makes sure any components using the translate HoC receive the t function as a prop
565
+ Trans,
566
+ Translation,
567
+ useTranslation,
568
+ // mock if needed
569
+ I18nextProvider: reactI18next__namespace.I18nextProvider,
570
+ initReactI18next: reactI18next__namespace.initReactI18next,
571
+ setDefaults: reactI18next__namespace.setDefaults,
572
+ getDefaults: reactI18next__namespace.getDefaults,
573
+ setI18n: reactI18next__namespace.setI18n,
574
+ getI18n: reactI18next__namespace.getI18n,
575
+ };
576
+ });
577
+ jest.doMock("@trackunit/i18n-library-translation", () => ({
578
+ ...jest.requireActual("@trackunit/i18n-library-translation"),
579
+ NamespaceTrans: (props) => jsxRuntime.jsx(Trans, { ...props }),
580
+ useNamespaceTranslation: useTranslation,
581
+ }));
493
582
  };
494
583
 
495
584
  /**
@@ -509,8 +598,8 @@ const setupTranslations = () => {
509
598
  * setupWebStreams();
510
599
  */
511
600
  const setupWebStreams = () => {
512
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
513
- require("./setupWebStreamsImpl").setupWebStreams();
601
+ global.TransformStream = webStreamsPolyfill.TransformStream;
602
+ global.WritableStream = webStreamsPolyfill.WritableStream;
514
603
  };
515
604
 
516
605
  /**
package/index.esm.js CHANGED
@@ -1,11 +1,15 @@
1
1
  import failOnConsole from 'jest-fail-on-console';
2
- import { jsx } from 'react/jsx-runtime';
2
+ import { jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { APILoadingStatus } from '@vis.gl/react-google-maps';
4
4
  import { initialize } from '@googlemaps/jest-mocks';
5
+ import '@okta/okta-react';
5
6
  import '@testing-library/jest-dom';
6
7
  import { cleanup, act } from '@testing-library/react';
7
8
  import { Temporal } from '@js-temporal/polyfill';
8
9
  import { Globals } from '@react-spring/web';
10
+ import { isValidElement, cloneElement } from 'react';
11
+ import * as reactI18next from 'react-i18next';
12
+ import { TransformStream, WritableStream } from 'web-streams-polyfill';
9
13
 
10
14
  /**
11
15
  * Sets up a mock implementation for HTML Canvas API in testing environments.
@@ -486,8 +490,74 @@ const setupTimeAndLanguage = () => {
486
490
  * setupTranslations();
487
491
  */
488
492
  const setupTranslations = () => {
489
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
490
- require("./setupTranslationsImpl").setupTranslations();
493
+ const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
494
+ const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
495
+ const renderNodes = (reactNodes) => {
496
+ if (typeof reactNodes === "string") {
497
+ return reactNodes;
498
+ }
499
+ return Object.keys(reactNodes).map((key, i) => {
500
+ const child = reactNodes[key];
501
+ const isElement = isValidElement(child);
502
+ if (typeof child === "string") {
503
+ return child;
504
+ }
505
+ if (hasChildren(child)) {
506
+ const inner = renderNodes(getChildren(child));
507
+ return cloneElement(child, { ...child.props, key: i }, inner);
508
+ }
509
+ if (typeof child === "object" && !isElement) {
510
+ return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
511
+ }
512
+ return child;
513
+ });
514
+ };
515
+ const i18n = { language: "en", exists: () => true };
516
+ const useMock = [
517
+ (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
518
+ i18n,
519
+ ];
520
+ useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
521
+ useMock.i18n = i18n;
522
+ const useTranslation = () => useMock;
523
+ const Trans = ({ i18nKey, components, children }) => {
524
+ const result = [];
525
+ result.push(renderNodes([i18nKey]));
526
+ if (Array.isArray(children)) {
527
+ result.push(...renderNodes(children));
528
+ }
529
+ else if (children && "toArray" in children) {
530
+ result.push(...renderNodes(children.toArray()));
531
+ }
532
+ else {
533
+ result.push(...renderNodes([children]));
534
+ }
535
+ if (components) {
536
+ result.push(...Object.keys(components).map(key => jsx("span", { children: components[key] }, key)));
537
+ }
538
+ return jsx(Fragment, { children: result });
539
+ };
540
+ const Translation = ({ children }) => children((k) => k, { i18n });
541
+ jest.doMock("react-i18next", () => {
542
+ return {
543
+ // this mock makes sure any components using the translate HoC receive the t function as a prop
544
+ Trans,
545
+ Translation,
546
+ useTranslation,
547
+ // mock if needed
548
+ I18nextProvider: reactI18next.I18nextProvider,
549
+ initReactI18next: reactI18next.initReactI18next,
550
+ setDefaults: reactI18next.setDefaults,
551
+ getDefaults: reactI18next.getDefaults,
552
+ setI18n: reactI18next.setI18n,
553
+ getI18n: reactI18next.getI18n,
554
+ };
555
+ });
556
+ jest.doMock("@trackunit/i18n-library-translation", () => ({
557
+ ...jest.requireActual("@trackunit/i18n-library-translation"),
558
+ NamespaceTrans: (props) => jsx(Trans, { ...props }),
559
+ useNamespaceTranslation: useTranslation,
560
+ }));
491
561
  };
492
562
 
493
563
  /**
@@ -507,8 +577,8 @@ const setupTranslations = () => {
507
577
  * setupWebStreams();
508
578
  */
509
579
  const setupWebStreams = () => {
510
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
511
- require("./setupWebStreamsImpl").setupWebStreams();
580
+ global.TransformStream = TransformStream;
581
+ global.WritableStream = WritableStream;
512
582
  };
513
583
 
514
584
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trackunit/react-test-setup",
3
3
  "description": "Test setup utilities for React applications",
4
- "version": "1.0.4",
4
+ "version": "1.0.6-alpha-0614a19af4e.0",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
7
7
  "engines": {
@@ -20,7 +20,8 @@
20
20
  "react": "19.0.0",
21
21
  "react-i18next": "^15.5.1",
22
22
  "react-virtualized-auto-sizer": "^1.0.20",
23
- "web-streams-polyfill": "^4.1.0"
23
+ "web-streams-polyfill": "^4.1.0",
24
+ "@okta/okta-react": "^6.9.0"
24
25
  },
25
26
  "module": "./index.esm.js",
26
27
  "main": "./index.cjs.js",
@@ -1,3 +1,4 @@
1
+ import "@okta/okta-react";
1
2
  import "@testing-library/jest-dom";
2
3
  /**
3
4
  * Sets up React Testing Library and Okta authentication mocks for testing.
@@ -1,18 +0,0 @@
1
- /**
2
- * Implementation of translation mocks for testing environments.
3
- *
4
- * This function creates detailed mock implementations for react-i18next and
5
- * Trackunit i18n library translation utilities. The mocks are designed to:
6
- *
7
- * 1. Return translation keys as the translated strings (with any provided props)
8
- * 2. Render components within Trans components by preserving their React structure
9
- * 3. Provide a simplified i18n object with expected properties
10
- * 4. Handle nested components and rendering flows without complex translation logic
11
- *
12
- * These mocks allow components that use internationalization to be tested without
13
- * requiring actual translation files or i18n initialization, simplifying test setup
14
- * while preserving component rendering behavior.
15
- *
16
- * @internal
17
- */
18
- export declare const setupTranslations: () => void;
@@ -1,16 +0,0 @@
1
- /**
2
- * Implementation for Web Streams API polyfills in testing environments.
3
- *
4
- * This function adds the TransformStream and WritableStream implementations from
5
- * web-streams-polyfill to the global object, making them available to code running
6
- * in the Jest/JSDOM environment which may not have native implementations of these APIs.
7
- *
8
- * These polyfills are essential for testing code that uses modern streaming features,
9
- * particularly for scenarios involving:
10
- * - Data processing pipelines
11
- * - Chunk-by-chunk text or binary processing
12
- * - Streaming responses from APIs
13
- *
14
- * @internal
15
- */
16
- export declare const setupWebStreams: () => void;