41 lines
1.5 KiB
JavaScript
41 lines
1.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 page = fs.readFileSync(path.join(__dirname, '../../src/views/goauto/syb-inner-codes/index.vue'), 'utf8')
|
|
const source = page.split('<script>')[1].split('</script>')[0].replace(/^import .*$/gm, '').replace('export default', 'return')
|
|
const options = new Function(source)()
|
|
|
|
test('inner code page defaults to 200 and keeps a manual size through search and clear', async () => {
|
|
const vm = { ...options.data(), ...options.methods }
|
|
const requests = []
|
|
vm.load = async () => { requests.push({ ...vm.query }) }
|
|
|
|
const now = new Date()
|
|
const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`
|
|
assert.equal(vm.query.page, 1)
|
|
assert.equal(vm.query.pageSize, 200)
|
|
assert.deepEqual(vm.dateRange, [today, today])
|
|
assert.match(page, /:page-sizes="\[20, 50, 100, 200\]"/)
|
|
|
|
vm.query.pageSize = 50
|
|
vm.query.page = 4
|
|
vm.query.keyword = 'code'
|
|
vm.dateRange = ['2026-10-01', '2026-10-02']
|
|
await vm.search()
|
|
assert.equal(requests[0].page, 1)
|
|
assert.equal(requests[0].pageSize, 50)
|
|
|
|
vm.query.page = 3
|
|
await vm.clearFilters()
|
|
assert.equal(requests[1].page, 1)
|
|
assert.equal(requests[1].pageSize, 50)
|
|
assert.equal(requests[1].keyword, '')
|
|
assert.equal(requests[1].dateFrom, '')
|
|
assert.equal(requests[1].dateTo, '')
|
|
|
|
const freshVm = { ...options.data() }
|
|
assert.equal(freshVm.query.pageSize, 200)
|
|
})
|