2018-12-23 03:13:56 +03:00
|
|
|
import React from 'react';
|
2021-10-22 03:43:15 +03:00
|
|
|
import { render } from '@testing-library/react';
|
2020-12-21 17:08:08 +03:00
|
|
|
import { PerformAction } from '@redux-devtools/core';
|
2020-09-13 07:02:24 +03:00
|
|
|
import { Action } from 'redux';
|
2018-12-23 03:13:56 +03:00
|
|
|
import TestGenerator from '../src/TestGenerator';
|
|
|
|
import fnTemplate from '../src/redux/mocha';
|
|
|
|
import strTemplate from '../src/redux/mocha/template';
|
|
|
|
import fnVanillaTemplate from '../src/vanilla/mocha';
|
|
|
|
import strVanillaTemplate from '../src/vanilla/mocha/template';
|
|
|
|
|
2020-09-13 07:02:24 +03:00
|
|
|
const actions: { [actionId: number]: PerformAction<Action<unknown>> } = {
|
|
|
|
0: {
|
|
|
|
type: 'PERFORM_ACTION',
|
|
|
|
action: { type: '@@INIT' },
|
|
|
|
timestamp: 0,
|
|
|
|
stack: undefined,
|
|
|
|
},
|
|
|
|
1: {
|
|
|
|
type: 'PERFORM_ACTION',
|
|
|
|
action: { type: 'INCREMENT_COUNTER' },
|
|
|
|
timestamp: 0,
|
|
|
|
stack: undefined,
|
|
|
|
},
|
2018-12-23 03:13:56 +03:00
|
|
|
};
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const computedStates = [{ state: { counter: 0 } }, { state: { counter: 1 } }];
|
2018-12-23 03:13:56 +03:00
|
|
|
|
2020-09-13 07:02:24 +03:00
|
|
|
const TestGeneratorAsAny = TestGenerator as any;
|
|
|
|
|
2018-12-23 03:13:56 +03:00
|
|
|
describe('TestGenerator component', () => {
|
|
|
|
it('should show warning message when no params provided', () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(<TestGeneratorAsAny useCodemirror={false} />);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be empty when no actions provided', () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(
|
2020-09-13 07:02:24 +03:00
|
|
|
<TestGeneratorAsAny
|
2019-01-10 21:51:14 +03:00
|
|
|
assertion={fnTemplate.assertion}
|
|
|
|
dispatcher={fnTemplate.dispatcher}
|
|
|
|
wrap={fnTemplate.wrap}
|
2018-12-23 03:13:56 +03:00
|
|
|
useCodemirror={false}
|
|
|
|
/>
|
|
|
|
);
|
2021-10-22 00:55:21 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
it("should match function template's test for first action", () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(
|
2020-09-13 07:02:24 +03:00
|
|
|
<TestGeneratorAsAny
|
2019-01-10 21:51:14 +03:00
|
|
|
assertion={fnTemplate.assertion}
|
|
|
|
dispatcher={fnTemplate.dispatcher}
|
|
|
|
wrap={fnTemplate.wrap}
|
|
|
|
actions={actions}
|
|
|
|
computedStates={computedStates}
|
|
|
|
selectedActionId={1}
|
2018-12-23 03:13:56 +03:00
|
|
|
useCodemirror={false}
|
|
|
|
/>
|
|
|
|
);
|
2021-10-22 00:55:21 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
it("should match string template's test for first action", () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(
|
2020-09-13 07:02:24 +03:00
|
|
|
<TestGeneratorAsAny
|
2019-01-10 21:51:14 +03:00
|
|
|
assertion={strTemplate.assertion}
|
|
|
|
dispatcher={strTemplate.dispatcher}
|
|
|
|
wrap={strTemplate.wrap}
|
|
|
|
useCodemirror={false}
|
|
|
|
actions={actions}
|
|
|
|
computedStates={computedStates}
|
|
|
|
selectedActionId={1}
|
2018-12-23 03:13:56 +03:00
|
|
|
/>
|
|
|
|
);
|
2021-10-22 00:55:21 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate test for the last action when selectedActionId not specified', () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(
|
2020-09-13 07:02:24 +03:00
|
|
|
<TestGeneratorAsAny
|
2019-01-10 21:51:14 +03:00
|
|
|
assertion={fnTemplate.assertion}
|
|
|
|
dispatcher={fnTemplate.dispatcher}
|
|
|
|
wrap={fnTemplate.wrap}
|
|
|
|
actions={actions}
|
|
|
|
computedStates={computedStates}
|
|
|
|
useCodemirror={false}
|
2018-12-23 03:13:56 +03:00
|
|
|
/>
|
|
|
|
);
|
2021-10-22 00:55:21 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate test for vanilla js class', () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(
|
2020-09-13 07:02:24 +03:00
|
|
|
<TestGeneratorAsAny
|
2019-01-10 21:51:14 +03:00
|
|
|
assertion={fnVanillaTemplate.assertion}
|
|
|
|
dispatcher={fnVanillaTemplate.dispatcher}
|
2018-12-23 03:13:56 +03:00
|
|
|
wrap={fnVanillaTemplate.wrap}
|
2019-01-10 21:51:14 +03:00
|
|
|
actions={actions}
|
|
|
|
computedStates={computedStates}
|
|
|
|
selectedActionId={1}
|
|
|
|
isVanilla
|
|
|
|
name="SomeStore"
|
|
|
|
useCodemirror={false}
|
2018-12-23 03:13:56 +03:00
|
|
|
/>
|
|
|
|
);
|
2021-10-22 00:55:21 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate test for vanilla js class with string template', () => {
|
2021-10-22 00:55:21 +03:00
|
|
|
const { container } = render(
|
2020-09-13 07:02:24 +03:00
|
|
|
<TestGeneratorAsAny
|
2019-01-10 21:51:14 +03:00
|
|
|
assertion={strVanillaTemplate.assertion}
|
|
|
|
dispatcher={strVanillaTemplate.dispatcher}
|
2018-12-23 03:13:56 +03:00
|
|
|
wrap={strVanillaTemplate.wrap}
|
2019-01-10 21:51:14 +03:00
|
|
|
actions={actions}
|
|
|
|
computedStates={computedStates}
|
|
|
|
selectedActionId={1}
|
|
|
|
isVanilla
|
|
|
|
name="SomeStore"
|
|
|
|
useCodemirror={false}
|
2018-12-23 03:13:56 +03:00
|
|
|
/>
|
|
|
|
);
|
2021-10-22 00:55:21 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-12-23 03:13:56 +03:00
|
|
|
});
|
|
|
|
});
|