1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-06-16 13:46:16 +02:00

Global alert

This commit is contained in:
Maciej Lenartowicz
2019-10-30 16:06:53 +00:00
parent 22b2bc9c09
commit 0915d477fe
15 changed files with 168 additions and 43 deletions

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
*/
import React from "react";
import { AlertContext } from "../alertContext/AlertContext";
const mockSetAlert = jest.fn();
const mockDismissAlert = jest.fn();
function AlertContextMock({ children }) {
return (
<AlertContext.Provider value={[mockSetAlert, mockDismissAlert]}>
{ children }
</AlertContext.Provider>
);
}
export { AlertContextMock, mockSetAlert, mockDismissAlert };

View File

@ -7,31 +7,37 @@
/* eslint import/export: "off" */
import React from 'react';
import PropTypes from 'prop-types';
import {UIDReset} from 'react-uid';
import {StaticRouter} from 'react-router';
import {render} from '@testing-library/react'
import React from "react";
import { UIDReset } from "react-uid";
import { StaticRouter } from "react-router";
import { render } from "@testing-library/react";
import PropTypes from "prop-types";
import { AlertContextMock } from "alertContextMock";
Wrapper.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
])
PropTypes.node,
]),
};
function Wrapper({children}) {
return <StaticRouter>
<UIDReset>
{children}
</UIDReset>
</StaticRouter>
function Wrapper({ children }) {
return (
<AlertContextMock>
<StaticRouter>
<UIDReset>
{children}
</UIDReset>
</StaticRouter>
</AlertContextMock>
);
}
const customTestRender = (ui, options) => render(ui, {wrapper: Wrapper, ...options});
const customTestRender = (ui, options) => render(ui, { wrapper: Wrapper, ...options });
// re-export everything
export * from '@testing-library/react'
export * from "@testing-library/react";
// override render method
export {customTestRender as render}
export { customTestRender as render };

12
src/testUtils/network.js Normal file
View File

@ -0,0 +1,12 @@
/*
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
*/
import mockAxios from 'jest-mock-axios';
export function mockJSONError(data) {
mockAxios.mockError({ response: { data, headers: { "content-type": "application/json" } } });
}

View File

@ -15,12 +15,15 @@ global.afterEach(() => {
// Mock babel (gettext)
global._ = str => str;
global.ngettext = str => str;
global.babel = {format: (str) => str};
global.ForisTranslations = {};
// Mock web sockets
window.WebSocket = jest.fn();
// Mock scrollIntoView
global.HTMLElement.prototype.scrollIntoView = () => {
};
global.HTMLElement.prototype.scrollIntoView = () => {};
jest.doMock('moment', () => {
moment.tz.setDefault('UTC');