fix: clarify PDA quantity inputs
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readdir, readFile } from 'node:fs/promises'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { join, relative } from 'node:path'
|
||||
|
||||
const sourceRoot = fileURLToPath(new URL('../src', import.meta.url))
|
||||
|
||||
async function vueFiles(directory) {
|
||||
const entries = await readdir(directory, { withFileTypes: true })
|
||||
const files = []
|
||||
for (const entry of entries) {
|
||||
if (entry.name === 'uni_modules') continue
|
||||
const path = join(directory, entry.name)
|
||||
if (entry.isDirectory()) files.push(...await vueFiles(path))
|
||||
else if (entry.name.endsWith('.vue')) files.push(path)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
test('every editable PDA input and textarea provides an input hint', async () => {
|
||||
const missing = []
|
||||
for (const file of await vueFiles(sourceRoot)) {
|
||||
const source = await readFile(file, 'utf8')
|
||||
for (const match of source.matchAll(/<(input|textarea)\b[^>]*>/gs)) {
|
||||
if (!/\s:?placeholder\s*=/.test(match[0])) {
|
||||
const line = source.slice(0, match.index).split('\n').length
|
||||
missing.push(`${relative(sourceRoot, file)}:${line}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.deepEqual(missing, [], `缺少 placeholder:${missing.join(', ')}`)
|
||||
})
|
||||
|
||||
test('quantity inputs explain the valid package range', async () => {
|
||||
const [dispatch, outbound, pallet] = await Promise.all([
|
||||
readFile(join(sourceRoot, 'pages/dispatch/dispatch.vue'), 'utf8'),
|
||||
readFile(join(sourceRoot, 'pages/outbound/outbound.vue'), 'utf8'),
|
||||
readFile(join(sourceRoot, 'pages/pallet/pallet.vue'), 'utf8')
|
||||
])
|
||||
assert.match(dispatch, /:placeholder="`请输入 1-\$\{selectedRemaining\} 箱`"/)
|
||||
assert.match(outbound, /:placeholder="`请输入 1-\$\{selectedRemaining\} 箱`"/)
|
||||
assert.match(pallet, /:placeholder="`最多 \$\{line\.availablePackages\} 箱`"/)
|
||||
})
|
||||
Reference in New Issue
Block a user