完成JC-ArtList与JC-Salon端侧清理和统一命名
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const sourceRoot = join(process.cwd(), 'src')
|
||||
const adminViewsPath = join(sourceRoot, 'views', 'admin')
|
||||
|
||||
function readSource(relativePath: string) {
|
||||
return readFileSync(join(sourceRoot, relativePath), 'utf-8')
|
||||
}
|
||||
|
||||
function findModalTags(source: string) {
|
||||
return Array.from(source.matchAll(/<a-modal\b[\s\S]*?>/g), match => match[0])
|
||||
}
|
||||
|
||||
function findUserFormModal(source: string) {
|
||||
const match = source.match(/<AdminResponsiveModal\b[\s\S]*?@cancel="handleModalCancel"[\s\S]*?<\/AdminResponsiveModal>/)
|
||||
return match?.[0] ?? ''
|
||||
}
|
||||
|
||||
function findFormItem(source: string, name: string) {
|
||||
const match = source.match(new RegExp(`<a-form-item\\b[\\s\\S]*?name="${name}"[\\s\\S]*?</a-form-item>`))
|
||||
return match?.[0] ?? ''
|
||||
}
|
||||
|
||||
describe('admin modal and user form behavior', () => {
|
||||
it('keeps every backend modal open when users click the blank mask area', () => {
|
||||
const responsiveModal = readSource('components/admin/AdminResponsiveModal.vue')
|
||||
expect(responsiveModal).toMatch(/<a-modal\b[\s\S]*:mask-closable="false"/)
|
||||
|
||||
const missingMaskLock = readdirSync(adminViewsPath)
|
||||
.filter(fileName => fileName.endsWith('.vue'))
|
||||
.flatMap(fileName => {
|
||||
const source = readFileSync(join(adminViewsPath, fileName), 'utf-8')
|
||||
return findModalTags(source)
|
||||
.map((tag, index) => ({ fileName, index: index + 1, tag }))
|
||||
.filter(({ tag }) => !/:mask-closable\s*=\s*"false"/.test(tag))
|
||||
.map(({ fileName, index }) => `${fileName} modal #${index}`)
|
||||
})
|
||||
|
||||
expect(missingMaskLock).toEqual([])
|
||||
})
|
||||
|
||||
it('shows only one editable phone field in the user create and edit form', () => {
|
||||
const usersView = readSource('views/admin/UsersView.vue')
|
||||
const userFormModal = findUserFormModal(usersView)
|
||||
|
||||
expect(userFormModal).toContain('name="phone"')
|
||||
expect(userFormModal).not.toContain('name="contactPhone"')
|
||||
expect(userFormModal).not.toContain('formState.contactPhone')
|
||||
expect(usersView).toContain('const primaryPhone = formState.phone.trim()')
|
||||
expect(usersView).toContain('phone: primaryPhone')
|
||||
expect(usersView).toContain('contactPhone: primaryPhone')
|
||||
})
|
||||
|
||||
it('uses a polished date picker and visible required markers for conditional user fields', () => {
|
||||
const usersView = readSource('views/admin/UsersView.vue')
|
||||
const userFormModal = findUserFormModal(usersView)
|
||||
const wechatIdField = findFormItem(userFormModal, 'wechatId')
|
||||
const shopIdsField = findFormItem(userFormModal, 'shopIds')
|
||||
|
||||
expect(userFormModal).not.toContain('type="date"')
|
||||
expect(userFormModal).toContain('<a-date-picker')
|
||||
expect(userFormModal).toContain('value-format="YYYY-MM-DD"')
|
||||
expect(userFormModal).toContain('class="user-date-picker"')
|
||||
expect(usersView).toContain('.user-date-picker')
|
||||
expect(wechatIdField).toContain(':required="[2, 3].includes(Number(formState.type))"')
|
||||
expect(shopIdsField).toContain(':required="Number(formState.type) !== 4"')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user