2020-10-26 15:18:23 +03:00
|
|
|
import { insertScript, listenMessage } from '../../utils/inject';
|
2022-10-10 20:05:28 +03:00
|
|
|
import '../../../src/pageScript';
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
describe('API', () => {
|
|
|
|
it('should get window.__REDUX_DEVTOOLS_EXTENSION__ function', () => {
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(typeof window.__REDUX_DEVTOOLS_EXTENSION__).toBe('function');
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should notify error', () => {
|
2020-12-19 23:01:09 +03:00
|
|
|
const mockFunc = jest.fn(() => {});
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.notifyErrors(mockFunc);
|
2020-10-26 15:18:23 +03:00
|
|
|
insertScript('hi()');
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(mockFunc.mock.calls.length).toBeGreaterThan(0);
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should open monitor', async () => {
|
|
|
|
let message = await listenMessage(() => {
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.open();
|
|
|
|
});
|
|
|
|
expect(message).toEqual({
|
|
|
|
source: '@devtools-page',
|
|
|
|
type: 'OPEN',
|
|
|
|
position: 'right',
|
|
|
|
});
|
|
|
|
|
|
|
|
message = await listenMessage(() => {
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.open('left');
|
|
|
|
});
|
|
|
|
expect(message).toEqual({
|
|
|
|
source: '@devtools-page',
|
|
|
|
type: 'OPEN',
|
|
|
|
position: 'left',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should send message', async () => {
|
|
|
|
let message = await listenMessage(() => {
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.send('hi');
|
|
|
|
});
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(message).toMatchObject({
|
2020-10-26 15:18:23 +03:00
|
|
|
type: 'ACTION',
|
|
|
|
payload: undefined,
|
|
|
|
instanceId: 1,
|
|
|
|
name: undefined,
|
|
|
|
source: '@devtools-page',
|
|
|
|
});
|
|
|
|
expect(message.action).toMatch(/{"action":{"type":"hi"},"timestamp":\d+}/);
|
|
|
|
|
|
|
|
message = await listenMessage(() => {
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.send(
|
|
|
|
{ type: 'hi' },
|
|
|
|
{ counter: 1 },
|
2023-07-12 21:03:20 +03:00
|
|
|
1,
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
});
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(message).toMatchObject({
|
2020-10-26 15:18:23 +03:00
|
|
|
type: 'ACTION',
|
|
|
|
payload: '{"counter":1}',
|
|
|
|
instanceId: 1,
|
|
|
|
name: undefined,
|
|
|
|
source: '@devtools-page',
|
|
|
|
});
|
|
|
|
expect(message.action).toMatch(/{"action":{"type":"hi"},"timestamp":\d+}/);
|
|
|
|
|
|
|
|
message = await listenMessage(() => {
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.send(
|
|
|
|
{ type: 'hi' },
|
|
|
|
{ counter: 1 },
|
2023-07-12 21:03:20 +03:00
|
|
|
1,
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
});
|
2020-12-19 23:01:09 +03:00
|
|
|
expect(message).toMatchObject({
|
2020-10-26 15:18:23 +03:00
|
|
|
type: 'ACTION',
|
|
|
|
payload: '{"counter":1}',
|
|
|
|
instanceId: 1,
|
|
|
|
name: undefined,
|
|
|
|
source: '@devtools-page',
|
|
|
|
});
|
|
|
|
expect(message.action).toMatch(/{"action":{"type":"hi"},"timestamp":\d+}/);
|
|
|
|
|
|
|
|
message = await listenMessage(() => {
|
|
|
|
window.__REDUX_DEVTOOLS_EXTENSION__.send(undefined, { counter: 1 }, 1);
|
|
|
|
});
|
|
|
|
expect(message).toEqual({
|
|
|
|
action: undefined,
|
|
|
|
type: 'STATE',
|
|
|
|
payload: { counter: 1 },
|
|
|
|
actionsById: undefined,
|
|
|
|
computedStates: undefined,
|
|
|
|
committedState: false,
|
|
|
|
instanceId: 1,
|
|
|
|
maxAge: undefined,
|
|
|
|
name: undefined,
|
|
|
|
source: '@devtools-page',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|