2018-12-23 03:13:56 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'enzyme';
|
|
|
|
import { renderToJson } from 'enzyme-to-json';
|
2020-12-20 17:13:01 +03:00
|
|
|
import { PerformAction } from 'redux-devtools';
|
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', () => {
|
2020-09-13 07:02:24 +03:00
|
|
|
const component = render(<TestGeneratorAsAny useCodemirror={false} />);
|
2018-12-23 03:13:56 +03:00
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be empty when no actions provided', () => {
|
|
|
|
const component = 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}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
it("should match function template's test for first action", () => {
|
2018-12-23 03:13:56 +03:00
|
|
|
const component = 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}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
it("should match string template's test for first action", () => {
|
2018-12-23 03:13:56 +03:00
|
|
|
const component = 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
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate test for the last action when selectedActionId not specified', () => {
|
|
|
|
const component = 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
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate test for vanilla js class', () => {
|
|
|
|
const component = 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
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate test for vanilla js class with string template', () => {
|
|
|
|
const component = 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
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(component)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|