diff --git a/__tests__/renderers/ButtonToolbar.test.tsx b/__tests__/renderers/ButtonToolbar.test.tsx new file mode 100644 index 000000000..41220bb6e --- /dev/null +++ b/__tests__/renderers/ButtonToolbar.test.tsx @@ -0,0 +1,31 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:button-toolbar', async () => { + const { + container + } = render(amisRender({ + type: 'button-toolbar', + name: 'button-toolbar', + label: 'button-toolbar', + buttons: [ + { + type: 'button', + label: '按钮1', + }, + { + type: 'button', + label: '按钮2' + } + ], + className: 'show' + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Carousel.test.tsx b/__tests__/renderers/Carousel.test.tsx new file mode 100644 index 000000000..2d3c9e07f --- /dev/null +++ b/__tests__/renderers/Carousel.test.tsx @@ -0,0 +1,44 @@ +import React = require('react'); +import {render, fireEvent} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:carousel', async () => { + const { + container + } = render(amisRender({ + type: 'carousel', + controlsTheme: 'light', + width: '500', + height: '300', + options: [ + { + image: 'https://video-react.js.org/assets/poster.png', + title: '标题', + titleClassName: 'block', + description: '描述', + descriptionClassName: 'block' + }, + { + html: '
carousel data
' + }, + { + image: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg' + } + ], + className: 'show' + }, {}, makeEnv({ + }))); + + const image = document.querySelector('div.a-Carousel-item'); + fireEvent.mouseEnter(image as HTMLDivElement); + const leftArrow = document.querySelector('div.a-Carousel-leftArrow') + fireEvent.click(leftArrow as HTMLDivElement); + const rightArrow = document.querySelector('div.a-Carousel-rightArrow') + fireEvent.click(rightArrow as HTMLDivElement); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Date.test.tsx b/__tests__/renderers/Date.test.tsx new file mode 100644 index 000000000..1efbfcd2c --- /dev/null +++ b/__tests__/renderers/Date.test.tsx @@ -0,0 +1,29 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:date', async () => { + const { + container + } = render(amisRender({ + type: 'date', + name: 'date', + label: 'date', + value: '1559836800', + format: 'YYYY-MM-DD', + placeholder: '请选择时间', + minDate: '1559664000', + maxDate: '1561737600', + className: 'show' + }, {}, makeEnv({ + }))); + + const input = container.querySelector('.a-DateField'); + expect(input.innerHTML).toEqual('2019-06-07'); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/DropDownButton.test.tsx b/__tests__/renderers/DropDownButton.test.tsx new file mode 100644 index 000000000..d3c9aeef2 --- /dev/null +++ b/__tests__/renderers/DropDownButton.test.tsx @@ -0,0 +1,49 @@ +import React = require('react'); +import {render, fireEvent} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:dropdown-button', async () => { + const { + container + } = render(amisRender({ + type: 'dropdown-button', + level: 'primary', + buttons: [ + { + type: 'button', + label: '按钮', + actionType: 'dialog', + dialog: { + title: '系统提示', + body: '对你点击了' + } + }, + { + type: 'button', + label: '按钮', + actionType: 'dialog', + dialog: { + title: '系统提示', + body: '对你点击了' + } + }, + { + type: 'button', + label: '按钮', + visible: false + } + ], + className: 'show' + }, {}, makeEnv({ + }))); + + const dropdowmButton = document.querySelector('button.a-Button'); + fireEvent.click(dropdowmButton as HTMLDivElement); + expect(container).toMatchSnapshot(); + fireEvent.click(dropdowmButton as HTMLDivElement); + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Each.test.tsx b/__tests__/renderers/Each.test.tsx new file mode 100644 index 000000000..5c83bc138 --- /dev/null +++ b/__tests__/renderers/Each.test.tsx @@ -0,0 +1,24 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:each', async () => { + const { + container + } = render(amisRender({ + type: 'each', + items: { + type: 'tpl', + tpl: '<%= data.name %>' + }, + value: [{name: 'jack'}, {name: 'martin'}], + className: 'show' + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/HBox.test.tsx b/__tests__/renderers/HBox.test.tsx new file mode 100644 index 000000000..7aea073a8 --- /dev/null +++ b/__tests__/renderers/HBox.test.tsx @@ -0,0 +1,53 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:hbox', async () => { + const { + container + } = render(amisRender({ + type: 'hbox', + columns: [ + { + type: 'tpl', + tpl: 'w-xs', + className: 'bg-info', + inline: false, + columnClassName: 'w-xs' + }, + { + type: 'tpl', + tpl: 'w-sm', + className: 'bg-info lter', + inline: false, + columnClassName: 'w-sm' + }, + { + type: 'tpl', + tpl: 'w', + className: 'bg-info dk', + inline: false, + columnClassName: 'w' + }, + { + type: 'tpl', + tpl: '平均分配', + className: 'bg-success', + inline: false + }, + { + type: 'tpl', + tpl: '平均分配', + className: 'bg-primary', + inline: false + } + ] + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/IFrame.test.tsx b/__tests__/renderers/IFrame.test.tsx new file mode 100644 index 000000000..a584f0046 --- /dev/null +++ b/__tests__/renderers/IFrame.test.tsx @@ -0,0 +1,22 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:iframe', async () => { + const { + container + } = render(amisRender({ + type: 'iframe', + className: 'b-a', + src: "https://www.baidu.com", + height: 500, + width: 500 + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Image.test.tsx b/__tests__/renderers/Image.test.tsx new file mode 100644 index 000000000..902dec274 --- /dev/null +++ b/__tests__/renderers/Image.test.tsx @@ -0,0 +1,23 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:image', async () => { + const { + container + } = render(amisRender({ + type: 'image', + defaultImage: 'https://www.baidu.com/img/bd_logo1.png', + title: '图片', + description: '图片描述', + imageClassName: 'b', + className: 'show' + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Link.test.tsx b/__tests__/renderers/Link.test.tsx new file mode 100644 index 000000000..41f86bd26 --- /dev/null +++ b/__tests__/renderers/Link.test.tsx @@ -0,0 +1,22 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:link', async () => { + const { + container + } = render(amisRender({ + type: 'link', + href: 'https://www.baidu.com', + placeholder: 'link address', + className: 'show', + blank: true + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Mapping.test.tsx b/__tests__/renderers/Mapping.test.tsx new file mode 100644 index 000000000..fad1f229e --- /dev/null +++ b/__tests__/renderers/Mapping.test.tsx @@ -0,0 +1,25 @@ +import React = require('react'); +import {render} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import { makeEnv } from '../helper'; + +test('Renderer:mapping', async () => { + const { + container + } = render(amisRender({ + type: 'mapping', + mapping: { + 1: "漂亮", + 2: "开心", + 3: "惊吓", + 4: "紧张", + "*": "其他:${type}" + } + }, {}, makeEnv({ + }))); + + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/Tabs.test.tsx b/__tests__/renderers/Tabs.test.tsx new file mode 100644 index 000000000..4afacb031 --- /dev/null +++ b/__tests__/renderers/Tabs.test.tsx @@ -0,0 +1,44 @@ +import React = require('react'); +import {render, cleanup} from 'react-testing-library'; +import '../../src/themes/default'; +import { + render as amisRender +} from '../../src/index'; +import {makeEnv} from '../helper'; +import { clearStoresCache } from '../../src/factory'; + +afterEach(() => { + cleanup(); + clearStoresCache(); +}); + +test('Renderer:tabs', async () => { + const { + container + } = render(amisRender({ + type: "tabs", + tabClassName: 'bg-info', + tabs: [ + { + title: '基本配置', + body: '

tab1 内容

', + }, + { + title: '其他配置', + controls: [ + { + name: 'c', + type: 'text', + label: '文本3' + }, + { + name: 'd', + type: 'text', + label: '文本4' + } + ] + } + ] + }, {}, makeEnv())); + expect(container).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/__tests__/renderers/__snapshots__/ButtonToolbar.test.tsx.snap b/__tests__/renderers/__snapshots__/ButtonToolbar.test.tsx.snap new file mode 100644 index 000000000..b334a1bd8 --- /dev/null +++ b/__tests__/renderers/__snapshots__/ButtonToolbar.test.tsx.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renderer:button-toolbar 1`] = ` +
+
+ + +
+
+`; diff --git a/__tests__/renderers/__snapshots__/Carousel.test.tsx.snap b/__tests__/renderers/__snapshots__/Carousel.test.tsx.snap new file mode 100644 index 000000000..8210457c7 --- /dev/null +++ b/__tests__/renderers/__snapshots__/Carousel.test.tsx.snap @@ -0,0 +1,114 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Renderer:carousel 1`] = ` +
+