1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
| import assert from 'node:assert/strict'
| import test from 'node:test'
|
| import {
| buildListExportPayload,
| buildPrintPageQuery,
| toExportColumns
| } from '../src/components/biz/list-export-print/list-export-print.helpers.js'
|
| test('selected rows keep export payload on ids only instead of flat query params', () => {
| const payload = buildListExportPayload({
| reportTitle: '角色管理报表',
| selectedRows: [{ id: 7 }, { id: 9 }],
| queryParams: { current: 1, pageSize: 20, name: '管理员', code: 'R_ADMIN' },
| columns: [{ prop: 'name', label: '角色名称' }]
| })
|
| assert.deepEqual(payload.ids, [7, 9])
| assert.deepEqual(payload.columns, [{ source: 'name', label: '角色名称' }])
| assert.equal(payload.meta.reportTitle, '角色管理报表')
| assert.deepEqual(
| Object.keys(payload).filter((key) => ['current', 'pageSize', 'name', 'code', 'queryParams'].includes(key)),
| []
| )
| })
|
| test('export columns use ListExportService source/label contract only', () => {
| assert.deepEqual(
| toExportColumns([
| { prop: 'name', label: '角色名称' },
| { prop: 'operation', label: '操作' },
| { prop: 'selection', label: '勾选' }
| ]),
| [{ source: 'name', label: '角色名称' }]
| )
| })
|
| test('export payload keeps no-filter searches legal as flat params', () => {
| const payload = buildListExportPayload({
| reportTitle: '角色管理报表',
| selectedRows: [],
| queryParams: { current: 1, pageSize: 20 },
| columns: [{ prop: 'name', label: '角色名称' }]
| })
|
| assert.equal(payload.current, 1)
| assert.equal(payload.pageSize, 20)
| assert.equal(payload.meta.reportTitle, '角色管理报表')
| assert.deepEqual(payload.ids, [])
| assert.equal(Object.prototype.hasOwnProperty.call(payload, 'queryParams'), false)
| })
|
| test('export payload preserves report style meta and column align without top-level reportStyle', () => {
| const payload = buildListExportPayload({
| reportTitle: '角色管理报表',
| meta: {
| reportStyle: {
| orientation: 'landscape',
| density: 'comfortable'
| }
| },
| columns: [{ prop: 'name', label: '角色名称', align: 'right' }]
| })
|
| assert.deepEqual(payload.meta.reportStyle, {
| orientation: 'landscape',
| density: 'comfortable'
| })
| assert.equal(payload.columns[0].align, 'right')
| assert.equal(Object.prototype.hasOwnProperty.call(payload, 'reportStyle'), false)
| })
|
| test('print query expands to the full result set instead of the current page size', () => {
| assert.deepEqual(
| buildPrintPageQuery({
| queryParams: { current: 3, pageSize: 20, orderBy: 'createTime desc', name: '管理员' },
| total: 86,
| maxResults: 1000
| }),
| {
| current: 1,
| pageSize: 86,
| orderBy: 'createTime desc',
| name: '管理员'
| }
| )
| })
|
| test('print query caps pageSize at maxResults when total is larger', () => {
| assert.deepEqual(
| buildPrintPageQuery({
| queryParams: { current: 5, pageSize: 20, orderBy: 'createTime desc', code: 'R_ADMIN' },
| total: 1500,
| maxResults: 1000
| }),
| {
| current: 1,
| pageSize: 1000,
| orderBy: 'createTime desc',
| code: 'R_ADMIN'
| }
| )
| })
|
|