1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-26 00:21:36 +01:00

Compare commits

..

9 Commits

Author SHA1 Message Date
Aleksandr Gumroian
1bb20e01c1 Merge branch 'add-customization-context' into 'dev'
Add CustomizationContext and custom hook

See merge request turris/reforis/foris-js!183
2022-12-22 15:35:39 +01:00
Aleksandr Gumroian
f2ae6c4d0a
Move contexts in a context folder 2022-12-22 15:35:22 +01:00
Aleksandr Gumroian
f382e743aa
Update caniuse-lite 2022-12-22 15:35:22 +01:00
Aleksandr Gumroian
d71f4a7967
Remove testUtils from .gitignore
Because the testUtils folder consists of useful utils for testing,
we want to track changes in these files.
2022-12-22 15:35:21 +01:00
Aleksandr Gumroian
aeabc0bf06
Add info about CustomizationContext to the docs 2022-12-22 15:35:21 +01:00
Aleksandr Gumroian
46fe75d3cf
Add tests for CustomizationContext 2022-12-22 15:35:20 +01:00
Aleksandr Gumroian
c469d8dfde
Add CustomizationContext and custom hook
As we want to share customization context between reForis & Plugins
2022-12-22 15:35:20 +01:00
Aleksandr Gumroian
f327428765
Add about endpoint to forisUrls 2022-12-22 15:35:19 +01:00
Aleksandr Gumroian
badb043554 Merge branch 'dev' into 'master'
Dev

See merge request turris/reforis/foris-js!206
2022-12-02 16:15:39 +01:00
16 changed files with 47 additions and 41 deletions

View File

@ -97,8 +97,6 @@ test-js-watch:
.PHONY: test-js-update-snapshots
test-js-update-snapshots:
npm test -- -u
test-js-watch:
npm test -- --watch
# Translations

26
package-lock.json generated
View File

@ -4874,14 +4874,20 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001309",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001309.tgz",
"integrity": "sha512-Pl8vfigmBXXq+/yUz1jUwULeq9xhMJznzdc/xwl4WclDAuebcTHVefpz8lE/bMI+UN7TOkSSe7B7RnZd6+dzjA==",
"version": "1.0.30001441",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001441.tgz",
"integrity": "sha512-OyxRR4Vof59I3yGWXws6i908EtGbMzVUi3ganaZQHmydk1iwDhRnvaPG2WaR0KcqrDFKrxVZHULT396LEPhXfg==",
"dev": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/browserslist"
}
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/browserslist"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
}
]
},
"node_modules/capture-exit": {
"version": "2.0.0",
@ -22831,9 +22837,9 @@
"dev": true
},
"caniuse-lite": {
"version": "1.0.30001309",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001309.tgz",
"integrity": "sha512-Pl8vfigmBXXq+/yUz1jUwULeq9xhMJznzdc/xwl4WclDAuebcTHVefpz8lE/bMI+UN7TOkSSe7B7RnZd6+dzjA==",
"version": "1.0.30001441",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001441.tgz",
"integrity": "sha512-OyxRR4Vof59I3yGWXws6i908EtGbMzVUi3ganaZQHmydk1iwDhRnvaPG2WaR0KcqrDFKrxVZHULT396LEPhXfg==",
"dev": true
},
"capture-exit": {

View File

@ -14,7 +14,7 @@ import { ForisURLs } from "../utils/forisUrls";
import { Button } from "../bootstrap/Button";
import { Modal, ModalHeader, ModalBody, ModalFooter } from "../bootstrap/Modal";
import { useAlert } from "../alertContext/AlertContext";
import { useAlert } from "../context/alertContext/AlertContext";
export function RebootButton(props) {
const [triggered, setTriggered] = useState(false);

View File

@ -9,7 +9,7 @@ import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import { Button } from "../../bootstrap/Button";
import { useAlert } from "../../alertContext/AlertContext";
import { useAlert } from "../../context/alertContext/AlertContext";
import { ALERT_TYPES } from "../../bootstrap/Alert";
import { useAPIPost } from "../../api/hooks";
import { API_STATE } from "../../api/utils";

View File

@ -8,8 +8,8 @@
import React, { useState, useContext, useCallback } from "react";
import PropTypes from "prop-types";
import { Alert, ALERT_TYPES } from "../bootstrap/Alert";
import { Portal } from "../utils/Portal";
import { Alert, ALERT_TYPES } from "../../bootstrap/Alert";
import { Portal } from "../../utils/Portal";
AlertContextProvider.propTypes = {
children: PropTypes.oneOfType([

View File

@ -8,10 +8,10 @@
import React, { useContext, useEffect } from "react";
import PropTypes from "prop-types";
import { useAPIGet } from "../api/hooks";
import { ForisURLs } from "../utils/forisUrls";
import { useAPIGet } from "../../api/hooks";
import { ForisURLs } from "../../utils/forisUrls";
import { Spinner } from "../bootstrap/Spinner";
import { Spinner } from "../../bootstrap/Spinner";
CustomizationContextProvider.propTypes = {
children: PropTypes.oneOfType([

View File

@ -7,7 +7,7 @@
import React from "react";
import { render, wait } from "customTestRender";
import { render, wait, getByText } from "customTestRender";
import mockAxios from "jest-mock-axios";
import {
@ -18,39 +18,35 @@ import {
const CUSTOM = "Description / component for customized reForis (Shield)";
const ORIGINAL = "Description / component for original reForis (other devices)";
function CustomizationTest() {
const isCustomized = useCustomizationContext();
const CustomizationTest = () => {
const { isCustomized } = useCustomizationContext();
return <p>{isCustomized ? CUSTOM : ORIGINAL}</p>;
}
};
describe("CustomizationContext", () => {
let componentContainer;
it("should render component without customization", async () => {
const { container, getByText } = render(
beforeEach(() => {
const { container } = render(
<CustomizationContextProvider>
<CustomizationTest />
</CustomizationContextProvider>
);
componentContainer = container;
});
it("should render component without customization", async () => {
mockAxios.mockResponse({ data: {} });
await wait(() => getByText(ORIGINAL));
await wait(() => getByText(componentContainer, ORIGINAL));
expect(componentContainer).toMatchSnapshot();
});
it("should render customized component", async () => {
const { container, getByText } = render(
<CustomizationContextProvider>
<CustomizationTest />
</CustomizationContextProvider>
);
componentContainer = container;
mockAxios.mockResponse({ data: { customization: "shield" } });
await wait(() => getByText(CUSTOM));
await wait(() => getByText(componentContainer, CUSTOM));
expect(componentContainer).toMatchSnapshot();
});

View File

@ -13,7 +13,7 @@ import { ALERT_TYPES } from "../../bootstrap/Alert";
import { API_STATE } from "../../api/utils";
import { formFieldsSize } from "../../bootstrap/constants";
import { Spinner } from "../../bootstrap/Spinner";
import { useAlert } from "../../alertContext/AlertContext";
import { useAlert } from "../../context/alertContext/AlertContext";
import { useAPIPost } from "../../api/hooks";
import { useForisModule, useForm } from "../hooks";

View File

@ -90,10 +90,13 @@ export {
} from "./utils/validations";
// Alert context
export { AlertContextProvider, useAlert } from "./alertContext/AlertContext";
export {
AlertContextProvider,
useAlert,
} from "./context/alertContext/AlertContext";
// Customization context
export {
CustomizationContextProvider,
useCustomizationContext,
} from "./customizationContext/CustomizationContext";
} from "./context/customizationContext/CustomizationContext";

View File

@ -9,11 +9,12 @@ import React from "react";
window.CustomizationContext = React.createContext();
const deviceDetails = {};
const isCustomized = jest.fn();
function CustomizationContextMock({ children }) {
return (
<CustomizationContext.Provider value={isCustomized}>
<CustomizationContext.Provider value={(deviceDetails, isCustomized)}>
{children}
</CustomizationContext.Provider>
);

View File

@ -43,7 +43,7 @@ module.exports = {
},
{
name: "Alert Context",
components: ["src/alertContext/AlertContext.js"],
components: ["src/context/alertContext/AlertContext.js"],
exampleMode: "expand",
usageMode: "expand",
},
@ -53,7 +53,9 @@ module.exports = {
{
name: "Customization Context",
components: ["src/customizationContext/CustomizationContext.js"],
components: [
"src/context/customizationContext/CustomizationContext.js",
],
exampleMode: "expand",
usageMode: "expand",
},