build / task (16.x, npm, macOS-latest) (push) Canceled after 0s
build / task (16.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, npm, windows-latest) (push) Canceled after 0s
build / task (16.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (16.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (16.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (16.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, yarn, windows-latest) (push) Canceled after 0s
build / task (18.x, npm, macOS-latest) (push) Canceled after 0s
build / task (18.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, npm, windows-latest) (push) Canceled after 0s
build / task (18.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (18.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (18.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (18.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, yarn, windows-latest) (push) Canceled after 0s
build / task (20.x, npm, macOS-latest) (push) Canceled after 0s
build / task (20.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, npm, windows-latest) (push) Canceled after 0s
build / task (20.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (20.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (20.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (20.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, yarn, windows-latest) (push) Canceled after 0s
60 lines
3.5 KiB
JavaScript
60 lines
3.5 KiB
JavaScript
const { test } = require("node:test")
|
|
const assert = require("node:assert/strict")
|
|
const fs = require("node:fs")
|
|
const path = require("node:path")
|
|
const ts = require("typescript")
|
|
const vue = require("vue")
|
|
const { parse, compileScript, compileTemplate } = require("@vue/compiler-sfc")
|
|
const root = path.join(__dirname, "../src")
|
|
|
|
function load(source, mocks, globals = {}) {
|
|
const compiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021 } }).outputText
|
|
const mod = { exports: {} }
|
|
new Function("module", "exports", "require", ...Object.keys(globals), compiled)(mod, mod.exports,
|
|
key => key in mocks ? mocks[key] : require(key), ...Object.values(globals))
|
|
return mod.exports
|
|
}
|
|
|
|
test("电子钱包页面提交后台任务,保留筛选快照且不受当前列表页限制", async () => {
|
|
const requests = []
|
|
const progress = []
|
|
const submitted = { taskId: "a".repeat(32), redisKey: "wallet:export:manage", status: "PENDING" }
|
|
const request = options => { requests.push(options); return Promise.resolve({ data: submitted }) }
|
|
const tasks = load(fs.readFileSync(path.join(root, "api/asyncTask.ts"), "utf8"), { "/@/utils/request": { default: request } })
|
|
const api = load(fs.readFileSync(path.join(root, "api/wallet/wallet-manage.ts"), "utf8"), {
|
|
"/@/utils/request": { default: request }, "/@/api/asyncTask": tasks,
|
|
})
|
|
const hook = load(fs.readFileSync(path.join(root, "hooks/batchExport.ts"), "utf8"), {
|
|
vue, "/@/components/AsyncTaskProgress.vue": {},
|
|
"/@/hooks/message": { useMessage: () => ({ error: message => assert.fail(message) }) },
|
|
"/@/utils/exportDownload": {},
|
|
})
|
|
const descriptor = parse(fs.readFileSync(path.join(root, "views/wallet/wallet-manage/index.vue"), "utf8")).descriptor
|
|
assert.deepEqual(compileTemplate({ source: descriptor.template.content, filename: "wallet-manage.vue", id: "wallet-manage" }).errors, [])
|
|
const page = load(compileScript(descriptor, { id: "wallet-manage" }).content, {
|
|
vue, "/@/api/wallet/wallet-manage": api,
|
|
"/@/components/AsyncTaskProgress.vue": {}, "/@/hooks/batchExport": hook,
|
|
"/@/hooks/table": { useTable: state => {
|
|
state.pagination = { current: 3, size: 10 }
|
|
return { getDataList() {}, tableStyle: {} }
|
|
} },
|
|
"/@/hooks/message": {}, "/@/hooks/dict": { useDict: () => ({}) },
|
|
"/@/utils/formatMoney": {},
|
|
}, { ref: vue.ref, reactive: vue.reactive, defineAsyncComponent: vue.defineAsyncComponent })
|
|
const state = page.default.setup({}, { expose() {} })
|
|
state.exportProgressRef.value = { startSubmitting: name => progress.push(name), start: value => progress.push(value), submissionFailed: message => assert.fail(message) }
|
|
Object.assign(state.state.queryForm, { current: 3, size: 10, userId: "123", deptIds: ["456"], walletTypeId: "789", isInclude: false, leBalance: 100 })
|
|
const original = JSON.parse(JSON.stringify(state.state.queryForm))
|
|
await state.exportExcel()
|
|
assert.equal(requests.length, 1)
|
|
assert.equal(requests[0].url, "/wallet/wallet-manage/export-async")
|
|
assert.equal(requests[0].method, "post")
|
|
assert.deepEqual(requests[0].data, { userId: "123", deptIds: ["456"], walletTypeId: "789", isInclude: false, leBalance: 100 })
|
|
assert.deepEqual(JSON.parse(JSON.stringify(state.state.queryForm)), original)
|
|
assert.equal(state.exportTaskConfig.progressUrl, "/wallet/async-task/progress")
|
|
assert.equal(state.exportTaskConfig.redisKey, "wallet:export:manage")
|
|
assert.deepEqual(progress, ["电子钱包导出", submitted])
|
|
state.state.queryForm.deptIds.push("999")
|
|
assert.deepEqual(requests[0].data.deptIds, ["456"])
|
|
})
|