Files
image-workbench-desktop/tests/iwb-full-window-resize.spec.js
T

92 lines
4.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 资源中心面板:缩放手柄「隐形但可拖」+ 标题栏尺寸显示(2026-10-20)
//
// 背景:此前缩放手柄的 CSS 里有**三套互相冲突**的规则(基类斜角三角 / 四边细条 / 4 角 L 形括号),
// 后写的 `background: transparent` 把前两套的三角**全部覆盖失效** ⇒ 实际显示的是
// 「L 形括号 + 圆角边框」套在**方形面板**上(面板 border-radius: 0)⇒ 视觉上是几截半截线头。
// 现在:手柄**完全不可见**(仍保留 DOM 与拖动热区),「能缩放」的信息改由
// 边缘 hover 淡入提示传递(2026-10-31 起移除标题栏尺寸文字)。
//
// 本用例守三件事(行为断言,不看源码文本):
// ① 4 角 + 4 边手柄**不可见**(背景透明、无边框)但**仍在 DOM 里**(热区未被删);
// ② hover 边缘出现淡入提示(静止时无);
// ③ 拖动边缘仍能改尺寸。
const { test, expect } = require('./_pw-coverage')
const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787'
test.use({ baseURL, viewport: { width: 1440, height: 1000 } })
const WS = {
workspaces: [{ id: 'ws_fs', name: '资源中心', nodes: [], edges: [], groups: [] }],
activeId: 'ws_fs', rev: 1, schemaVersion: 1,
}
async function openResourceCenter(page) {
await page.addInitScript((ws) => { localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) }, WS)
await page.goto('/', { waitUntil: 'domcontentloaded' })
await page.waitForSelector('.iwb-home-card:not(.iwb-home-new)', { timeout: 20000 })
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 20000 })
await page.locator('.iwb-top-nav-icon[title*="资源中心"]').click()
await page.waitForSelector('.iwb-res-tabs', { timeout: 10000 })
await page.waitForTimeout(400)
}
test('缩放手柄不可见但可拖,拖动边缘可改尺寸', async ({ page }) => {
await openResourceCenter(page)
// ① 手柄仍在 DOM 里(热区没被删)且完全不可见
const handles = await page.evaluate(() => {
const out = []
for (const el of document.querySelectorAll('.iwb-full-resize')) {
const cs = getComputedStyle(el)
out.push({
cls: el.className,
bg: cs.backgroundColor,
bgImage: cs.backgroundImage,
border: cs.borderTopWidth,
cursor: cs.cursor,
w: parseFloat(cs.width),
h: parseFloat(cs.height),
})
}
return out
})
expect(handles.length, '应保留 8 个缩放手柄(4 角 + 4 边)').toBe(8)
for (const h of handles) {
expect(h.bg, h.cls + ' 背景应透明').toBe('rgba(0, 0, 0, 0)')
expect(h.bgImage, h.cls + ' 不应有渐变角标').toBe('none')
expect(h.border, h.cls + ' 不应有边框线头').toBe('0px')
}
// 角与边的热区尺寸保持(20px 角 / 7px 边)⇒ 交互手感不变
const corner = handles.find((h) => h.cls.includes('resize-br'))
const edge = handles.find((h) => h.cls.includes('resize-r'))
expect(corner.w, '角热区应保持 20px').toBe(20)
expect(corner.h, '角热区应保持 20px').toBe(20)
expect(edge.w, '边热区应保持 7px').toBe(7)
expect(edge.cursor, '右边应是 ew-resize 光标').toBe('ew-resize')
expect(corner.cursor, '右下角应是 nwse-resize 光标').toBe('nwse-resize')
// ② hover 边缘出现淡入提示(静止时无)
const box = await page.locator('.iwb-fullmask').boundingBox()
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.waitForTimeout(250)
const idle = await page.evaluate(() => getComputedStyle(document.querySelector('.iwb-full-resize-r')).backgroundColor)
expect(idle, '静止时边缘不应有提示色').toBe('rgba(0, 0, 0, 0)')
await page.mouse.move(box.x + box.width - 3, box.y + box.height / 2)
await page.waitForTimeout(350)
const hover = await page.evaluate(() => getComputedStyle(document.querySelector('.iwb-full-resize-r')).backgroundColor)
expect(hover, 'hover 边缘应出现淡入提示').not.toBe('rgba(0, 0, 0, 0)')
// ④ 拖动仍能改尺寸,且尺寸文字实时跟随
const before = await page.evaluate(() => document.querySelector('.iwb-fullmask').getBoundingClientRect().width)
await page.mouse.move(box.x + box.width - 3, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(box.x + box.width - 120, box.y + box.height / 2, { steps: 8 })
await page.mouse.up()
await page.waitForTimeout(400)
const after = await page.evaluate(() => document.querySelector('.iwb-fullmask').getBoundingClientRect().width)
expect(after, '拖动右边缘应缩小面板').toBeLessThan(before)
})