48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
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 findTableTags(source: string) {
|
|
return Array.from(source.matchAll(/<a-table\b[\s\S]*?>/g), match => match[0])
|
|
}
|
|
|
|
describe('admin table layout', () => {
|
|
it('keeps every admin table wide enough to scroll horizontally', () => {
|
|
const missingScrollX = readdirSync(adminViewsPath)
|
|
.filter(fileName => fileName.endsWith('.vue'))
|
|
.flatMap(fileName => {
|
|
const source = readFileSync(join(adminViewsPath, fileName), 'utf-8')
|
|
return findTableTags(source)
|
|
.map((tag, index) => ({ fileName, index: index + 1, tag }))
|
|
.filter(({ tag }) => !/:scroll\s*=\s*"\{[\s\S]*x:\s*'max-content'/.test(tag))
|
|
.map(({ fileName, index }) => `${fileName} table #${index}`)
|
|
})
|
|
|
|
expect(missingScrollX).toEqual([])
|
|
})
|
|
|
|
it('prevents backend table cells from breaking text into vertical columns', () => {
|
|
const adminLayout = readSource('views/admin/AdminLayout.vue')
|
|
|
|
expect(adminLayout).not.toMatch(/\.mobile-content\s+:deep\(\.ant-table-cell\)\s*\{[\s\S]*overflow-wrap:\s*anywhere/)
|
|
expect(adminLayout).toContain('table-layout: auto;')
|
|
expect(adminLayout).toContain('width: max-content;')
|
|
expect(adminLayout).toContain('word-break: keep-all;')
|
|
})
|
|
|
|
it('keeps table ellipsis text content-sized without arbitrary character breaking', () => {
|
|
const ellipsisText = readSource('components/TableEllipsisText.vue')
|
|
|
|
expect(ellipsisText).toContain('display: inline-block;')
|
|
expect(ellipsisText).not.toMatch(/^\s*width:\s*100%;$/m)
|
|
expect(ellipsisText).not.toContain('word-break: break-all;')
|
|
})
|
|
})
|