2021-10-22 17:49:53 +03:00
|
|
|
import React from 'react';
|
2019-01-03 17:14:25 +03:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { createStore, applyMiddleware } from 'redux';
|
2021-10-22 17:49:53 +03:00
|
|
|
import { render, screen, within } from '@testing-library/react';
|
2020-12-22 20:02:14 +03:00
|
|
|
import App from '../src/containers/App';
|
2022-01-10 18:41:53 +03:00
|
|
|
import { api } from '../src/middlewares/api';
|
|
|
|
import { exportStateMiddleware } from '../src/middlewares/exportState';
|
|
|
|
import { rootReducer } from '../src/reducers';
|
2020-12-22 20:02:14 +03:00
|
|
|
import { DATA_TYPE_KEY } from '../src/constants/dataTypes';
|
2022-01-10 18:41:53 +03:00
|
|
|
import { stringifyJSON } from '../src/utils/stringifyJSON';
|
2019-01-03 23:43:56 +03:00
|
|
|
|
2021-11-06 20:28:35 +03:00
|
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
|
|
writable: true,
|
|
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: jest.fn(), // deprecated
|
|
|
|
removeListener: jest.fn(), // deprecated
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
2022-01-10 18:41:53 +03:00
|
|
|
const store = createStore(
|
|
|
|
rootReducer,
|
|
|
|
applyMiddleware(exportStateMiddleware, api)
|
|
|
|
);
|
2019-01-03 17:14:25 +03:00
|
|
|
|
|
|
|
describe('App container', () => {
|
2021-10-22 17:49:53 +03:00
|
|
|
it("should render inspector monitor's wrapper", () => {
|
|
|
|
render(
|
2019-01-03 17:14:25 +03:00
|
|
|
<Provider store={store}>
|
|
|
|
<App />
|
|
|
|
</Provider>
|
|
|
|
);
|
2021-10-22 17:49:53 +03:00
|
|
|
expect(screen.getByTestId('inspector')).toBeDefined();
|
2019-01-03 17:14:25 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain an empty action list', () => {
|
2021-10-22 17:49:53 +03:00
|
|
|
render(
|
|
|
|
<Provider store={store}>
|
|
|
|
<App />
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
const actionList = screen.getByTestId('actionList');
|
2019-01-03 17:14:25 +03:00
|
|
|
expect(
|
2021-10-22 17:49:53 +03:00
|
|
|
within(actionList).getByTestId('actionListRows')
|
|
|
|
).toBeEmptyDOMElement();
|
2019-01-03 17:14:25 +03:00
|
|
|
});
|
|
|
|
});
|
2020-09-05 01:28:36 +03:00
|
|
|
|
|
|
|
describe('stringifyJSON', () => {
|
|
|
|
it('should not mutate the source object', () => {
|
|
|
|
const src = {
|
|
|
|
isTest: true,
|
|
|
|
[DATA_TYPE_KEY]: 'Test',
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
data: {
|
|
|
|
isTest: true,
|
|
|
|
},
|
|
|
|
__serializedType__: 'Test',
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(stringifyJSON(src, true)).toEqual(JSON.stringify(result));
|
|
|
|
expect(src).toEqual({
|
|
|
|
isTest: true,
|
|
|
|
[DATA_TYPE_KEY]: 'Test',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|