amis2/packages/amis/__tests__/renderers/Page.test.tsx

1409 lines
30 KiB
TypeScript
Raw Normal View History

2019-04-30 11:11:25 +08:00
import * as renderer from 'react-test-renderer';
import {render, fireEvent, cleanup, waitFor} from '@testing-library/react';
2022-06-02 10:00:09 +08:00
import '../../src';
import {render as amisRender} from '../../src';
import {wait, makeEnv} from '../helper';
2022-06-02 13:28:23 +08:00
import {clearStoresCache} from '../../src';
import {createMemoryHistory} from 'history';
2019-04-30 11:11:25 +08:00
afterEach(() => {
cleanup();
clearStoresCache();
jest.useRealTimers();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page', () => {
const component = renderer.create(
amisRender({
type: 'page',
title: 'This is Title',
subTitle: 'This is SubTitle',
remark: 'Remark Text',
toolbar: 'This is toolbar',
body: 'This is body'
})
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initData', () => {
const component = renderer.create(
amisRender({
type: 'page',
data: {
a: 1
},
body: 'The variable value is ${a}'
})
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
data: {
a: 2
}
}
})
);
const {container, getByText, rerender}: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is 2')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi error show Message', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 500,
msg: 'Internal Error'
}
})
);
const {container, getByText, rerender}: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
expect(container.querySelector('.cxd-Alert')).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi show loading', async () => {
const fetcher = jest.fn().mockImplementationOnce(() => {
return new Promise(async resolve => {
await wait(200, false);
resolve({
data: {
status: 0,
msg: 'ok',
data: {
a: 3
}
}
});
2019-04-30 11:11:25 +08:00
});
});
const {container, getByText, getByTestId, unmount} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(
container.querySelector('[data-testid="spinner"]')
).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('The variable value is 3')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
});
2019-04-30 11:11:25 +08:00
test('Renderer:Page initApi initFetch:false', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 2
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
initFetch: false,
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is')).toBeInTheDocument();
});
expect(fetcher).not.toHaveBeenCalled();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi initFetch:true', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 2
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
initFetch: true,
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is 2')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(fetcher).toHaveBeenCalled();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi initFetchOn -> true', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 2
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
initFetchOn: 'this.goFetch',
body: 'The variable value is ${a}'
},
{
2019-04-30 11:11:25 +08:00
data: {
goFetch: true
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is 2')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(fetcher).toHaveBeenCalled();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi initFetchOn -> false', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 2
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
initFetchOn: 'this.goFetch',
body: 'The variable value is ${a}'
},
{
2019-04-30 11:11:25 +08:00
data: {
goFetch: false
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is')).toBeInTheDocument();
});
expect(fetcher).not.toHaveBeenCalled();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page classNames', async () => {
const {container, getByText, getByTestId} = render(
amisRender({
type: 'page',
title: 'This is Title',
subTitle: 'This is SubTitle',
remark: 'Remark Text',
toolbar: 'This is toolbar',
body: 'This is body',
aside: 'This is aside',
headerClassName: 'header-class-name',
bodyClassName: 'body-class-name',
asideClassName: 'aside-class-name',
toolbarClassName: 'toolbar-class-name'
})
);
await waitFor(() => {
expect(getByText('This is body')).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi interval 轮询调用', async () => {
jest.useFakeTimers();
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 4
2019-04-30 11:11:25 +08:00
}
}
})
);
const component = renderer.create(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
interval: 3000,
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
2019-04-30 11:11:25 +08:00
await wait(10, false);
jest.advanceTimersByTime(3000);
2019-04-30 11:11:25 +08:00
const times = fetcher.mock.calls.length;
2019-04-30 11:11:25 +08:00
// 至少调用了 1次
expect(times).toBeGreaterThan(0);
component.unmount();
});
2019-04-30 11:11:25 +08:00
test('Renderer:Page initApi interval 轮询调用自动停止', async () => {
// jest.useFakeTimers();
let count = 1;
const fetcher = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
status: 0,
msg: 'ok',
data: {
a: count++
}
}
2019-04-30 11:11:25 +08:00
});
});
renderer.create(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
interval: 1000,
2019-04-30 11:11:25 +08:00
stopAutoRefreshWhen: 'this.a > 2',
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
2019-04-30 11:11:25 +08:00
await wait(1000);
// jest.advanceTimersByTime(3000);
await wait(1000);
// jest.advanceTimersByTime(3000);
await wait(1000);
// jest.advanceTimersByTime(3000);
expect(fetcher).toHaveBeenCalledTimes(3);
});
2019-04-30 11:11:25 +08:00
test('Renderer:Page initApi silentPolling', async () => {
jest.useFakeTimers();
const fetcher = jest
.fn()
.mockImplementationOnce(() => {
return new Promise(resolve =>
resolve({
data: {
status: 0,
msg: 'ok',
data: {
a: 3
}
}
})
);
})
.mockImplementationOnce(() => {
return new Promise(async resolve => {
resolve({
data: {
status: 0,
msg: 'ok',
data: {
a: 4
}
}
});
});
2019-04-30 11:11:25 +08:00
});
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: '/api/xxx',
body: 'The variable value is ${a}',
interval: 3000, // 最少是 3秒
silentPolling: true
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is 3')).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
jest.advanceTimersByTime(3000);
await waitFor(() => {
expect(getByText('The variable value is 4')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi sendOn -> true', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 2
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: {
method: 'get',
url: '/api/xxx',
sendOn: 'this.goFetch'
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{
2019-04-30 11:11:25 +08:00
data: {
goFetch: true
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is 2')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(fetcher).toHaveBeenCalled();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi sendOn -> false', async () => {
const fetcher = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 2
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, getByTestId} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: {
method: 'get',
url: '/api/xxx',
sendOn: 'this.goFetch'
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{
2019-04-30 11:11:25 +08:00
data: {
goFetch: false
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await waitFor(() => {
expect(getByText('The variable value is')).toBeInTheDocument();
});
expect(fetcher).not.toHaveBeenCalled();
2019-04-30 11:11:25 +08:00
});
2023-04-07 11:04:18 +08:00
test('Renderer:Page location query', async () => {
const history = createMemoryHistory({
initialEntries: ['/xxx?a=5']
});
2019-04-30 11:11:25 +08:00
const component = renderer.create(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
body: 'The variable value is ${a}'
},
{
location: history.location as any
}
)
);
2019-04-30 11:11:25 +08:00
expect(component.toJSON()).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
history.push('/xxx?a=6');
2019-04-30 11:11:25 +08:00
component.update(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
body: 'The variable value is ${a}'
},
{
location: history.location as any
}
)
);
2023-04-07 11:04:18 +08:00
await wait(300);
expect(component.toJSON()).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initFetchOn trigger initApi fetch when condition becomes ture', async () => {
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 6
2019-04-30 11:11:25 +08:00
}
}
})
);
const history = createMemoryHistory({
initialEntries: ['/xxx']
});
const component = renderer.create(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
initFetchOn: 'this.id',
body: 'The variable value is ${a}'
},
{
location: history.location as any
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await wait(300);
history.push('/xxxx?id=1');
2019-04-30 11:11:25 +08:00
component.update(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
initFetchOn: 'this.id',
body: 'The variable value is ${a}'
},
{
location: history.location as any
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
2019-04-30 11:11:25 +08:00
await wait(300);
expect(fetcher).toHaveBeenCalledTimes(1);
expect(component.toJSON()).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=url|link', async () => {
const jumpTo = jest.fn();
const {getByText} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'JumpTo',
actionType: 'link',
to: '/goToPath?a=${a}'
}
2019-04-30 11:11:25 +08:00
]
},
{
2019-04-30 11:11:25 +08:00
data: {
a: 1
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
jumpTo
})
)
);
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('JumpTo')).toBeInTheDocument();
});
fireEvent.click(getByText(/JumpTo/));
await wait(300);
expect(jumpTo).toHaveBeenCalled();
expect(jumpTo.mock.calls[0][0]).toEqual('/goToPath?a=1');
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=dialog default', async () => {
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'OpenDialog',
actionType: 'dialog',
dialog: {
body: 'this is dialog'
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
]
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('OpenDialog')).toBeInTheDocument();
});
fireEvent.click(getByText('OpenDialog'));
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('取消')).toBeInTheDocument();
});
fireEvent.click(getByText('取消'));
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=dialog mergeData', async () => {
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'OpenDialog',
actionType: 'dialog',
dialog: {
actions: [
{
label: '确认',
type: 'submit',
mergeData: true
2019-04-30 11:11:25 +08:00
}
],
body: {
type: 'form',
controls: [
{
label: 'A',
type: 'text',
value: '3',
name: 'a'
}
]
}
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
],
body: 'The variable a is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('OpenDialog')).toBeInTheDocument();
});
fireEvent.click(getByText(/OpenDialog/));
await waitFor(() => {
expect(getByText('确认')).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/确认/));
style:cxd主题对齐云舍4.0样式 (#4354) * Select Options等组件样式对齐4.0 * 更新测试快照 * 修改部分测试用例 * feat:4.0样式修改 * 修改checkboxes hover问题 * Feat image 4.0 (#4242) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * fix: textarea组件对齐4.0标准 (#4149) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * fix: inputTree 组价对齐4.0标准 (#4148) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: inputTree组件对齐4.0标准 * fix: inputtree组件图标颜色修改 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * feat: 部分组件样式问题修复 (#4154) * feat: input-text 样式 * feat: input-range 样式 * feat: table 样式 1 * feat: search-box * feat: curd icon * feat: table 空状态 * feat: input-text 多选,最大宽度设置 * feat: search-box 搜索图标颜色 * feat: crud 编辑、过滤、搜索、排序 图标样式修改 * feat: 更新快照 * feat: 更新快照 2 * feat: curd fix * feat: curd edit icon fix * feat: input-password 不可见 icon 修改 * feat: input-password snapshot update * docs:完善对话框size参数说明 * feat: Log 组件支持虚拟渲染及限制最大行数 * 修复不支持 loading 问题 * 换一下名字 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> Co-authored-by: liweijian <liweijian@hkmtl.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> * fix:修复删除图标颜色问题 (#4245) * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * feat: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * faet: Step组件支持点状步骤条、指定标签放置位置、新增超出内容显示浮层 * fix: 点状步骤条样式修改 * fix: inputTree组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: textarea组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: inputImage组件对齐4.0标准 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: image组件样式优化 * fix: 修复conditionbuilder组价图标颜色问题 Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> * form表单对齐云社4.0 (#4248) * feat: form增加表单项 label文本对齐方式选项 * fix: remark 支持在表单内配置 * style: form 间距对齐云社4.0 Co-authored-by: sarding <hongfuquan@baidu.com> * Fix chart radios name (#4251) * fix: Chart 单选框 修改为 ChartRadios 图表单选框 * fix: input-password 修改 可见 图标 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * feat: checkboxes内边距&nestedSelect箭头修改 (#4254) Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * Feature style 4.0 cxd (#4261) * feat: 日期&折叠面板&提示样式对齐 * fix:测试用例修复 * feat: timeRange开始和结束分开&日期样式优化 * styles: 日历样式修复 Co-authored-by: hongyang03 <hongyang03@baidu.com> * 整体字体大小调整 (#4264) * feat: form增加表单项 label文本对齐方式选项 * fix: remark 支持在表单内配置 * style: form 间距对齐云社4.0 * 修改表单的字体 Co-authored-by: sarding <hongfuquan@baidu.com> * inputfile 和 drawer对齐云社4.0 (#4249) * fix: drawer 和 inputfile 关闭图标对齐云社4.0 * fix:修改 drawer的图标大小 和边框圆角 * drawer 样式调整 Co-authored-by: sarding <hongfuquan@baidu.com> * Fix style (#4265) * fix: input-password icon 高度 * fix: input-password icon 换行问题 Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * fix: curd 图标垂直居中 (#4271) Co-authored-by: liuzedong02 <liuzedong02@baidu.com> * fix:修复nestedSelect无法动态调整位置及溢出问题 (#4292) Co-authored-by: xujiahao01 <xujiahao01@baidu.com> * style: 优化switch组件动效 (#4302) * style:优化date组件最小宽度 (#4303) * style:cxd主题移动端基础字号调整为16px (#4305) * style:switch调整动效速度 * chore:更新快照 * chore:更新快照 Co-authored-by: xujiahao01 <xujiahao01@baidu.com> Co-authored-by: qiaogg <43558337+qiaogg@users.noreply.github.com> Co-authored-by: qiaoganggang <qiaoganggang@baidu.com> Co-authored-by: sansiro <sansiro@sansiro.me> Co-authored-by: liuzedong02 <liuzedong02@baidu.com> Co-authored-by: liweijian <liweijian@hkmtl.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com> Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Co-authored-by: sarding <37691952+sarding@users.noreply.github.com> Co-authored-by: sarding <hongfuquan@baidu.com> Co-authored-by: 徐佳豪 <53201551+blue-squirrel@users.noreply.github.com> Co-authored-by: HongYang <33488114+hy993658052@users.noreply.github.com> Co-authored-by: hongyang03 <hongyang03@baidu.com>
2022-05-18 10:03:56 +08:00
await wait(300);
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=drawer default', async () => {
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'OpenDrawer',
actionType: 'drawer',
drawer: {
body: 'this is drawer'
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
]
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('OpenDrawer')).toBeInTheDocument();
});
fireEvent.click(getByText(/OpenDrawer/));
await waitFor(() => {
expect(getByText('取消')).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/取消/));
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=drawer mergeData', async () => {
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'OpenDrawer',
actionType: 'drawer',
drawer: {
actions: [
{
label: '确认',
type: 'submit',
mergeData: true
2019-04-30 11:11:25 +08:00
}
],
body: {
type: 'form',
controls: [
{
label: 'A',
type: 'text',
value: '3',
name: 'a'
}
]
}
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
],
body: 'The variable a is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('OpenDrawer')).toBeInTheDocument();
});
fireEvent.click(getByText('OpenDrawer'));
await waitFor(() => {
expect(
container.querySelector('[name="a"][value="3"]')
).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/确认/));
await wait(300);
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=ajax', async () => {
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 6
2019-04-30 11:11:25 +08:00
}
}
})
);
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'RequestAjax',
actionType: 'ajax',
api: '/doxxx'
}
2019-04-30 11:11:25 +08:00
],
body: 'The variable a is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher,
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('RequestAjax')).toBeInTheDocument();
});
fireEvent.click(getByText(/RequestAjax/));
await waitFor(() => {
expect(getByText('The variable a is 6')).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=copy', async () => {
const copy = jest.fn();
const {getByText} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'CopyContent',
actionType: 'copy',
content: 'the content is ${a}'
}
2019-04-30 11:11:25 +08:00
]
},
{
2019-04-30 11:11:25 +08:00
data: {
a: 1
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
copy
})
)
);
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/CopyContent/));
await wait(300);
expect(copy).toHaveBeenCalled();
expect(copy.mock.calls[0][0]).toEqual('the content is 1');
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page handleAction actionType=ajax & feedback', async () => {
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: 6
2019-04-30 11:11:25 +08:00
}
}
})
);
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: [
{
type: 'button',
label: 'RequestAjax',
actionType: 'ajax',
api: '/doxxx',
feedback: {
body: 'this is feedback'
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
],
body: 'The variable a is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher,
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/RequestAjax/));
await waitFor(() => {
expect(getByText('确认')).toBeInTheDocument();
});
2023-04-07 11:04:18 +08:00
await wait(300);
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/确认/));
await wait(300);
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi reFetch when condition changes', async () => {
let count = 1;
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: count++
2019-04-30 11:11:25 +08:00
}
}
})
);
const history = createMemoryHistory({
initialEntries: ['/xxx']
});
const component = renderer.create(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{
location: history.location as any
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
await wait(300);
expect(component.toJSON()).toMatchSnapshot();
history.push('/xxxx?id=1');
2019-04-30 11:11:25 +08:00
component.update(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{
location: history.location as any
},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
2019-04-30 11:11:25 +08:00
await wait(500);
expect(fetcher).toHaveBeenCalledTimes(2);
expect(component.toJSON()).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi reload by action', async () => {
let count = 1;
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: count++
2019-04-30 11:11:25 +08:00
}
}
})
);
const {container, getByText, rerender} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
name: 'thepage',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
toolbar: {
type: 'button',
label: 'Reload',
actionType: 'reload',
target: 'thepage'
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher
})
)
);
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('The variable value is 1')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/Reload/));
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('The variable value is 2')).toBeInTheDocument();
});
expect(fetcher).toHaveBeenCalledTimes(2);
expect(container).toMatchSnapshot();
});
2019-04-30 11:11:25 +08:00
test('Renderer:Page Tpl JumpTo', async () => {
const jumpTo = jest.fn();
const {getByText} = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
toolbar: ['<a data-link="/goToPath?a=${a}">JumpTo</a>']
},
{
2019-04-30 11:11:25 +08:00
data: {
a: 1
2019-04-30 11:11:25 +08:00
}
},
makeEnv({
2019-04-30 11:11:25 +08:00
jumpTo
})
)
);
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/JumpTo/));
await wait(300);
expect(jumpTo).toHaveBeenCalled();
expect(jumpTo.mock.calls[0][0]).toEqual('/goToPath?a=1');
2019-04-30 11:11:25 +08:00
});
test('Renderer:Page initApi reload by Dialog action', async () => {
let count = 1;
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: count++
2019-04-30 11:11:25 +08:00
}
}
})
);
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
name: 'thepage',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
toolbar: {
type: 'button',
label: 'OpenDialog',
actionType: 'dialog',
reload: 'thepage',
dialog: {
body: {
type: 'form',
controls: [
{
type: 'text',
name: 'a',
value: '3'
2019-04-30 11:11:25 +08:00
}
]
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher,
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('The variable value is 1')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/OpenDialog/));
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText(/确认/)).toBeInTheDocument();
});
expect(container).toMatchSnapshot();
fireEvent.click(getByText(/确认/));
await wait(500);
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
expect(getByText('The variable value is 2')).toBeInTheDocument();
});
2019-04-30 11:11:25 +08:00
expect(container).toMatchSnapshot();
expect(fetcher).toHaveBeenCalledTimes(2);
});
2019-04-30 11:11:25 +08:00
test('Renderer:Page initApi reload by Drawer action', async () => {
let count = 1;
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: count++
2019-04-30 11:11:25 +08:00
}
}
})
);
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
name: 'thepage',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
toolbar: {
type: 'button',
label: 'OpenDialog',
actionType: 'drawer',
reload: 'thepage',
drawer: {
body: {
type: 'form',
controls: [
{
type: 'text',
name: 'a',
value: '3'
2019-04-30 11:11:25 +08:00
}
]
2019-04-30 11:11:25 +08:00
}
}
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher,
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText('The variable value is 1')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/OpenDialog/));
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText(/确认/)).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
fireEvent.click(getByText(/确认/));
await waitFor(() => {
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
expect(getByText('The variable value is 2')).toBeInTheDocument();
});
2019-04-30 11:11:25 +08:00
expect(container).toMatchSnapshot();
expect(fetcher).toHaveBeenCalledTimes(2);
});
2019-04-30 11:11:25 +08:00
test('Renderer:Page initApi reload by Form submit', async () => {
let count = 1;
const fetcher = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
status: 0,
msg: 'ok',
2019-04-30 11:11:25 +08:00
data: {
a: count++
2019-04-30 11:11:25 +08:00
}
}
})
);
let container: HTMLElement;
const renderResult: any = render(
amisRender(
{
2019-04-30 11:11:25 +08:00
type: 'page',
name: 'thepage',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}'
2019-04-30 11:11:25 +08:00
},
toolbar: {
type: 'form',
target: 'thepage',
controls: [
{
type: 'text',
name: 'a',
value: '3'
}
],
actions: [
{
type: 'submit',
label: 'Submit'
}
]
2019-04-30 11:11:25 +08:00
},
body: 'The variable value is ${a}'
},
{},
makeEnv({
2019-04-30 11:11:25 +08:00
fetcher,
getModalContainer: () => container
})
)
);
const getByText = renderResult.getByText;
container = renderResult.container;
2019-04-30 11:11:25 +08:00
await waitFor(() => {
expect(getByText(/Submit/)).toBeInTheDocument();
expect(getByText('The variable value is 1')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
2019-04-30 11:11:25 +08:00
fireEvent.click(getByText(/Submit/));
await waitFor(() => {
expect(getByText('The variable value is 2')).toBeInTheDocument();
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot();
expect(fetcher).toHaveBeenCalledTimes(2);
});