diff --git a/frontend/.gitignore b/frontend/.gitignore index 2c150d3410..d70f6e55fd 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -7,4 +7,4 @@ coverage .node/ package-lock.json pnpm-lock.yaml -yarn.lock +yarn.lock \ No newline at end of file diff --git a/frontend/.vscode/settings.json b/frontend/.vscode/settings.json deleted file mode 100644 index a5d4a92c72..0000000000 --- a/frontend/.vscode/settings.json +++ /dev/null @@ -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, -} \ No newline at end of file diff --git a/frontend/src/__test__/table.spec.ts b/frontend/src/__test__/table.spec.ts new file mode 100644 index 0000000000..1670df1918 --- /dev/null +++ b/frontend/src/__test__/table.spec.ts @@ -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'); + }); +}); diff --git a/frontend/src/components/ms-table/useTable.ts b/frontend/src/components/ms-table/useTable.ts index a4660b7a92..3167fbec8f 100644 --- a/frontend/src/components/ms-table/useTable.ts +++ b/frontend/src/components/ms-table/useTable.ts @@ -20,11 +20,11 @@ export interface QueryParams { } type GetListFunc = (v: QueryParams) => Promise>; -export default function useTbleProps(loadListFunc: GetListFunc, props?: MsTabelProps) { +export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial) { const defaultProps: MsTabelProps = { 'bordered': true, 'size': 'small', - 'scroll': { y: 550, x: '100%' }, + 'scroll': { y: 550, x: '1400px' }, 'expandable': false, 'loading': true, 'data': [] as MsTableData, @@ -67,10 +67,12 @@ export default function useTbleProps(loadListFunc: GetListFunc, props?: MsTabelP }; // 单独设置默认属性 - const setProps = (params: MsTabelProps) => { + const setProps = (params: Partial) => { + const tmpProps = propsRes.value; Object.keys(params).forEach((key) => { - defaultProps[key] = params[key]; + tmpProps[key] = params[key]; }); + propsRes.value = tmpProps; }; // 设置请求参数,如果出了分页参数还有搜索参数,在模板页面调用此方法,可以加入参数 diff --git a/frontend/src/views/api-test/index.vue b/frontend/src/views/api-test/index.vue index a48ef6bc24..c9e55ea030 100644 --- a/frontend/src/views/api-test/index.vue +++ b/frontend/src/views/api-test/index.vue @@ -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 () => { await loadList();