mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-11-14 17:35:35 +01:00
Compare commits
8 Commits
1bb20e01c1
...
15f6cf6709
Author | SHA1 | Date | |
---|---|---|---|
|
15f6cf6709 | ||
|
3fc1388a9f | ||
|
2bbdda566c | ||
|
f12de3205f | ||
|
a971e8ce1a | ||
|
1297d8446c | ||
|
0791087d8f | ||
|
ce3d439005 |
2
Makefile
2
Makefile
|
@ -97,6 +97,8 @@ test-js-watch:
|
||||||
.PHONY: test-js-update-snapshots
|
.PHONY: test-js-update-snapshots
|
||||||
test-js-update-snapshots:
|
test-js-update-snapshots:
|
||||||
npm test -- -u
|
npm test -- -u
|
||||||
|
test-js-watch:
|
||||||
|
npm test -- --watch
|
||||||
|
|
||||||
|
|
||||||
# Translations
|
# Translations
|
||||||
|
|
26
package-lock.json
generated
26
package-lock.json
generated
|
@ -4874,20 +4874,14 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001441",
|
"version": "1.0.30001309",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001441.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001309.tgz",
|
||||||
"integrity": "sha512-OyxRR4Vof59I3yGWXws6i908EtGbMzVUi3ganaZQHmydk1iwDhRnvaPG2WaR0KcqrDFKrxVZHULT396LEPhXfg==",
|
"integrity": "sha512-Pl8vfigmBXXq+/yUz1jUwULeq9xhMJznzdc/xwl4WclDAuebcTHVefpz8lE/bMI+UN7TOkSSe7B7RnZd6+dzjA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": {
|
||||||
{
|
"type": "opencollective",
|
||||||
"type": "opencollective",
|
"url": "https://opencollective.com/browserslist"
|
||||||
"url": "https://opencollective.com/browserslist"
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "tidelift",
|
|
||||||
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"node_modules/capture-exit": {
|
"node_modules/capture-exit": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
|
@ -22837,9 +22831,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"caniuse-lite": {
|
"caniuse-lite": {
|
||||||
"version": "1.0.30001441",
|
"version": "1.0.30001309",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001441.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001309.tgz",
|
||||||
"integrity": "sha512-OyxRR4Vof59I3yGWXws6i908EtGbMzVUi3ganaZQHmydk1iwDhRnvaPG2WaR0KcqrDFKrxVZHULT396LEPhXfg==",
|
"integrity": "sha512-Pl8vfigmBXXq+/yUz1jUwULeq9xhMJznzdc/xwl4WclDAuebcTHVefpz8lE/bMI+UN7TOkSSe7B7RnZd6+dzjA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"capture-exit": {
|
"capture-exit": {
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
import React, { useState, useContext, useCallback } from "react";
|
import React, { useState, useContext, useCallback } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
import { Alert, ALERT_TYPES } from "../../bootstrap/Alert";
|
import { Alert, ALERT_TYPES } from "../bootstrap/Alert";
|
||||||
import { Portal } from "../../utils/Portal";
|
import { Portal } from "../utils/Portal";
|
||||||
|
|
||||||
AlertContextProvider.propTypes = {
|
AlertContextProvider.propTypes = {
|
||||||
children: PropTypes.oneOfType([
|
children: PropTypes.oneOfType([
|
|
@ -14,7 +14,7 @@ import { ForisURLs } from "../utils/forisUrls";
|
||||||
|
|
||||||
import { Button } from "../bootstrap/Button";
|
import { Button } from "../bootstrap/Button";
|
||||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from "../bootstrap/Modal";
|
import { Modal, ModalHeader, ModalBody, ModalFooter } from "../bootstrap/Modal";
|
||||||
import { useAlert } from "../context/alertContext/AlertContext";
|
import { useAlert } from "../alertContext/AlertContext";
|
||||||
|
|
||||||
export function RebootButton(props) {
|
export function RebootButton(props) {
|
||||||
const [triggered, setTriggered] = useState(false);
|
const [triggered, setTriggered] = useState(false);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import React, { useEffect, useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
import { Button } from "../../bootstrap/Button";
|
import { Button } from "../../bootstrap/Button";
|
||||||
import { useAlert } from "../../context/alertContext/AlertContext";
|
import { useAlert } from "../../alertContext/AlertContext";
|
||||||
import { ALERT_TYPES } from "../../bootstrap/Alert";
|
import { ALERT_TYPES } from "../../bootstrap/Alert";
|
||||||
import { useAPIPost } from "../../api/hooks";
|
import { useAPIPost } from "../../api/hooks";
|
||||||
import { API_STATE } from "../../api/utils";
|
import { API_STATE } from "../../api/utils";
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
import React, { useContext, useEffect } from "react";
|
import React, { useContext, useEffect } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
import { useAPIGet } from "../../api/hooks";
|
import { useAPIGet } from "../api/hooks";
|
||||||
import { ForisURLs } from "../../utils/forisUrls";
|
import { ForisURLs } from "../utils/forisUrls";
|
||||||
|
|
||||||
import { Spinner } from "../../bootstrap/Spinner";
|
import { Spinner } from "../bootstrap/Spinner";
|
||||||
|
|
||||||
CustomizationContextProvider.propTypes = {
|
CustomizationContextProvider.propTypes = {
|
||||||
children: PropTypes.oneOfType([
|
children: PropTypes.oneOfType([
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { render, wait, getByText } from "customTestRender";
|
import { render, wait } from "customTestRender";
|
||||||
import mockAxios from "jest-mock-axios";
|
import mockAxios from "jest-mock-axios";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -18,35 +18,39 @@ import {
|
||||||
const CUSTOM = "Description / component for customized reForis (Shield)";
|
const CUSTOM = "Description / component for customized reForis (Shield)";
|
||||||
const ORIGINAL = "Description / component for original reForis (other devices)";
|
const ORIGINAL = "Description / component for original reForis (other devices)";
|
||||||
|
|
||||||
const CustomizationTest = () => {
|
function CustomizationTest() {
|
||||||
const { isCustomized } = useCustomizationContext();
|
const isCustomized = useCustomizationContext();
|
||||||
|
|
||||||
return <p>{isCustomized ? CUSTOM : ORIGINAL}</p>;
|
return <p>{isCustomized ? CUSTOM : ORIGINAL}</p>;
|
||||||
};
|
}
|
||||||
|
|
||||||
describe("CustomizationContext", () => {
|
describe("CustomizationContext", () => {
|
||||||
let componentContainer;
|
let componentContainer;
|
||||||
beforeEach(() => {
|
|
||||||
const { container } = render(
|
it("should render component without customization", async () => {
|
||||||
|
const { container, getByText } = render(
|
||||||
<CustomizationContextProvider>
|
<CustomizationContextProvider>
|
||||||
<CustomizationTest />
|
<CustomizationTest />
|
||||||
</CustomizationContextProvider>
|
</CustomizationContextProvider>
|
||||||
);
|
);
|
||||||
componentContainer = container;
|
componentContainer = container;
|
||||||
});
|
|
||||||
|
|
||||||
it("should render component without customization", async () => {
|
|
||||||
mockAxios.mockResponse({ data: {} });
|
mockAxios.mockResponse({ data: {} });
|
||||||
|
await wait(() => getByText(ORIGINAL));
|
||||||
await wait(() => getByText(componentContainer, ORIGINAL));
|
|
||||||
|
|
||||||
expect(componentContainer).toMatchSnapshot();
|
expect(componentContainer).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render customized component", async () => {
|
it("should render customized component", async () => {
|
||||||
mockAxios.mockResponse({ data: { customization: "shield" } });
|
const { container, getByText } = render(
|
||||||
|
<CustomizationContextProvider>
|
||||||
|
<CustomizationTest />
|
||||||
|
</CustomizationContextProvider>
|
||||||
|
);
|
||||||
|
componentContainer = container;
|
||||||
|
|
||||||
await wait(() => getByText(componentContainer, CUSTOM));
|
mockAxios.mockResponse({ data: { customization: "shield" } });
|
||||||
|
await wait(() => getByText(CUSTOM));
|
||||||
|
|
||||||
expect(componentContainer).toMatchSnapshot();
|
expect(componentContainer).toMatchSnapshot();
|
||||||
});
|
});
|
|
@ -13,7 +13,7 @@ import { ALERT_TYPES } from "../../bootstrap/Alert";
|
||||||
import { API_STATE } from "../../api/utils";
|
import { API_STATE } from "../../api/utils";
|
||||||
import { formFieldsSize } from "../../bootstrap/constants";
|
import { formFieldsSize } from "../../bootstrap/constants";
|
||||||
import { Spinner } from "../../bootstrap/Spinner";
|
import { Spinner } from "../../bootstrap/Spinner";
|
||||||
import { useAlert } from "../../context/alertContext/AlertContext";
|
import { useAlert } from "../../alertContext/AlertContext";
|
||||||
import { useAPIPost } from "../../api/hooks";
|
import { useAPIPost } from "../../api/hooks";
|
||||||
|
|
||||||
import { useForisModule, useForm } from "../hooks";
|
import { useForisModule, useForm } from "../hooks";
|
||||||
|
|
|
@ -90,13 +90,10 @@ export {
|
||||||
} from "./utils/validations";
|
} from "./utils/validations";
|
||||||
|
|
||||||
// Alert context
|
// Alert context
|
||||||
export {
|
export { AlertContextProvider, useAlert } from "./alertContext/AlertContext";
|
||||||
AlertContextProvider,
|
|
||||||
useAlert,
|
|
||||||
} from "./context/alertContext/AlertContext";
|
|
||||||
|
|
||||||
// Customization context
|
// Customization context
|
||||||
export {
|
export {
|
||||||
CustomizationContextProvider,
|
CustomizationContextProvider,
|
||||||
useCustomizationContext,
|
useCustomizationContext,
|
||||||
} from "./context/customizationContext/CustomizationContext";
|
} from "./customizationContext/CustomizationContext";
|
||||||
|
|
|
@ -9,12 +9,11 @@ import React from "react";
|
||||||
|
|
||||||
window.CustomizationContext = React.createContext();
|
window.CustomizationContext = React.createContext();
|
||||||
|
|
||||||
const deviceDetails = {};
|
|
||||||
const isCustomized = jest.fn();
|
const isCustomized = jest.fn();
|
||||||
|
|
||||||
function CustomizationContextMock({ children }) {
|
function CustomizationContextMock({ children }) {
|
||||||
return (
|
return (
|
||||||
<CustomizationContext.Provider value={(deviceDetails, isCustomized)}>
|
<CustomizationContext.Provider value={isCustomized}>
|
||||||
{children}
|
{children}
|
||||||
</CustomizationContext.Provider>
|
</CustomizationContext.Provider>
|
||||||
);
|
);
|
||||||
|
|
|
@ -43,7 +43,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Alert Context",
|
name: "Alert Context",
|
||||||
components: ["src/context/alertContext/AlertContext.js"],
|
components: ["src/alertContext/AlertContext.js"],
|
||||||
exampleMode: "expand",
|
exampleMode: "expand",
|
||||||
usageMode: "expand",
|
usageMode: "expand",
|
||||||
},
|
},
|
||||||
|
@ -53,9 +53,7 @@ module.exports = {
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Customization Context",
|
name: "Customization Context",
|
||||||
components: [
|
components: ["src/customizationContext/CustomizationContext.js"],
|
||||||
"src/context/customizationContext/CustomizationContext.js",
|
|
||||||
],
|
|
||||||
exampleMode: "expand",
|
exampleMode: "expand",
|
||||||
usageMode: "expand",
|
usageMode: "expand",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user