From 2a988428ffdc581aefedb65fbbed8710ef29a0a8 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Mon, 11 May 2020 16:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20snapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __mocks__/svgMock.js | 5 + __tests__/__snapshots__/factory.test.tsx.snap | 79 +- __tests__/factory.test.tsx | 412 ++--- .../Form/__snapshots__/array.test.tsx.snap | 119 +- .../Form/__snapshots__/button.test.tsx.snap | 102 +- .../__snapshots__/buttonGroup.test.tsx.snap | 66 +- .../__snapshots__/buttonToolBar.test.tsx.snap | 102 +- .../Form/__snapshots__/checkbox.test.tsx.snap | 22 +- .../__snapshots__/checkboxes.test.tsx.snap | 68 +- .../Form/__snapshots__/city.test.tsx.snap | 18 + .../Form/__snapshots__/color.test.tsx.snap | 35 +- .../__snapshots__/container.test.tsx.snap | 23 +- .../Form/__snapshots__/date.test.tsx.snap | 35 +- .../Form/__snapshots__/dateRang.test.tsx.snap | 35 +- .../Form/__snapshots__/datetime.test.tsx.snap | 35 +- .../Form/__snapshots__/fieldSet.test.tsx.snap | 25 +- .../Form/__snapshots__/formula.test.tsx.snap | 18 + .../Form/__snapshots__/grid.test.tsx.snap | 19 + .../Form/__snapshots__/group.test.tsx.snap | 24 + .../Form/__snapshots__/hbox.test.tsx.snap | 19 + .../__snapshots__/iconPicker.test.tsx.snap | 19 + .../Form/__snapshots__/index.test.tsx.snap | 174 +++ .../__snapshots__/inputGroup.test.tsx.snap | 19 + .../Form/__snapshots__/list.test.tsx.snap | 66 +- .../Form/__snapshots__/number.test.tsx.snap | 18 + .../Form/__snapshots__/panel.test.tsx.snap | 108 +- .../Form/__snapshots__/radios.test.tsx.snap | 68 +- .../Form/__snapshots__/range.test.tsx.snap | 70 +- .../Form/__snapshots__/rating.test.tsx.snap | 18 + .../Form/__snapshots__/repeat.test.tsx.snap | 62 +- .../Form/__snapshots__/service.test.tsx.snap | 26 + .../Form/__snapshots__/static.test.tsx.snap | 18 + .../Form/__snapshots__/switch.test.tsx.snap | 18 + .../Form/__snapshots__/tabs.test.tsx.snap | 60 +- .../Form/__snapshots__/testarea.test.tsx.snap | 18 + .../Form/__snapshots__/time.test.tsx.snap | 35 +- .../__snapshots__/Carousel.test.tsx.snap | 28 +- .../__snapshots__/Image.test.tsx.snap | 25 +- .../__snapshots__/Page.test.tsx.snap | 728 ++------- .../__snapshots__/Tabs.test.tsx.snap | 34 +- .../__snapshots__/Wizard.test.tsx.snap | 1367 ++++++++--------- .../stores/__snapshots__/index.test.ts.snap | 14 + .../stores/__snapshots__/service.test.ts.snap | 17 +- .../utils/__snapshots__/api.test.ts.snap | 12 + __tests__/utils/tpl-builtin.test.ts | 1174 +++++++------- examples/components/Page/Form.jsx | 71 +- package.json | 3 +- src/components/icons.tsx | 5 + src/renderers/Form/Checkbox.tsx | 1 - 49 files changed, 2915 insertions(+), 2622 deletions(-) create mode 100644 __mocks__/svgMock.js diff --git a/__mocks__/svgMock.js b/__mocks__/svgMock.js new file mode 100644 index 00000000..57dc8ed7 --- /dev/null +++ b/__mocks__/svgMock.js @@ -0,0 +1,5 @@ +const React = require('react'); + +module.exports = React.forwardRef((props, ref) => + React.createElement('icon-mock', {ref, ...props}) +); diff --git a/__tests__/__snapshots__/factory.test.tsx.snap b/__tests__/__snapshots__/factory.test.tsx.snap index 536bd0b7..dc9354cf 100644 --- a/__tests__/__snapshots__/factory.test.tsx.snap +++ b/__tests__/__snapshots__/factory.test.tsx.snap @@ -128,6 +128,7 @@ exports[`factory:definitions 1`] = ` autocomplete="off" name="ref1" placeholder="" + size="10" type="text" value="ref value" /> @@ -190,6 +191,7 @@ exports[`factory:definitions 1`] = ` autocomplete="off" name="key" placeholder="" + size="10" type="text" value="" /> @@ -216,6 +218,7 @@ exports[`factory:definitions 1`] = ` autocomplete="off" name="value" placeholder="" + size="10" type="text" value="ref value" /> @@ -239,33 +242,6 @@ exports[`factory:definitions 1`] = ` children -
-
-
-
- -
-
-
@@ -284,8 +260,8 @@ exports[`factory:definitions 1`] = ` data-position="bottom" data-tooltip="删除" > -
@@ -323,22 +299,40 @@ exports[`factory:definitions 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + @@ -419,6 +413,7 @@ exports[`factory:definitions override 1`] = ` autocomplete="off" name="ref1" placeholder="" + size="10" type="text" value="" /> @@ -453,7 +448,9 @@ exports[`factory:definitions override 1`] = ` type="checkbox" /> - + Option A @@ -464,7 +461,9 @@ exports[`factory:definitions override 1`] = ` type="checkbox" /> - + Option B @@ -483,22 +482,40 @@ exports[`factory:definitions override 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + diff --git a/__tests__/factory.test.tsx b/__tests__/factory.test.tsx index 79c6cb62..5f01572c 100644 --- a/__tests__/factory.test.tsx +++ b/__tests__/factory.test.tsx @@ -1,257 +1,275 @@ import { - registerRenderer, - unRegisterRenderer, - RendererProps, + registerRenderer, + unRegisterRenderer, + RendererProps } from '../src/factory'; import '../src/themes/default'; -import { - render as amisRender -} from '../src/index'; +import {render as amisRender} from '../src/index'; import React = require('react'); import {render, fireEvent, cleanup} from 'react-testing-library'; -import { wait, makeEnv } from './helper'; +import {wait, makeEnv} from './helper'; test('factory unregistered Renderer', async () => { - const { - container, - } = render(amisRender({ - type: 'my-renderer', - a: 23 - })); - await wait(100); - expect(container).toMatchSnapshot(); // not found + const {container} = render( + amisRender({ + type: 'my-renderer', + a: 23 + }) + ); + await wait(100); + expect(container).toMatchSnapshot(); // not found }); test('factory custom not found!', async () => { - const { - container, - } = render(amisRender({ + const {container} = render( + amisRender( + { type: 'my-renderer', a: 23 - }, {}, makeEnv({ - loadRenderer: () => Promise.resolve(() => (
Not Found
)) - }))); - await wait(100); - expect(container).toMatchSnapshot(); // not found + }, + {}, + makeEnv({ + loadRenderer: () => Promise.resolve(() =>
Not Found
) + }) + ) + ); + await wait(100); + expect(container).toMatchSnapshot(); // not found }); test('factory custom not found 2!', async () => { - const { - container, - } = render(amisRender({ + const {container} = render( + amisRender( + { type: 'my-renderer', a: 23 - }, {}, makeEnv({ - loadRenderer: () => () => (
Not Found
) - }))); - await wait(100); - expect(container).toMatchSnapshot(); // not found + }, + {}, + makeEnv({ + loadRenderer: () => () =>
Not Found
+ }) + ) + ); + await wait(100); + expect(container).toMatchSnapshot(); // not found }); test('factory custom not found 3!', async () => { - const { - container, - } = render(amisRender({ + const {container} = render( + amisRender( + { type: 'my-renderer', a: 23 - }, {}, makeEnv({ - loadRenderer: () => (
Not Found
) - }))); - await wait(100); - expect(container).toMatchSnapshot(); // not found + }, + {}, + makeEnv({ + loadRenderer: () =>
Not Found
+ }) + ) + ); + await wait(100); + expect(container).toMatchSnapshot(); // not found }); test('factory load Renderer on need', async () => { - const { - container, - } = render(amisRender({ + const {container} = render( + amisRender( + { type: 'my-renderer2', a: 23 - }, {}, makeEnv({ + }, + {}, + makeEnv({ session: 'loadRenderer', - loadRenderer: (schema) => { - interface MyProps extends RendererProps { - a: number; - }; - - class MyComponent extends React.Component { - render() { - return (
This is Custom Renderer2, a is {this.props.a}
); - } + loadRenderer: schema => { + interface MyProps extends RendererProps { + a: number; + } + + class MyComponent extends React.Component { + render() { + return
This is Custom Renderer2, a is {this.props.a}
; } - - registerRenderer({ - component: MyComponent, - test: /\bmy-renderer2$/ - }); + } + + registerRenderer({ + component: MyComponent, + test: /\bmy-renderer2$/ + }); } - }))); - await wait(100); - expect(container).toMatchSnapshot(); // not found + }) + ) + ); + await wait(100); + expect(container).toMatchSnapshot(); // not found }); test('factory:registerRenderer', () => { - interface MyProps extends RendererProps { - a: number; - }; + interface MyProps extends RendererProps { + a: number; + } - class MyComponent extends React.Component { - render() { - return (
This is Custom Renderer, a is {this.props.a}
); - } + class MyComponent extends React.Component { + render() { + return
This is Custom Renderer, a is {this.props.a}
; } + } - const renderer = registerRenderer({ - component: MyComponent, - test: /\bmy-renderer$/ - }); + const renderer = registerRenderer({ + component: MyComponent, + test: /\bmy-renderer$/ + }); - const { - container - } = render(amisRender({ - type: 'my-renderer', - a: 23 - })) + const {container} = render( + amisRender({ + type: 'my-renderer', + a: 23 + }) + ); - expect(container).toMatchSnapshot(); - unRegisterRenderer(renderer); + expect(container).toMatchSnapshot(); + unRegisterRenderer(renderer); }); -test('factory:definitions', () => { - const { - container, - getByText - } = render(amisRender({ +test('factory:definitions', async () => { + const {container, getByText} = render( + amisRender( + { definitions: { - aa: { + aa: { + type: 'text', + name: 'jack', + value: 'ref value', + remark: '通过\\$ref引入的组件' + }, + bb: { + type: 'combo', + multiple: true, + multiLine: true, + remark: 'combo中的子项引入自身,实现嵌套的效果', + controls: [ + { + label: 'combo 1', type: 'text', - name: 'jack', - value: 'ref value', - remark: '通过\\$ref引入的组件' - }, - bb: { - type: 'combo', - multiple: true, - multiLine: true, - remark: 'combo中的子项引入自身,实现嵌套的效果', - controls: [ - { - label: 'combo 1', - type: 'text', - name: 'key' - }, - { - label: 'combo 2', - name: 'value', - $ref: 'aa' - }, - { - name: 'children', - label: 'children', - $ref: 'bb' - } - ] - } + name: 'key' + }, + { + label: 'combo 2', + name: 'value', + $ref: 'aa' + }, + { + name: 'children', + label: 'children', + $ref: 'bb' + } + ] + } }, type: 'page', title: '引用', body: [ - { - type: 'form', - api: 'api/xxx', - actions: [], - controls: [ - { - label: 'text2', - $ref: 'aa', - name: 'ref1' - }, - { - label: 'combo', - $ref: 'bb', - name: 'ref2' - } - ] - } + { + type: 'form', + api: 'api/xxx', + actions: [], + controls: [ + { + label: 'text2', + $ref: 'aa', + name: 'ref1' + }, + { + label: 'combo', + $ref: 'bb', + name: 'ref2' + } + ] + } ] - }, { - }, makeEnv({ - }))); + }, + {}, + makeEnv({}) + ) + ); - fireEvent.click(getByText('新增')); - expect(container).toMatchSnapshot(); + await wait(100); + fireEvent.click(getByText('新增')); + expect(container).toMatchSnapshot(); }); test('factory:definitions override', () => { - const { - container - } = render(amisRender({ + const {container} = render( + amisRender( + { definitions: { - aa: { + aa: { + type: 'text', + name: 'jack', + remark: '通过\\$ref引入的组件' + }, + bb: { + type: 'combo', + multiple: true, + multiLine: true, + remark: 'combo中的子项引入自身,实现嵌套的效果', + controls: [ + { + label: 'combo 1', type: 'text', - name: 'jack', - remark: '通过\\$ref引入的组件' - }, - bb: { - type: 'combo', - multiple: true, - multiLine: true, - remark: 'combo中的子项引入自身,实现嵌套的效果', - controls: [ - { - label: 'combo 1', - type: 'text', - name: 'key' - }, - { - label: 'combo 2', - name: 'value', - $ref: 'aa' - }, - { - name: 'children', - label: 'children', - $ref: 'bb' - } - ] - } + name: 'key' + }, + { + label: 'combo 2', + name: 'value', + $ref: 'aa' + }, + { + name: 'children', + label: 'children', + $ref: 'bb' + } + ] + } }, type: 'page', title: '引用', body: [ - { - type: 'form', - api: 'api/xxx', - actions: [], - controls: [ - { - label: 'text2', - $ref: 'aa', - name: 'ref1' - }, - { - label: 'combo', - $ref: 'bb', - name: 'ref2', - type: 'checkboxes', - value: 1, - options: [ - { - label: 'Option A', - value: 1 - }, - { - label: 'Option B', - value: 2 - } - ] - } + { + type: 'form', + api: 'api/xxx', + actions: [], + controls: [ + { + label: 'text2', + $ref: 'aa', + name: 'ref1' + }, + { + label: 'combo', + $ref: 'bb', + name: 'ref2', + type: 'checkboxes', + value: 1, + options: [ + { + label: 'Option A', + value: 1 + }, + { + label: 'Option B', + value: 2 + } ] - } + } + ] + } ] - }, { - }, makeEnv({ - }))); + }, + {}, + makeEnv({}) + ) + ); - expect(container).toMatchSnapshot(); -}); \ No newline at end of file + expect(container).toMatchSnapshot(); +}); diff --git a/__tests__/renderers/Form/__snapshots__/array.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/array.test.tsx.snap index 95fcdb21..ddc336e2 100644 --- a/__tests__/renderers/Form/__snapshots__/array.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/array.test.tsx.snap @@ -36,107 +36,6 @@ exports[`Renderer:array 1`] = ` 颜色集合
-
-
-
-
-
-
-
-
-
-
-
-
- - - - - - - - - -
-
-
-
-
-
-
-
-
-
-
- - -
-
-
@@ -144,22 +43,40 @@ exports[`Renderer:array 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + diff --git a/__tests__/renderers/Form/__snapshots__/button.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/button.test.tsx.snap index 3ff99600..71cc437f 100644 --- a/__tests__/renderers/Form/__snapshots__/button.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/button.test.tsx.snap @@ -83,22 +83,40 @@ exports[`Renderer:button 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + @@ -187,90 +205,40 @@ exports[`Renderer:button 2`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + - diff --git a/__tests__/renderers/Form/__snapshots__/buttonGroup.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/buttonGroup.test.tsx.snap index d36366a0..914e7597 100644 --- a/__tests__/renderers/Form/__snapshots__/buttonGroup.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/buttonGroup.test.tsx.snap @@ -95,22 +95,40 @@ exports[`Renderer:button-group 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + @@ -196,7 +214,11 @@ exports[`Renderer:button-group:multiple clearable 1`] = ` - a,b + + - + @@ -207,22 +229,40 @@ exports[`Renderer:button-group:multiple clearable 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + @@ -308,7 +348,11 @@ exports[`Renderer:button-group:multiple clearable 2`] = ` - a + + - + @@ -319,22 +363,40 @@ exports[`Renderer:button-group:multiple clearable 2`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + diff --git a/__tests__/renderers/Form/__snapshots__/buttonToolBar.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/buttonToolBar.test.tsx.snap index 4bfcbdfe..63893dba 100644 --- a/__tests__/renderers/Form/__snapshots__/buttonToolBar.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/buttonToolBar.test.tsx.snap @@ -64,22 +64,40 @@ exports[`Renderer:button-toolbar 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + @@ -149,90 +167,40 @@ exports[`Renderer:button-toolbar 2`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + - diff --git a/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap index fcad00b4..1a8e20e3 100644 --- a/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/checkbox.test.tsx.snap @@ -46,7 +46,9 @@ exports[`Renderer:checkbox 1`] = ` type="checkbox" /> - + @@ -62,22 +64,40 @@ exports[`Renderer:checkbox 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + diff --git a/__tests__/renderers/Form/__snapshots__/checkboxes.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/checkboxes.test.tsx.snap index 66d72f4d..b50385f6 100644 --- a/__tests__/renderers/Form/__snapshots__/checkboxes.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/checkboxes.test.tsx.snap @@ -46,7 +46,9 @@ exports[`Renderer:checkboxes 1`] = ` type="checkbox" /> - + Option A @@ -57,7 +59,9 @@ exports[`Renderer:checkboxes 1`] = ` type="checkbox" /> - + Option B @@ -68,7 +72,9 @@ exports[`Renderer:checkboxes 1`] = ` type="checkbox" /> - + Option C @@ -79,7 +85,9 @@ exports[`Renderer:checkboxes 1`] = ` type="checkbox" /> - + Option D @@ -119,22 +127,40 @@ exports[`Renderer:checkboxes 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + @@ -186,7 +212,9 @@ exports[`Renderer:checkboxes 2`] = ` type="checkbox" /> - + Option A @@ -197,7 +225,9 @@ exports[`Renderer:checkboxes 2`] = ` type="checkbox" /> - + Option B @@ -208,7 +238,9 @@ exports[`Renderer:checkboxes 2`] = ` type="checkbox" /> - + Option C @@ -219,7 +251,9 @@ exports[`Renderer:checkboxes 2`] = ` type="checkbox" /> - + Option D @@ -259,22 +293,40 @@ exports[`Renderer:checkboxes 2`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + diff --git a/__tests__/renderers/Form/__snapshots__/city.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/city.test.tsx.snap index e62a5ade..d7476c8f 100644 --- a/__tests__/renderers/Form/__snapshots__/city.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/city.test.tsx.snap @@ -110,22 +110,40 @@ exports[`Renderer:city 1`] = ` class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: scroll; z-index: -1; visibility: hidden;" > + + diff --git a/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap b/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap index d87cb94e..f3d5ffcc 100644 --- a/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap +++ b/__tests__/renderers/Form/__snapshots__/color.test.tsx.snap @@ -53,19 +53,10 @@ exports[`Renderer:color 1`] = ` - - - +