test(all): 测试用例

This commit is contained in:
RubyLiu 2023-06-01 18:22:51 +08:00 committed by rubylliu
parent 9b1c1abb64
commit 84a022e862
5 changed files with 103 additions and 38 deletions

2
frontend/.gitignore vendored
View File

@ -7,4 +7,4 @@ coverage
.node/ .node/
package-lock.json package-lock.json
pnpm-lock.yaml pnpm-lock.yaml
yarn.lock yarn.lock

View File

@ -1,32 +0,0 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true, // stylelint
},
"editor.formatOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"vue",
"markdown",
"json",
"jsonc"
],
// stylelint
"stylelint.validate": [
"css",
"less",
"postcss",
"scss",
"sass",
"vue"
],
"stylelint.enable": true,
"css.validate": false,
"less.validate": false,
"scss.validate": false,
}

View File

@ -0,0 +1,95 @@
import { mount } from '@vue/test-utils';
import { describe, expect, test } from 'vitest';
import MsBaseTable from '@/components/ms-table/base-table.vue';
import { nextTick } from 'vue';
import { MsTableColumn } from '@/components/ms-table/type';
import useTable from '@/components/ms-table/useTable';
import { getTableList } from '@/api/modules/api-test/index';
const columns: MsTableColumn = [
{
title: 'ID',
dataIndex: 'num',
},
{
title: '接口名称',
dataIndex: 'name',
},
{
title: '请求类型',
dataIndex: 'method',
},
{
title: '责任人',
dataIndex: 'username',
},
{
title: '路径',
dataIndex: 'path',
},
{
title: '标签',
dataIndex: 'tags',
},
{
title: '更新时间',
slotName: 'updataTime',
},
{
title: '用例数',
dataIndex: 'caseTotal',
},
{
title: '用例状态',
dataIndex: 'caseStatus',
},
{
title: '用例通过率',
dataIndex: 'casePassingRate',
},
{
title: '接口状态',
dataIndex: 'status',
},
{
title: '创建时间',
slotName: 'createTime',
},
{
title: '描述',
dataIndex: 'description',
},
{
title: '操作',
slotName: 'action',
fixed: 'right',
width: 200,
},
];
describe('MS-Table', () => {
test('init table with useTable', async () => {
const { propsRes, propsEvent, loadList, setProps } = useTable(getTableList, {
columns,
pagination: { current: 1, pageSize: 1 },
});
const wrapper = mount(MsBaseTable, {
vOn: propsEvent,
vBind: propsRes,
});
loadList();
await nextTick();
let content = wrapper.find('.arco-table-td-content').element.innerHTML;
expect(propsRes.value.data.length).toBe(2);
expect(content).toBe('e7bd7179-d63a-43a5-1a65-218473ee69ca');
setProps({ pagination: { current: 2, pageSize: 1 } });
loadList();
await nextTick();
content = wrapper.find('.arco-table-td-content').element.innerHTML;
expect(content).toBe('937be890-79bb-1b68-e03e-7d37a8b0a607');
});
});

View File

@ -20,11 +20,11 @@ export interface QueryParams {
} }
type GetListFunc = (v: QueryParams) => Promise<CommonReponse<ApiTestListI>>; type GetListFunc = (v: QueryParams) => Promise<CommonReponse<ApiTestListI>>;
export default function useTbleProps(loadListFunc: GetListFunc, props?: MsTabelProps) { export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial<MsTabelProps>) {
const defaultProps: MsTabelProps = { const defaultProps: MsTabelProps = {
'bordered': true, 'bordered': true,
'size': 'small', 'size': 'small',
'scroll': { y: 550, x: '100%' }, 'scroll': { y: 550, x: '1400px' },
'expandable': false, 'expandable': false,
'loading': true, 'loading': true,
'data': [] as MsTableData, 'data': [] as MsTableData,
@ -67,10 +67,12 @@ export default function useTbleProps(loadListFunc: GetListFunc, props?: MsTabelP
}; };
// 单独设置默认属性 // 单独设置默认属性
const setProps = (params: MsTabelProps) => { const setProps = (params: Partial<MsTabelProps>) => {
const tmpProps = propsRes.value;
Object.keys(params).forEach((key) => { Object.keys(params).forEach((key) => {
defaultProps[key] = params[key]; tmpProps[key] = params[key];
}); });
propsRes.value = tmpProps;
}; };
// 设置请求参数,如果出了分页参数还有搜索参数,在模板页面调用此方法,可以加入参数 // 设置请求参数,如果出了分页参数还有搜索参数,在模板页面调用此方法,可以加入参数

View File

@ -79,7 +79,7 @@
}, },
]; ];
const { propsRes, propsEvent, loadList } = useTable(getTableList, { columns, data: [] }); const { propsRes, propsEvent, loadList } = useTable(getTableList, { columns, scroll: { x: 2000 } });
const fetchData = async () => { const fetchData = async () => {
await loadList(); await loadList();