20260917165839
This commit is contained in:
1 parent
182ed86966
commit
38e1e66c3b
108 files changed
+2497
-1215
No files matched your search
@@ -2,7 +2,7 @@
|
||||
* FmsModuleListPage 冒烟测试(V2:元数据来自 s_field + s_module_schema JSON)。
|
||||
* 验证:按模块编码加载字段与 view/query 界面配置后,能正常渲染数据列、无配置错误。
|
||||
*/
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { nextTick } from 'vue'
|
||||
@@ -20,6 +20,13 @@ const querySchema = {
|
||||
quick: ['b_name'],
|
||||
groups: [{ logic: 'and', conditions: [{ field: 'b_name', operator: 'like' }] }],
|
||||
}
|
||||
let withSummary = false
|
||||
|
||||
vi.mock('@/services/exportService', () => ({
|
||||
exportListApi: vi.fn(async () => 'data.xlsx'),
|
||||
loadTotalsApi: vi.fn(async () => ({ data: { b_amount: 120.5 } })),
|
||||
countExportApi: vi.fn(async () => ({ data: { total: 5 } })),
|
||||
}))
|
||||
|
||||
vi.mock('@/services/api', () => ({
|
||||
loadDataApi: vi.fn(async (viewName) => {
|
||||
@@ -42,6 +49,7 @@ vi.mock('@/services/api', () => ({
|
||||
data: [
|
||||
{ b_field: 'b_id', b_name: '语言编码', b_type: 'input', b_canuse: 1, b_i18n: null },
|
||||
{ b_field: 'b_name', b_name: '语言名称', b_type: 'input', b_canuse: 1, b_i18n: null },
|
||||
{ b_field: 'b_amount', b_name: '金额', b_type: 'money', b_canuse: 1 },
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -56,6 +64,7 @@ vi.mock('@/services/api', () => ({
|
||||
columns: [
|
||||
{ field: 'b_id', width: 120 },
|
||||
{ field: 'b_name', width: 180 },
|
||||
...(withSummary ? [{ field: 'b_amount', width: 120, summary: 'sum' }] : []),
|
||||
],
|
||||
}),
|
||||
},
|
||||
@@ -79,10 +88,15 @@ vi.mock('@/services/api', () => ({
|
||||
|
||||
import FmsModuleListPage from '@/components/fms-module-list/FmsModuleListPage.vue'
|
||||
import { pageDataApi } from '@/services/api'
|
||||
import { exportListApi, loadTotalsApi } from '@/services/exportService'
|
||||
import { Pagination } from '@/components/ui'
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
pageDataApi.mockClear()
|
||||
exportListApi.mockClear()
|
||||
loadTotalsApi.mockClear()
|
||||
withSummary = false
|
||||
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
|
||||
configurable: true,
|
||||
get() {
|
||||
@@ -101,6 +115,79 @@ const lastCondition = () =>
|
||||
pageDataApi.mock.calls[pageDataApi.mock.calls.length - 1][0].searchCondition
|
||||
|
||||
describe('FmsModuleListPage 冒烟', () => {
|
||||
it('配置合计后底层表格显示当页及总合计,翻页导出使用当前区间', async () => {
|
||||
withSummary = true
|
||||
pageDataApi.mockResolvedValueOnce({
|
||||
data: {
|
||||
rows: [
|
||||
{ b_id: '1', b_amount: 10.2 },
|
||||
{ b_id: '2', b_amount: 20.3 },
|
||||
],
|
||||
total: 5,
|
||||
},
|
||||
})
|
||||
const wrapper = mount(FmsModuleListPage, {
|
||||
props: { dataCode: 's_i18n_type', pageSize: 2, fixedSearchCondition: 'b_canuse = 1' },
|
||||
attachTo: document.body,
|
||||
})
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.stk-footer').text()).toContain('该页合计')
|
||||
expect(wrapper.find('.stk-footer').text()).toContain('30.50')
|
||||
expect(wrapper.find('.stk-footer').text()).toContain('总合计')
|
||||
expect(wrapper.find('.stk-footer').text()).toContain('120.50')
|
||||
expect(loadTotalsApi).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ searchCondition: '(b_canuse = 1)' }),
|
||||
)
|
||||
|
||||
pageDataApi.mockResolvedValueOnce({
|
||||
data: {
|
||||
rows: [
|
||||
{ b_id: '3', b_amount: 40 },
|
||||
{ b_id: '4', b_amount: 25 },
|
||||
],
|
||||
total: 5,
|
||||
},
|
||||
})
|
||||
wrapper.findComponent(Pagination).vm.$emit('change', 2, 2)
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.stk-footer').text()).toContain('65.00')
|
||||
await wrapper.find('button[title="导出当页数据;勾选行则只导出勾选"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(exportListApi).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
rangeStart: 3,
|
||||
rangeEnd: 4,
|
||||
columns: ['b_id', 'b_name', 'b_amount'],
|
||||
searchCondition: '(b_canuse = 1)',
|
||||
orderBy: 'b_id DESC',
|
||||
}),
|
||||
)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('勾选导出不叠加当前页范围,空页不发送非法导出区间', async () => {
|
||||
const wrapper = mount(FmsModuleListPage, {
|
||||
props: { dataCode: 's_i18n_type', rowSelection: { selectedRowKeys: ['a', 'b'] } },
|
||||
attachTo: document.body,
|
||||
})
|
||||
await flushPromises()
|
||||
const button = () => wrapper.find('button[title="导出当页数据;勾选行则只导出勾选"]')
|
||||
await button().trigger('click')
|
||||
await flushPromises()
|
||||
expect(exportListApi).toHaveBeenLastCalledWith(expect.objectContaining({ rowKeys: ['a', 'b'] }))
|
||||
expect(exportListApi.mock.calls.at(-1)[0]).not.toHaveProperty('rangeStart')
|
||||
await wrapper.setProps({ rowSelection: null })
|
||||
pageDataApi.mockResolvedValueOnce({ data: { rows: [], total: 0 } })
|
||||
await wrapper.vm.reload()
|
||||
await flushPromises()
|
||||
exportListApi.mockClear()
|
||||
await button().trigger('click')
|
||||
await flushPromises()
|
||||
expect(exportListApi).not.toHaveBeenCalled()
|
||||
expect(loadTotalsApi).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('按 data-code 加载字段与界面配置后渲染列,无配置错误', async () => {
|
||||
const wrapper = mount(FmsModuleListPage, {
|
||||
props: { dataCode: 's_i18n_type' },
|
||||
|
||||
Reference in new issue
Block a user