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 { exportStateMiddleware } from '../src/middlewares/exportState';
|
2024-06-12 16:18:46 +03:00
|
|
|
import { coreReducers } 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';
|
2024-06-12 16:18:46 +03:00
|
|
|
import { combineReducers } from 'redux';
|
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(
|
2024-06-12 16:18:46 +03:00
|
|
|
combineReducers(coreReducers),
|
|
|
|
applyMiddleware(exportStateMiddleware),
|
2022-01-10 18:41:53 +03:00
|
|
|
);
|
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 />
|
2023-07-12 21:03:20 +03:00
|
|
|
</Provider>,
|
2019-01-03 17:14:25 +03:00
|
|
|
);
|
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 />
|
2023-07-12 21:03:20 +03:00
|
|
|
</Provider>,
|
2021-10-22 17:49:53 +03:00
|
|
|
);
|
|
|
|
const actionList = screen.getByTestId('actionList');
|
2023-08-19 02:52:43 +03:00
|
|
|
expect(within(actionList).queryByRole('button')).not.toBeInTheDocument();
|
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',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|