test(gallery): 覆盖坏图不留白块 + 面板可见自动恢复/防抖/手动刷新(1.3.0 回归)
This commit is contained in:
1 parent
fb654844bf
commit
393d83550c
2 files changed
+104
-1
No files matched your search
+1
-1
@@ -10,7 +10,7 @@
|
||||
"app:build": "tauri build",
|
||||
"lint": "eslint src app.js",
|
||||
"test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js",
|
||||
"test:unit": "node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/ui-groups-sidebar-test.js && node tests/ui-lib-sidebar-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/ui-workbench-hooks-test.js",
|
||||
"test:unit": "node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/ui-groups-sidebar-test.js && node tests/ui-lib-sidebar-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/ui-workbench-hooks-test.js",
|
||||
"test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js",
|
||||
"test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js",
|
||||
"plugins:gc": "node scripts/plugins-publish.mjs --gc",
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
'use strict'
|
||||
// 图库插件「可靠性」回归(gallery 1.3.0)
|
||||
//
|
||||
// 1) 坏图/截断缩略图(naturalWidth=0)不得留白块:重试后必须落到可点击重试的占位文案。
|
||||
// 2) 自动恢复:面板重新可见(visibilitychange / focus)且距上次拉取 >5s 时重拉列表;
|
||||
// 5s 内不重复拉(防抖),底部「刷新」按钮可强制重拉。
|
||||
const assert = require('assert')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const vm = require('vm')
|
||||
const { JSDOM } = require('jsdom')
|
||||
|
||||
const src = fs.readFileSync(path.resolve(__dirname, '..', '..', 'iwb-plugins-desktop', 'gallery', 'src', 'index.js'), 'utf8')
|
||||
|
||||
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
||||
|
||||
async function boot ({ items, thumb, clock }) {
|
||||
const dom = new JSDOM('<!doctype html><html><body><div id="host"></div></body></html>', { pretendToBeVisual: true })
|
||||
const { window } = dom
|
||||
window.ResizeObserver = class { observe () {} disconnect () {} }
|
||||
window.confirm = () => true
|
||||
|
||||
const registered = []
|
||||
window.IWBPluginHost = { plugins: [], register (manifest, factory) { registered.push({ manifest, factory }) } }
|
||||
|
||||
class FakeDate extends Date { static now () { return clock.now } }
|
||||
|
||||
const sandbox = { window, document: window.document, console, setTimeout, clearTimeout, Promise, Object, Array, JSON, Math, Date: FakeDate }
|
||||
vm.runInNewContext(src, sandbox)
|
||||
|
||||
let mounted = null
|
||||
const calls = { list: 0, thumb: 0 }
|
||||
const ctx = {
|
||||
ui: { registerPanel (p) { mounted = p.mount } },
|
||||
data: { read: async () => ({ cfg: { tile: 130 } }), patch: async () => true },
|
||||
gallery: {
|
||||
list: async () => { calls.list++; return { items: items.slice(), total: items.length } },
|
||||
thumb: async (n) => { calls.thumb++; return thumb(n) },
|
||||
preview: () => {},
|
||||
download: async () => ({ ok: true }),
|
||||
insert: async () => ({ ok: true }),
|
||||
remove: async () => ({ ok: true }),
|
||||
},
|
||||
}
|
||||
registered[0].factory(ctx)
|
||||
const node = window.document.getElementById('host')
|
||||
mounted(node)
|
||||
await wait(60)
|
||||
return { window, document: window.document, node, calls, clock }
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
// ---- 1) 坏图不留白块 ----
|
||||
{
|
||||
const clock = { now: 1000 }
|
||||
const env = await boot({
|
||||
items: [{ name: 'bad.png', w: 200, h: 300 }],
|
||||
thumb: () => 'data:image/png;base64,AAAA',
|
||||
clock,
|
||||
})
|
||||
const box = env.node.querySelector('.iwb-history-item')
|
||||
assert.ok(box, '应渲染出格子')
|
||||
// jsdom 不解码图片:手动触发 load 模拟「拿到坏图」
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const img = box.querySelector('img')
|
||||
if (img) img.dispatchEvent(new env.window.Event('load'))
|
||||
await wait(450)
|
||||
}
|
||||
const holder = box.querySelector('.iwb-history-missing')
|
||||
const visibleImg = Array.from(box.querySelectorAll('img')).filter((i) => i.style.display !== 'none')
|
||||
assert.strictEqual(visibleImg.length, 0, '坏图不得以可见 img 留在格子里(白块)')
|
||||
assert.ok(holder && /失败/.test(holder.textContent), '坏图应显示可点击重试文案,实际:' + (holder && holder.textContent))
|
||||
}
|
||||
|
||||
// ---- 2) 自动恢复 + 防抖 + 手动刷新 ----
|
||||
{
|
||||
const clock = { now: 10_000 }
|
||||
const good = 'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="2" height="3"/>')
|
||||
const env = await boot({ items: [{ name: 'a.png', w: 200, h: 300 }], thumb: () => good, clock })
|
||||
assert.strictEqual(env.calls.list, 1, '初次挂载应拉一次列表')
|
||||
|
||||
// 5s 内重新可见:不重拉(防抖)
|
||||
clock.now += 1000
|
||||
env.document.dispatchEvent(new env.window.Event('visibilitychange'))
|
||||
await wait(60)
|
||||
assert.strictEqual(env.calls.list, 1, '5s 内再次可见不应重复拉取')
|
||||
|
||||
// 超过 5s 后重新可见:自动重拉(图床恢复后无需手动操作)
|
||||
clock.now += 6000
|
||||
env.document.dispatchEvent(new env.window.Event('visibilitychange'))
|
||||
await wait(60)
|
||||
assert.strictEqual(env.calls.list, 2, '面板重新可见且间隔 >5s 应自动重拉,实际 ' + env.calls.list)
|
||||
|
||||
// 底部「刷新」按钮:随时强制重拉
|
||||
const btn = Array.from(env.node.querySelectorAll('.iwb-gal-foot button')).find((b) => b.textContent === '刷新')
|
||||
assert.ok(btn, '底部应有「刷新」按钮')
|
||||
btn.dispatchEvent(new env.window.MouseEvent('click', { bubbles: true }))
|
||||
await wait(60)
|
||||
assert.strictEqual(env.calls.list, 3, '点「刷新」应重拉列表,实际 ' + env.calls.list)
|
||||
}
|
||||
|
||||
console.log('plugin-gallery recovery checks passed(坏图不留白块 / 自动恢复 / 防抖 / 手动刷新)')
|
||||
})().catch((e) => { console.error(e); process.exit(1) })
|
||||
Reference in new issue
Block a user