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(//g), match => match[0]) } function findUserFormModal(source: string) { const match = source.match(//) return match?.[0] ?? '' } function findFormItem(source: string, name: string) { const match = source.match(new RegExp(``)) 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(/ 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('