mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-06-16 13:46:16 +02:00
Don't use default exports.
This commit is contained in:
@ -7,9 +7,9 @@
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import {act, fireEvent, render, waitForElement} from 'customTestRender';
|
||||
import { act, fireEvent, render, waitForElement } from 'customTestRender';
|
||||
import mockAxios from 'jest-mock-axios';
|
||||
import ForisForm from "../components/ForisForm";
|
||||
import { ForisForm } from "../components/ForisForm";
|
||||
|
||||
|
||||
// It's possible to unittest each hooks via react-hooks-testing-library.
|
||||
|
@ -10,75 +10,129 @@ import {
|
||||
validateDUID,
|
||||
validateIPv4Address,
|
||||
validateIPv6Address,
|
||||
validateIPv6Prefix, validateMAC
|
||||
} from 'validations';
|
||||
validateIPv6Prefix,
|
||||
validateMAC
|
||||
} from "validations";
|
||||
|
||||
describe('Validation functions', () => {
|
||||
it('validateIPv4Address valid', () => {
|
||||
expect(validateIPv4Address('192.168.1.1')).toBe(undefined);
|
||||
expect(validateIPv4Address('1.1.1.1')).toBe(undefined);
|
||||
expect(validateIPv4Address('0.0.0.0')).toBe(undefined);
|
||||
describe("Validation functions", () => {
|
||||
it("validateIPv4Address valid", () => {
|
||||
expect(validateIPv4Address("192.168.1.1"))
|
||||
.toBe(undefined);
|
||||
expect(validateIPv4Address("1.1.1.1"))
|
||||
.toBe(undefined);
|
||||
expect(validateIPv4Address("0.0.0.0"))
|
||||
.toBe(undefined);
|
||||
});
|
||||
it('validateIPv4Address invalid', () => {
|
||||
expect(validateIPv4Address('invalid')).not.toBe(undefined);
|
||||
expect(validateIPv4Address('192.256.1.1')).not.toBe(undefined);
|
||||
expect(validateIPv4Address('192.168.256.1')).not.toBe(undefined);
|
||||
expect(validateIPv4Address('192.168.1.256')).not.toBe(undefined);
|
||||
expect(validateIPv4Address('192.168.1.256')).not.toBe(undefined);
|
||||
it("validateIPv4Address invalid", () => {
|
||||
expect(validateIPv4Address("invalid"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv4Address("192.256.1.1"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv4Address("192.168.256.1"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv4Address("192.168.1.256"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv4Address("192.168.1.256"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
});
|
||||
|
||||
it('validateIPv6Address valid', () => {
|
||||
expect(validateIPv6Address('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(undefined);
|
||||
expect(validateIPv6Address('0:0:0:0:0:0:0:1')).toBe(undefined);
|
||||
expect(validateIPv6Address('::1')).toBe(undefined);
|
||||
expect(validateIPv6Address('::')).toBe(undefined);
|
||||
it("validateIPv6Address valid", () => {
|
||||
expect(validateIPv6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Address("0:0:0:0:0:0:0:1"))
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Address("::1"))
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Address("::"))
|
||||
.toBe(undefined);
|
||||
|
||||
});
|
||||
it('validateIPv6Address invalid', () => {
|
||||
expect(validateIPv6Address('invalid')).not.toBe(undefined);
|
||||
expect(validateIPv6Address('1.1.1.1')).not.toBe(undefined);
|
||||
expect(validateIPv6Address('1200::AB00:1234::2552:7777:1313')).not.toBe(undefined);
|
||||
expect(validateIPv6Address('1200:0000:AB00:1234:O000:2552:7777:1313')).not.toBe(undefined);
|
||||
it("validateIPv6Address invalid", () => {
|
||||
expect(validateIPv6Address("invalid"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Address("1.1.1.1"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Address("1200::AB00:1234::2552:7777:1313"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Address("1200:0000:AB00:1234:O000:2552:7777:1313"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
});
|
||||
|
||||
it('validateIPv6Prefix valid', () => {
|
||||
expect(validateIPv6Prefix('2002:0000::/16')).toBe(undefined);
|
||||
expect(validateIPv6Prefix('0::/0')).toBe(undefined);
|
||||
it("validateIPv6Prefix valid", () => {
|
||||
expect(validateIPv6Prefix("2002:0000::/16"))
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Prefix("0::/0"))
|
||||
.toBe(undefined);
|
||||
});
|
||||
it('validateIPv6Prefix invalid', () => {
|
||||
expect(validateIPv6Prefix('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).not.toBe(undefined);
|
||||
expect(validateIPv6Prefix('::1')).not.toBe(undefined);
|
||||
expect(validateIPv6Prefix('2002:0000::/999')).not.toBe(undefined);
|
||||
it("validateIPv6Prefix invalid", () => {
|
||||
expect(validateIPv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Prefix("::1"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateIPv6Prefix("2002:0000::/999"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
});
|
||||
|
||||
|
||||
it('validateDomain valid', () => {
|
||||
expect(validateDomain('example.com')).toBe(undefined);
|
||||
expect(validateDomain('one.two.three')).toBe(undefined);
|
||||
it("validateDomain valid", () => {
|
||||
expect(validateDomain("example.com"))
|
||||
.toBe(undefined);
|
||||
expect(validateDomain("one.two.three"))
|
||||
.toBe(undefined);
|
||||
});
|
||||
it('validateDomain invalid', () => {
|
||||
expect(validateDomain('test/')).not.toBe(undefined);
|
||||
expect(validateDomain('.')).not.toBe(undefined);
|
||||
it("validateDomain invalid", () => {
|
||||
expect(validateDomain("test/"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateDomain("."))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
});
|
||||
|
||||
it('validateDUID valid', () => {
|
||||
expect(validateDUID('abcdefAB')).toBe(undefined);
|
||||
expect(validateDUID('ABCDEF12')).toBe(undefined);
|
||||
expect(validateDUID('ABCDEF12AB')).toBe(undefined);
|
||||
it("validateDUID valid", () => {
|
||||
expect(validateDUID("abcdefAB"))
|
||||
.toBe(undefined);
|
||||
expect(validateDUID("ABCDEF12"))
|
||||
.toBe(undefined);
|
||||
expect(validateDUID("ABCDEF12AB"))
|
||||
.toBe(undefined);
|
||||
|
||||
});
|
||||
it('validateDUID invalid', () => {
|
||||
expect(validateDUID('gggggggg')).not.toBe(undefined);
|
||||
expect(validateDUID('abcdefABa')).not.toBe(undefined);
|
||||
it("validateDUID invalid", () => {
|
||||
expect(validateDUID("gggggggg"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateDUID("abcdefABa"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
});
|
||||
|
||||
it('validateMAC valid', () => {
|
||||
expect(validateMAC('00:D0:56:F2:B5:12')).toBe(undefined);
|
||||
expect(validateMAC('00:26:DD:14:C4:EE')).toBe(undefined);
|
||||
expect(validateMAC('06:00:00:00:00:00')).toBe(undefined);
|
||||
it("validateMAC valid", () => {
|
||||
expect(validateMAC("00:D0:56:F2:B5:12"))
|
||||
.toBe(undefined);
|
||||
expect(validateMAC("00:26:DD:14:C4:EE"))
|
||||
.toBe(undefined);
|
||||
expect(validateMAC("06:00:00:00:00:00"))
|
||||
.toBe(undefined);
|
||||
});
|
||||
it('validateMAC invalid', () => {
|
||||
expect(validateMAC('00:00:00:00:00:0G')).not.toBe(undefined);
|
||||
expect(validateMAC('06:00:00:00:00:00:00')).not.toBe(undefined);
|
||||
it("validateMAC invalid", () => {
|
||||
expect(validateMAC("00:00:00:00:00:0G"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
expect(validateMAC("06:00:00:00:00:00:00"))
|
||||
.not
|
||||
.toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
@ -57,7 +57,7 @@ ForisForm.defaultProps = {
|
||||
};
|
||||
|
||||
/** Serves as HOC for all foris forms components. */
|
||||
export default function ForisForm({
|
||||
export function ForisForm({
|
||||
ws,
|
||||
forisConfig,
|
||||
prepData,
|
||||
|
@ -8,7 +8,7 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import Button from "bootstrap/Button";
|
||||
import { Button } from "bootstrap/Button";
|
||||
|
||||
export const STATES = {
|
||||
READY: 1,
|
||||
@ -18,7 +18,8 @@ export const STATES = {
|
||||
|
||||
SubmitButton.propTypes = {
|
||||
disabled: PropTypes.bool,
|
||||
state: PropTypes.oneOf(Object.keys(STATES).map((key) => STATES[key])),
|
||||
state: PropTypes.oneOf(Object.keys(STATES)
|
||||
.map((key) => STATES[key])),
|
||||
};
|
||||
|
||||
export function SubmitButton({ disabled, state, ...props }) {
|
||||
|
@ -8,8 +8,8 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import Alert from "bootstrap/Alert";
|
||||
import Portal from "utils/Portal";
|
||||
import { Alert } from "bootstrap/Alert";
|
||||
import { Portal } from "utils/Portal";
|
||||
|
||||
SuccessAlert.propTypes = {
|
||||
onDismiss: PropTypes.func.isRequired,
|
||||
|
@ -9,7 +9,7 @@ import { useCallback, useEffect, useReducer } from "react";
|
||||
import update from "immutability-helper";
|
||||
|
||||
import { useAPIGet } from "api/hooks";
|
||||
import useWSForisModule from "webSockets/hooks";
|
||||
import { useWSForisModule } from "webSockets/hooks";
|
||||
|
||||
|
||||
const FORM_ACTIONS = {
|
||||
|
Reference in New Issue
Block a user