const assert = require('node:assert/strict') const fs = require('node:fs'), path = require('node:path') const { chromium } = require('./vue3-test-runtime.cjs') const base = process.env.VUE3_URL || 'http://127.0.0.1:8088' const out = path.resolve(__dirname, '../../.codex-tmp/vue3-global-ui-check') async function ready(page, route) { await page.goto(base + route) await page.locator('.desktop-viewport').waitFor() await page.waitForFunction(() => ![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(e => e.getClientRects().length)) } async function density(page, name) { await page.locator('#size-select').click() await page.getByRole('menuitem', { name, exact: true }).click() await page.waitForTimeout(150) } async function setting(page, patch) { await page.evaluate(async patch => { const { default: useSettings } = await import('/src/store/modules/settings.js') useSettings().$patch(patch) }, patch) await page.waitForTimeout(250) } ;(async () => { fs.mkdirSync(out, { recursive: true }) const browser = await chromium.launch({ headless: true }) const errors = [], report = {} try { const context = await browser.newContext({ viewport: { width: 1440, height: 900 } }) const page = await context.newPage() page.setDefaultTimeout(12000) page.on('pageerror', error => errors.push(error.message)) // Real login; every subsequent business write is blocked. const target = '/procurement/details?projectId=2&queue=pending#check' await page.goto(base + '/login?redirect=' + encodeURIComponent(target)) assert.equal(await page.getByPlaceholder('账号').inputValue(), '') assert.equal(await page.getByPlaceholder('密码', { exact: true }).inputValue(), '') assert.equal(await page.locator('.el-login-footer').count(), 0) await page.getByPlaceholder('账号').fill(process.env.TEST_USERNAME || 'admin') await page.getByPlaceholder('密码', { exact: true }).fill(process.env.TEST_PASSWORD || 'admin123') await page.waitForFunction(() => !document.querySelector('input[placeholder="验证码"]')) await page.getByRole('button', { name: /登\s*录/ }).click() await page.locator('.purchase-sheet').waitFor() assert.equal(new URL(page.url()).searchParams.get('projectId'), '2') assert.equal(new URL(page.url()).searchParams.get('queue'), 'pending') assert.equal(new URL(page.url()).hash, '#check') await context.route('**/dev-api/**', route => ['GET', 'HEAD'].includes(route.request().method()) ? route.continue() : route.abort('blockedbyclient')) console.log('PASS empty login credentials and complete redirect') await ready(page, '/businessBasics/products') let navigations = 0 page.on('framenavigated', frame => { if (frame === page.mainFrame()) navigations++ }) report.density = [] for (const [name, size, height, font, tableFont] of [['紧凑', 'small', 28, '13px', '12px'], ['宽松', 'large', 36, '15px', '14px'], ['标准', 'default', 32, '14px', '13px']]) { await density(page, name) assert.equal(navigations, 0) const metrics = await page.evaluate(() => { const control = selector => { const e = document.querySelector(selector); return { height: e.getBoundingClientRect().height, font: getComputedStyle(e).fontSize } } return { density: document.documentElement.dataset.density, input: control('.desktop-viewport .el-form--inline .el-input__wrapper'), button: control('.desktop-viewport .el-form--inline .el-button'), pager: control('.pagination-container .el-select__wrapper'), table: control('.el-table th') } }) console.log('DENSITY', JSON.stringify(metrics)) assert.equal(metrics.density, size) for (const key of ['input', 'button', 'pager']) { assert.equal(metrics[key].height, height); assert.equal(metrics[key].font, font) } assert.equal(metrics.table.font, tableFont) await page.getByRole('button', { name: '新增', exact: true }).click() const dialog = page.locator('.el-dialog:visible') await page.waitForTimeout(350) assert.equal(await dialog.locator('.el-select__wrapper').first().evaluate(e => e.getBoundingClientRect().height), height) await dialog.getByRole('button', { name: '取消', exact: true }).click() await dialog.waitFor({ state: 'hidden' }) report.density.push(metrics) await page.screenshot({ path: path.join(out, size + '.png') }) } assert.equal(await page.locator('#ruoyi-git,#ruoyi-doc').count(), 0) await page.locator('#hamburger-container').click() await page.reload() await page.locator('.hideSidebar').waitFor() await page.locator('#hamburger-container').click() console.log('PASS three live densities, dialogs and persisted sidebar collapse') report.layouts = [] for (const width of [1024, 1280, 1440]) { await page.setViewportSize({ width, height: 900 }) for (const navType of [2, 3, 1]) { await setting(page, { navType }) const geometry = await page.evaluate(() => { const nav = document.querySelector('.navbar'), menu = nav.querySelector('.topmenu-container,.topbar-container'), tools = nav.querySelector('.right-menu') const rect = e => e?.getBoundingClientRect().toJSON() return { nav: rect(nav), menu: rect(menu), tools: rect(tools), scrollWidth: document.documentElement.scrollWidth, width: innerWidth } }) if (geometry.menu) { assert.ok(geometry.menu.right <= geometry.tools.x + 1, JSON.stringify(geometry)) assert.ok(geometry.menu.y >= geometry.nav.y - 1) assert.ok(geometry.menu.bottom <= geometry.nav.bottom + 1) } assert.equal(geometry.scrollWidth, width) report.layouts.push({ width, navType, geometry }) } } await page.setViewportSize({ width: 1440, height: 900 }) await setting(page, { footerVisible: true }) await page.locator('.tags-action-dropdown').click() await page.getByRole('menuitem', { name: '内容全屏', exact: true }).click() const footer = await page.evaluate(() => ({ pager: document.querySelector('.pagination-container').getBoundingClientRect().bottom, footer: document.querySelector('.copyright').getBoundingClientRect().top })) assert.ok(footer.pager <= footer.footer, JSON.stringify(footer)) await page.keyboard.press('Escape') await setting(page, { footerVisible: false }) console.log('PASS 9 layout/width combinations and content fullscreen footer') await page.locator('.theme-switch-wrapper').click() await page.waitForFunction(() => document.documentElement.classList.contains('dark')) await page.waitForTimeout(750) await page.locator('#header-notice').hover() await page.waitForTimeout(200) report.dark = await page.evaluate(() => ({ tool: getComputedStyle(document.querySelector('.right-menu-item')).color, header: getComputedStyle(document.querySelector('.notice-header')).backgroundColor, light9: getComputedStyle(document.documentElement).getPropertyValue('--el-color-primary-light-9') })) assert.notEqual(report.dark.tool, 'rgb(90, 94, 102)') assert.notEqual(report.dark.header, 'rgb(247, 249, 251)') // Historical notice contents were copied deliberately. Check they come from // the current API, rather than treating words in real data as UI branding. const noticeRows=await page.evaluate(async()=>{const {default:request}=await import('/src/utils/request.js');return (await request.get('/system/notice/listTop')).data||[]}) assert.deepEqual(await page.locator('.notice-popover .notice-item-title').allTextContents(),noticeRows.map(row=>row.noticeTitle)) await page.mouse.move(600, 400) await page.evaluate(async () => { const { handleThemeStyle } = await import('/src/utils/theme.js') handleThemeStyle(null) }) await page.screenshot({ path: path.join(out, 'dark.png') }) await page.locator('.theme-switch-wrapper').click() await page.waitForTimeout(750) await page.locator('#header-search').click() await page.waitForFunction(() => document.activeElement?.getAttribute('placeholder')?.startsWith('菜单搜索')) for (let i = 0; i < 14; i++) await page.keyboard.press('ArrowDown') await page.waitForTimeout(100) const selection = await page.locator('.search-item.is-active').evaluate(e => ({ row: e.getBoundingClientRect().toJSON(), wrap: e.closest('.el-scrollbar__wrap').getBoundingClientRect().toJSON() })) assert.ok(selection.row.top >= selection.wrap.top - 1 && selection.row.bottom <= selection.wrap.bottom + 1) await page.keyboard.press('Escape') console.log('PASS dark theme, invalid theme fallback, notice cleanup and keyboard search') await page.route('**/dev-api/production/product/list?*', route => { const number = Number(new URL(route.request().url()).searchParams.get('pageNum') || 1) return route.fulfill({ json: { code: 200, total: 60, rows: Array.from({ length: 20 }, (_, index) => ({ id: number * 100 + index, itemId: number * 100 + index, itemName: 'PAGE' + number + '-ITEM' + index, itemCode: 'TEST' + index, brand: 'TEST', spec: 'M6', unit: '个' })) } }) }) await ready(page, '/businessBasics/products') const tableWrap = page.locator('.el-table__body-wrapper .el-scrollbar__wrap').first() await tableWrap.evaluate(el => { el.scrollTop = 250 }) assert.ok(await tableWrap.evaluate(el => el.scrollTop) > 0) await page.locator('.pagination-container .btn-next').click() await page.waitForFunction(() => document.querySelector('.el-table__body-wrapper').textContent.includes('PAGE2-ITEM0') && !document.querySelector('.el-table .el-loading-mask')) assert.equal(await tableWrap.evaluate(el => el.scrollTop), 0) await page.unroute('**/dev-api/production/product/list?*') console.log('PASS pagination resets the table body scroll') // Vue3 components are mounted only in this isolated browser. No API mutations. report.components = await page.evaluate(async () => { const { createApp, h, nextTick } = await import('/tests/browser-runtime.js') const { default: DictTag } = await import('/src/components/DictTag/index.vue') const { default: Receipt } = await import('/src/components/ReceiptDialog/index.vue') const { default: StockOperations } = await import('/src/components/Production/StockOperations.vue') const { ElementPlus } = await import('/tests/browser-runtime.js') const host = document.createElement('div'); document.body.append(host) const unknownApp = createApp({ render: () => h(DictTag, { value: 'UNKNOWN', options: [{ value: 'A', label: 'A' }] }) }) unknownApp.mount(host); await nextTick(); const unknown = host.textContent.trim(); unknownApp.unmount() const emptyApp = createApp({ render: () => h(DictTag, { value: 'RAW', options: [] }) }) emptyApp.mount(host); await nextTick(); const empty = host.textContent.trim(); emptyApp.unmount() const stockApp = createApp(StockOperations).use(ElementPlus) const stock = stockApp.mount(host) stock.kind = 'ISSUE'; stock.taskContext = { item_name: 'AUDIT-PRODUCT', task_no: 'AUDIT-TASK' } stock.rows = [{ projectName: 'TEST', productName: 'TEST', areaName: 'TEST', stockNum: 1, quantity: 1 }] stock.visible = true await nextTick(); await new Promise(resolve => setTimeout(resolve, 100)) const taskText = document.querySelector('.el-dialog .el-table__body-wrapper').textContent stockApp.unmount() const receiptApp = createApp(Receipt).use(ElementPlus) const receipt = receiptApp.mount(host); receipt.record = {}; receipt.visible = true; receipt.saving = true await nextTick() window.__auditReceipt = { receipt, receiptApp, host } return { unknown, empty, taskText } }) assert.equal(report.components.unknown, 'UNKNOWN') assert.equal(report.components.empty, 'RAW') assert.ok(report.components.taskText.includes('AUDIT-PRODUCT / AUDIT-TASK')) await page.keyboard.press('Escape') await page.waitForTimeout(200) assert.equal(await page.evaluate(() => window.__auditReceipt.receipt.visible), true) await page.evaluate(() => { window.__auditReceipt.receiptApp.unmount(); window.__auditReceipt.host.remove(); delete window.__auditReceipt }) console.log('PASS unknown dictionaries and blocked Escape during receipt submission') await ready(page, '/procurement/details') await page.getByRole('button', { name: '新增采购批次', exact: true }).click() const quantityCell = page.locator('.sheet-cell[data-field="quantity"]').first() const quantity = page.locator('.sheet-cell[data-field="quantity"] input').first() await quantityCell.click() await quantity.fill('9'); await quantity.blur() for (const [name, height, font] of [['紧凑', 24, '12px'], ['宽松', 32, '14px'], ['标准', 28, '13px']]) { await density(page, name) await quantityCell.click() assert.equal(Number(await quantity.inputValue()), 9) await page.locator('.sheet-cell[data-field="unit"]').first().click() const grid = await page.locator('.sheet-grid .el-select__wrapper').first().evaluate(e => ({ height: e.getBoundingClientRect().height, font: getComputedStyle(e).fontSize })) assert.equal(grid.height, height); assert.equal(grid.font, font) } const tab = page.locator('.tags-view-item').filter({ hasText: '采购明细' }) await tab.locator('.tags-close-btn').click() await page.locator('.el-message-box').getByRole('button', { name: '取消', exact: true }).click() assert.ok(new URL(page.url()).pathname === '/procurement/details') assert.equal(await tab.count(), 1) await page.locator('.tags-refresh-btn').click() await page.locator('.el-message-box').getByRole('button', { name: '取消', exact: true }).click() await quantityCell.click() assert.equal(Number(await quantity.inputValue()), 9) await page.locator('.tags-action-dropdown').click() await page.getByRole('menuitem', { name: '全部关闭', exact: true }).click() await page.locator('.el-message-box').getByRole('button', { name: '取消', exact: true }).click() assert.equal(await tab.count(), 1) await tab.locator('.tags-close-btn').click() await page.locator('.el-message-box').getByRole('button', { name: '确定', exact: true }).click() try { await page.waitForURL(url => url.pathname !== '/procurement/details') } catch(error) { console.log('CLOSE_STATE',page.url(),await page.locator('body').innerText());throw error } assert.equal(await page.locator('.tags-view-item').filter({ hasText: '采购明细' }).count(), 0) console.log('PASS cancelled/confirmed close preserves or removes tab atomically') await density(page, '宽松') await setting(page, { theme: '#ff4500', footerVisible: true, navType: 2 }) await page.locator('.avatar-container').hover() await page.getByRole('menuitem', { name: '显示设置', exact: true }).click() await page.locator('.el-drawer:visible').getByRole('button', { name: '恢复默认', exact: true }).click() assert.deepEqual(await page.evaluate(() => { const saved = JSON.parse(localStorage.getItem('layout-setting')) return { theme: saved.theme, size: saved.size, navType: saved.navType, footerVisible: saved.footerVisible, isDark: saved.isDark } }), { theme: '#409EFF', size: 'default', navType: 1, footerVisible: false, isDark: false }) await page.keyboard.press('Escape') await ready(page, '/businessBasics/area') let releaseSave const saveGate = new Promise(resolve => { releaseSave = resolve }) let saves = 0 await page.route('**/dev-api/warehouse/area', async route => { saves++ await saveGate await route.fulfill({ json: { code: 500, msg: '模拟保存失败' } }) }) await page.getByRole('button', { name: '新增', exact: true }).click() const areaDialog = page.locator('.el-dialog:visible') await areaDialog.getByPlaceholder('请输入库区名称').fill('AUDIT-NOT-SAVED') await areaDialog.getByRole('button', { name: /确\s*定/ }).click() await page.waitForFunction(() => {let vm=document.querySelector('.desktop-viewport .app-container').__vueParentComponent;while(vm&&!Object.hasOwn(vm.proxy.$data,'saving'))vm=vm.parent;return vm?.proxy.saving}) assert.equal(await areaDialog.getByRole('button', { name: /取\s*消/ }).isDisabled(), true) assert.equal(await areaDialog.locator('.el-dialog__headerbtn').count(), 0) await page.keyboard.press('Escape') assert.equal(await areaDialog.isVisible(), true) releaseSave() await page.waitForFunction(() => {let vm=document.querySelector('.desktop-viewport .app-container').__vueParentComponent;while(vm&&!Object.hasOwn(vm.proxy.$data,'saving'))vm=vm.parent;return vm&&!vm.proxy.saving}) assert.equal(saves, 1) assert.equal(await areaDialog.isVisible(), true) assert.equal(await areaDialog.getByRole('button', { name: /取\s*消/ }).isDisabled(), false) await areaDialog.getByRole('button', { name: /取\s*消/ }).click() console.log('PASS pending submit cannot close; failed submit remains editable') await page.goto(base + '/register') await page.locator('.wscn-http404-container').waitFor() assert.equal(await page.locator('.register').count(), 0) assert.deepEqual(errors, []) fs.writeFileSync(path.join(out, 'result.json'), JSON.stringify({ ...report, errors }, null, 2)) console.log('GLOBAL UI PASS') } finally { await browser.close() } })().catch(error => { console.error(error); process.exitCode = 1 })