@trackunit/react-test-setup 1.0.18 → 1.0.19-alpha-169add733bd.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,34 @@ 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 util = require('util');
|
|
13
|
+
var react$1 = require('react');
|
|
14
|
+
var reactI18next = require('react-i18next');
|
|
15
|
+
var webStreamsPolyfill = require('web-streams-polyfill');
|
|
16
|
+
|
|
17
|
+
function _interopNamespaceDefault(e) {
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n.default = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var reactI18next__namespace = /*#__PURE__*/_interopNamespaceDefault(reactI18next);
|
|
11
35
|
|
|
12
36
|
/**
|
|
13
37
|
* Sets up a mock implementation for HTML Canvas API in testing environments.
|
|
@@ -470,10 +494,14 @@ const setupTimeAndLanguage = () => {
|
|
|
470
494
|
};
|
|
471
495
|
};
|
|
472
496
|
|
|
497
|
+
if (typeof global !== "undefined") {
|
|
498
|
+
global.TextEncoder = global.TextEncoder || util.TextEncoder;
|
|
499
|
+
global.TextDecoder = global.TextDecoder || util.TextDecoder;
|
|
500
|
+
}
|
|
473
501
|
/**
|
|
474
502
|
* Sets up internationalization and translation mocks for testing environments.
|
|
475
503
|
*
|
|
476
|
-
* This function
|
|
504
|
+
* This function configures
|
|
477
505
|
* mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
478
506
|
* simple mock implementations that return the key string as the translation, which allows
|
|
479
507
|
* for testing internationalized components without the complexity of actual translations.
|
|
@@ -488,8 +516,74 @@ const setupTimeAndLanguage = () => {
|
|
|
488
516
|
* setupTranslations();
|
|
489
517
|
*/
|
|
490
518
|
const setupTranslations = () => {
|
|
491
|
-
|
|
492
|
-
|
|
519
|
+
const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
|
|
520
|
+
const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
|
|
521
|
+
const renderNodes = (reactNodes) => {
|
|
522
|
+
if (typeof reactNodes === "string") {
|
|
523
|
+
return reactNodes;
|
|
524
|
+
}
|
|
525
|
+
return Object.keys(reactNodes).map((key, i) => {
|
|
526
|
+
const child = reactNodes[key];
|
|
527
|
+
const isElement = react$1.isValidElement(child);
|
|
528
|
+
if (typeof child === "string") {
|
|
529
|
+
return child;
|
|
530
|
+
}
|
|
531
|
+
if (hasChildren(child)) {
|
|
532
|
+
const inner = renderNodes(getChildren(child));
|
|
533
|
+
return react$1.cloneElement(child, { ...child.props, key: i }, inner);
|
|
534
|
+
}
|
|
535
|
+
if (typeof child === "object" && !isElement) {
|
|
536
|
+
return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
|
|
537
|
+
}
|
|
538
|
+
return child;
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
const i18n = { language: "en", exists: () => true };
|
|
542
|
+
const useMock = [
|
|
543
|
+
(k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
|
|
544
|
+
i18n,
|
|
545
|
+
];
|
|
546
|
+
useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
|
|
547
|
+
useMock.i18n = i18n;
|
|
548
|
+
const useTranslation = () => useMock;
|
|
549
|
+
const Trans = ({ i18nKey, components, children }) => {
|
|
550
|
+
const result = [];
|
|
551
|
+
result.push(renderNodes([i18nKey]));
|
|
552
|
+
if (Array.isArray(children)) {
|
|
553
|
+
result.push(...renderNodes(children));
|
|
554
|
+
}
|
|
555
|
+
else if (children && "toArray" in children) {
|
|
556
|
+
result.push(...renderNodes(children.toArray()));
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
result.push(...renderNodes([children]));
|
|
560
|
+
}
|
|
561
|
+
if (components) {
|
|
562
|
+
result.push(...Object.keys(components).map(key => jsxRuntime.jsx("span", { children: components[key] }, key)));
|
|
563
|
+
}
|
|
564
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: result });
|
|
565
|
+
};
|
|
566
|
+
const Translation = ({ children }) => children((k) => k, { i18n });
|
|
567
|
+
jest.doMock("react-i18next", () => {
|
|
568
|
+
return {
|
|
569
|
+
// this mock makes sure any components using the translate HoC receive the t function as a prop
|
|
570
|
+
Trans,
|
|
571
|
+
Translation,
|
|
572
|
+
useTranslation,
|
|
573
|
+
// mock if needed
|
|
574
|
+
I18nextProvider: reactI18next__namespace.I18nextProvider,
|
|
575
|
+
initReactI18next: reactI18next__namespace.initReactI18next,
|
|
576
|
+
setDefaults: reactI18next__namespace.setDefaults,
|
|
577
|
+
getDefaults: reactI18next__namespace.getDefaults,
|
|
578
|
+
setI18n: reactI18next__namespace.setI18n,
|
|
579
|
+
getI18n: reactI18next__namespace.getI18n,
|
|
580
|
+
};
|
|
581
|
+
});
|
|
582
|
+
jest.doMock("@trackunit/i18n-library-translation", () => ({
|
|
583
|
+
...jest.requireActual("@trackunit/i18n-library-translation"),
|
|
584
|
+
NamespaceTrans: (props) => jsxRuntime.jsx(Trans, { ...props }),
|
|
585
|
+
useNamespaceTranslation: useTranslation,
|
|
586
|
+
}));
|
|
493
587
|
};
|
|
494
588
|
|
|
495
589
|
/**
|
|
@@ -509,8 +603,8 @@ const setupTranslations = () => {
|
|
|
509
603
|
* setupWebStreams();
|
|
510
604
|
*/
|
|
511
605
|
const setupWebStreams = () => {
|
|
512
|
-
|
|
513
|
-
|
|
606
|
+
global.TransformStream = webStreamsPolyfill.TransformStream;
|
|
607
|
+
global.WritableStream = webStreamsPolyfill.WritableStream;
|
|
514
608
|
};
|
|
515
609
|
|
|
516
610
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
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 { TextEncoder, TextDecoder } from 'util';
|
|
11
|
+
import { isValidElement, cloneElement } from 'react';
|
|
12
|
+
import * as reactI18next from 'react-i18next';
|
|
13
|
+
import { TransformStream, WritableStream } from 'web-streams-polyfill';
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* Sets up a mock implementation for HTML Canvas API in testing environments.
|
|
@@ -468,10 +473,14 @@ const setupTimeAndLanguage = () => {
|
|
|
468
473
|
};
|
|
469
474
|
};
|
|
470
475
|
|
|
476
|
+
if (typeof global !== "undefined") {
|
|
477
|
+
global.TextEncoder = global.TextEncoder || TextEncoder;
|
|
478
|
+
global.TextDecoder = global.TextDecoder || TextDecoder;
|
|
479
|
+
}
|
|
471
480
|
/**
|
|
472
481
|
* Sets up internationalization and translation mocks for testing environments.
|
|
473
482
|
*
|
|
474
|
-
* This function
|
|
483
|
+
* This function configures
|
|
475
484
|
* mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
476
485
|
* simple mock implementations that return the key string as the translation, which allows
|
|
477
486
|
* for testing internationalized components without the complexity of actual translations.
|
|
@@ -486,8 +495,74 @@ const setupTimeAndLanguage = () => {
|
|
|
486
495
|
* setupTranslations();
|
|
487
496
|
*/
|
|
488
497
|
const setupTranslations = () => {
|
|
489
|
-
|
|
490
|
-
|
|
498
|
+
const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
|
|
499
|
+
const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
|
|
500
|
+
const renderNodes = (reactNodes) => {
|
|
501
|
+
if (typeof reactNodes === "string") {
|
|
502
|
+
return reactNodes;
|
|
503
|
+
}
|
|
504
|
+
return Object.keys(reactNodes).map((key, i) => {
|
|
505
|
+
const child = reactNodes[key];
|
|
506
|
+
const isElement = isValidElement(child);
|
|
507
|
+
if (typeof child === "string") {
|
|
508
|
+
return child;
|
|
509
|
+
}
|
|
510
|
+
if (hasChildren(child)) {
|
|
511
|
+
const inner = renderNodes(getChildren(child));
|
|
512
|
+
return cloneElement(child, { ...child.props, key: i }, inner);
|
|
513
|
+
}
|
|
514
|
+
if (typeof child === "object" && !isElement) {
|
|
515
|
+
return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
|
|
516
|
+
}
|
|
517
|
+
return child;
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
const i18n = { language: "en", exists: () => true };
|
|
521
|
+
const useMock = [
|
|
522
|
+
(k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
|
|
523
|
+
i18n,
|
|
524
|
+
];
|
|
525
|
+
useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
|
|
526
|
+
useMock.i18n = i18n;
|
|
527
|
+
const useTranslation = () => useMock;
|
|
528
|
+
const Trans = ({ i18nKey, components, children }) => {
|
|
529
|
+
const result = [];
|
|
530
|
+
result.push(renderNodes([i18nKey]));
|
|
531
|
+
if (Array.isArray(children)) {
|
|
532
|
+
result.push(...renderNodes(children));
|
|
533
|
+
}
|
|
534
|
+
else if (children && "toArray" in children) {
|
|
535
|
+
result.push(...renderNodes(children.toArray()));
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
result.push(...renderNodes([children]));
|
|
539
|
+
}
|
|
540
|
+
if (components) {
|
|
541
|
+
result.push(...Object.keys(components).map(key => jsx("span", { children: components[key] }, key)));
|
|
542
|
+
}
|
|
543
|
+
return jsx(Fragment, { children: result });
|
|
544
|
+
};
|
|
545
|
+
const Translation = ({ children }) => children((k) => k, { i18n });
|
|
546
|
+
jest.doMock("react-i18next", () => {
|
|
547
|
+
return {
|
|
548
|
+
// this mock makes sure any components using the translate HoC receive the t function as a prop
|
|
549
|
+
Trans,
|
|
550
|
+
Translation,
|
|
551
|
+
useTranslation,
|
|
552
|
+
// mock if needed
|
|
553
|
+
I18nextProvider: reactI18next.I18nextProvider,
|
|
554
|
+
initReactI18next: reactI18next.initReactI18next,
|
|
555
|
+
setDefaults: reactI18next.setDefaults,
|
|
556
|
+
getDefaults: reactI18next.getDefaults,
|
|
557
|
+
setI18n: reactI18next.setI18n,
|
|
558
|
+
getI18n: reactI18next.getI18n,
|
|
559
|
+
};
|
|
560
|
+
});
|
|
561
|
+
jest.doMock("@trackunit/i18n-library-translation", () => ({
|
|
562
|
+
...jest.requireActual("@trackunit/i18n-library-translation"),
|
|
563
|
+
NamespaceTrans: (props) => jsx(Trans, { ...props }),
|
|
564
|
+
useNamespaceTranslation: useTranslation,
|
|
565
|
+
}));
|
|
491
566
|
};
|
|
492
567
|
|
|
493
568
|
/**
|
|
@@ -507,8 +582,8 @@ const setupTranslations = () => {
|
|
|
507
582
|
* setupWebStreams();
|
|
508
583
|
*/
|
|
509
584
|
const setupWebStreams = () => {
|
|
510
|
-
|
|
511
|
-
|
|
585
|
+
global.TransformStream = TransformStream;
|
|
586
|
+
global.WritableStream = WritableStream;
|
|
512
587
|
};
|
|
513
588
|
|
|
514
589
|
/**
|
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
|
+
"version": "1.0.19-alpha-169add733bd.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,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sets up internationalization and translation mocks for testing environments.
|
|
3
3
|
*
|
|
4
|
-
* This function
|
|
4
|
+
* This function configures
|
|
5
5
|
* mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
6
6
|
* simple mock implementations that return the key string as the translation, which allows
|
|
7
7
|
* for testing internationalized components without the complexity of actual translations.
|
|
@@ -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;
|