amis/__tests__/renderers/Table.test.tsx

649 lines
17 KiB
TypeScript
Raw Normal View History

import React = require('react');
import {render} from '@testing-library/react';
import '../../src/themes/default';
import {render as amisRender} from '../../src/index';
import {makeEnv} from '../helper';
import rows from '../mockData/rows';
test('Renderer:table', () => {
const {container} = render(
amisRender(
{
type: 'table',
title: '表格1',
data: {
items: rows
},
columns: [
{
name: 'engine',
label: 'Engine'
},
{
name: 'version',
label: 'Version'
}
]
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table align', () => {
const {container} = render(
amisRender(
{
type: 'table',
title: '表格1',
data: {
items: rows
},
columns: [
{
name: 'engine',
label: 'Engine'
},
{
name: 'version',
type: 'tpl',
tpl: '${version | number}',
align: 'right'
}
]
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table classNameExpr', () => {
const {container} = render(
amisRender(
{
type: 'table',
title: '表格1',
data: {
items: rows
},
columns: [
{
name: 'engine',
label: 'Engine'
},
{
name: 'version',
label: 'Version',
classNameExpr: "<%= data.version > 5 ? 'text-danger' : '' %>"
}
]
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table isHead fixed', () => {
const {container} = render(
amisRender(
{
type: 'table',
title: '表格1',
data: {
items: rows
},
columnsTogglable: false,
columns: [
{
name: 'engine',
label: 'Engine',
isHead: true
},
{
name: 'platform',
label: 'Platform',
fixed: 'right'
}
]
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table children', () => {
const {container} = render(
amisRender(
{
type: 'page',
body: {
type: 'service',
data: {
rows: [
{
engine: 'Trident',
browser: 'Internet Explorer 4.0',
platform: 'Win 95+',
version: '4',
grade: 'X',
id: 1,
children: [
{
engine: 'Trident',
browser: 'Internet Explorer 4.0',
platform: 'Win 95+',
version: '4',
grade: 'X',
id: 1001
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.0',
platform: 'Win 95+',
version: '5',
grade: 'C',
id: 1002
}
]
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.0',
platform: 'Win 95+',
version: '5',
grade: 'C',
id: 2,
children: [
{
engine: 'Trident',
browser: 'Internet Explorer 4.0',
platform: 'Win 95+',
version: '4',
grade: 'X',
id: 2001
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.0',
platform: 'Win 95+',
version: '5',
grade: 'C',
id: 2002
}
]
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.5',
platform: 'Win 95+',
version: '5.5',
grade: 'A',
id: 3,
children: [
{
engine: 'Trident',
browser: 'Internet Explorer 4.0',
platform: 'Win 95+',
version: '4',
grade: 'X',
id: 3001
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.0',
platform: 'Win 95+',
version: '5',
grade: 'C',
id: 3002
}
]
},
{
engine: 'Trident',
browser: 'Internet Explorer 6',
platform: 'Win 98+',
version: '6',
grade: 'A',
id: 4,
children: [
{
engine: 'Trident',
browser: 'Internet Explorer 4.0',
platform: 'Win 95+',
version: '4',
grade: 'X',
id: 4001
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.0',
platform: 'Win 95+',
version: '5',
grade: 'C',
id: 4002
}
]
},
{
engine: 'Trident',
browser: 'Internet Explorer 7',
platform: 'Win XP SP2+',
version: '7',
grade: 'A',
id: 5,
children: [
{
engine: 'Trident',
browser: 'Internet Explorer 4.0',
platform: 'Win 95+',
version: '4',
grade: 'X',
id: 5001
},
{
engine: 'Trident',
browser: 'Internet Explorer 5.0',
platform: 'Win 95+',
version: '5',
grade: 'C',
id: 5002
}
]
}
]
},
body: [
{
type: 'table',
source: '$rows',
className: 'm-b-none',
columnsTogglable: false,
columns: [
{
name: 'engine',
label: 'Engine'
},
{
name: 'grade',
label: 'Grade'
},
{
name: 'version',
label: 'Version'
},
{
name: 'browser',
label: 'Browser'
},
{
name: 'id',
label: 'ID'
},
{
name: 'platform',
label: 'Platform'
}
]
}
]
}
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table combineNum', () => {
const {container} = render(
amisRender(
{
type: 'page',
body: {
type: 'service',
data: {
rows
},
body: [
{
type: 'table',
source: '$rows',
className: 'm-b-none',
combineNum: 3,
columnsTogglable: false,
columns: [
{
name: 'engine',
label: 'Rendering engine'
},
{
name: 'browser',
label: 'Browser'
},
{
name: 'platform',
label: 'Platform(s)'
},
{
name: 'version',
label: 'Engine version'
},
{
name: 'grade',
label: 'CSS grade'
}
]
}
]
}
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table group', () => {
const {container} = render(
amisRender(
{
type: 'table',
title: '表格1',
data: {
items: rows
},
columnsTogglable: false,
columns: [
{
name: 'engine',
label: 'Engine',
isHead: true
},
{
name: 'platform',
label: 'Platform',
fixed: 'right'
}
]
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});
test('Renderer:table list', () => {
const {container} = render(
amisRender(
{
type: 'table',
data: {
items: [
{
id: '91264',
text: '衡 阎',
progress: 22,
type: 4,
boolean: true,
list: [
{
title: 'Forward Functionality Technician',
description: 'nisi ex eum'
},
{
title: 'District Applications Specialist',
description: 'ipsam ratione voluptas'
},
{
title: 'Future Operations Manager',
description: 'ducimus fugit debitis'
},
{
title: 'Dynamic Solutions Associate',
description: 'saepe consequatur aut'
}
],
audio:
'https://news-bos.cdn.bcebos.com/mvideo/%E7%9A%87%E5%90%8E%E5%A4%A7%E9%81%93%E4%B8%9C.aac',
carousel: [
{
image:
'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg'
},
{
html: '<div style="width: 100%; height: 200px; background: #e3e3e3; text-align: center; line-height: 200px;">carousel data in crud</div>'
},
{
image: 'https://video-react.js.org/assets/poster.png'
}
],
date: 1591270438,
image:
'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg',
json: {
id: 1,
text: 'text'
}
},
{
id: '34202',
text: '吉 卢汉市',
progress: 85,
type: 1,
boolean: true,
list: [
{
title: 'Dynamic Assurance Orchestrator',
description: 'ea ullam voluptates'
},
{
title: 'Internal Division Assistant',
description: 'illum deleniti qui'
},
{
title: 'International Usability Administrator',
description: 'sit voluptatem quia'
},
{
title: 'Lead Optimization Orchestrator',
description: 'autem et blanditiis'
},
{
title: 'Future Division Assistant',
description: 'dolor cupiditate sint'
},
{
title: 'Forward Program Orchestrator',
description: 'quia distinctio voluptas'
},
{
title: 'Human Implementation Technician',
description: 'consequatur quaerat ullam'
},
{
title: 'National Identity Administrator',
description: 'ipsa et reiciendis'
},
{
title: 'Regional Factors Planner',
description: 'sed deserunt natus'
},
{
title: 'Human Data Administrator',
description: 'rerum consequatur odit'
}
],
audio:
'https://news-bos.cdn.bcebos.com/mvideo/%E7%9A%87%E5%90%8E%E5%A4%A7%E9%81%93%E4%B8%9C.aac',
carousel: [
{
image:
'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg'
},
{
html: '<div style="width: 100%; height: 200px; background: #e3e3e3; text-align: center; line-height: 200px;">carousel data in crud</div>'
},
{
image: 'https://video-react.js.org/assets/poster.png'
}
],
date: 1591270438,
image:
'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg',
json: {
id: 1,
text: 'text'
}
},
{
id: '37701',
text: '立辉安市',
progress: 72,
type: 2,
boolean: false,
list: [
{
title: 'Corporate Metrics Liason',
description: 'aspernatur natus qui'
},
{
title: 'Central Paradigm Analyst',
description: 'sequi numquam ad'
},
{
title: 'International Data Administrator',
description: 'sed libero eum'
},
{
title: 'Forward Optimization Assistant',
description: 'officiis accusantium dolorem'
},
{
title: 'Senior Metrics Executive',
description: 'commodi sint quod'
},
{
title: 'Corporate Quality Facilitator',
description: 'aut aperiam est'
},
{
title: 'Forward Operations Producer',
description: 'sed corporis eaque'
},
{
title: 'National Integration Analyst',
description: 'quasi ab cumque'
}
],
audio:
'https://news-bos.cdn.bcebos.com/mvideo/%E7%9A%87%E5%90%8E%E5%A4%A7%E9%81%93%E4%B8%9C.aac',
carousel: [
{
image:
'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg'
},
{
html: '<div style="width: 100%; height: 200px; background: #e3e3e3; text-align: center; line-height: 200px;">carousel data in crud</div>'
},
{
image: 'https://video-react.js.org/assets/poster.png'
}
],
date: 1591270438,
image:
'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3893101144,2877209892&fm=23&gp=0.jpg',
json: {
id: 1,
text: 'text'
}
}
]
},
affixHeader: false,
syncLocation: false,
columns: [
{
name: 'id',
label: 'ID',
type: 'text'
},
{
name: 'text',
label: '文本',
type: 'text'
},
{
type: 'image',
label: '图片',
name: 'image'
},
{
name: 'date',
type: 'date',
label: '日期'
},
{
name: 'progress',
label: '进度',
type: 'progress'
},
{
name: 'boolean',
label: '状态',
type: 'status'
},
{
name: 'boolean',
label: '开关',
type: 'switch'
},
{
name: 'type',
label: '映射',
type: 'mapping',
map: {
'1': "<span class='label label-info'>漂亮</span>",
'2': "<span class='label label-success'>开心</span>",
'3': "<span class='label label-danger'>惊吓</span>",
'4': "<span class='label label-warning'>紧张</span>",
'*': '其他:${type}'
}
},
{
name: 'list',
type: 'list',
label: 'List',
placeholder: '-',
listItem: {
title: '${title}',
subTitle: '${description}'
}
}
]
},
{},
makeEnv({})
)
);
expect(container).toMatchSnapshot();
});