dsh-delete-session 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/package.json +1 -1
- package/src/client.js +50 -3
- package/test/checkbox.dom.test.js +769 -687
|
@@ -233,6 +233,12 @@ let bundleFactory = null
|
|
|
233
233
|
// next one can drop the leftovers.
|
|
234
234
|
const rafQueues = []
|
|
235
235
|
|
|
236
|
+
// Timers started by a plugin instance outlive the test that started them. The
|
|
237
|
+
// batch path schedules a 2.5 s settle, and its callback decorates whatever
|
|
238
|
+
// `globalThis.document` is when it fires - the next test's DOM. Track and
|
|
239
|
+
// clear them so one test cannot reach into another.
|
|
240
|
+
const pendingTimers = []
|
|
241
|
+
|
|
236
242
|
/**
|
|
237
243
|
* The bundle registers through `window.__ModuleLoader__` once per process and ESM
|
|
238
244
|
* caching means a second `import()` never re-runs it. Caching the factory is also
|
|
@@ -317,6 +323,13 @@ async function loadPlugin(options = {}) {
|
|
|
317
323
|
// very regression this file exists to catch.
|
|
318
324
|
// Drop anything an earlier instance queued: it would run against THIS dom.
|
|
319
325
|
for (const stale of rafQueues) stale.clear()
|
|
326
|
+
while (pendingTimers.length > 0) clearTimeout(pendingTimers.pop())
|
|
327
|
+
const realSetTimeout = globalThis.setTimeout
|
|
328
|
+
globalThis.setTimeout = (fn, ms) => {
|
|
329
|
+
const id = realSetTimeout(fn, ms)
|
|
330
|
+
pendingTimers.push(id)
|
|
331
|
+
return id
|
|
332
|
+
}
|
|
320
333
|
let rafId = 0
|
|
321
334
|
const rafQueue = new Map()
|
|
322
335
|
rafQueues.push(rafQueue)
|
|
@@ -593,13 +606,13 @@ const clickBar = (node) => node.props.onClick({ stopPropagation() {} })
|
|
|
593
606
|
const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
|
|
594
607
|
|
|
595
608
|
/** Let the queued rAF decorate passes drain. */
|
|
596
|
-
const flush = async () => { await tick() }
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* Drain until nothing is left. `flush()` is one tick, and a decorate pass can
|
|
600
|
-
* queue another callback while it runs; a test that snapshots a counter right
|
|
601
|
-
* after a single flush occasionally catches a straggler.
|
|
602
|
-
*/
|
|
609
|
+
const flush = async () => { await tick() }
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Drain until nothing is left. `flush()` is one tick, and a decorate pass can
|
|
613
|
+
* queue another callback while it runs; a test that snapshots a counter right
|
|
614
|
+
* after a single flush occasionally catches a straggler.
|
|
615
|
+
*/
|
|
603
616
|
const settle = async () => { for (let i = 0; i < 20; i += 1) await flush() }
|
|
604
617
|
|
|
605
618
|
/**
|
|
@@ -2878,704 +2891,773 @@ test('a button-shaped footer entry steps aside without hiding the bar itself', a
|
|
|
2878
2891
|
/\[data-slot="sidebar\.footer\.action"\] > button\{display:none\}/,
|
|
2879
2892
|
'never hide every button unconditionally',
|
|
2880
2893
|
)
|
|
2894
|
+
})
|
|
2895
|
+
|
|
2896
|
+
test('the drop label names the conversation instead of printing the placeholder', async () => {
|
|
2897
|
+
const harness = await loadPlugin()
|
|
2898
|
+
const row = mountRow(harness, SESSION_A)
|
|
2899
|
+
|
|
2900
|
+
startRowDrag(harness, row)
|
|
2901
|
+
await flush()
|
|
2902
|
+
bar(harness).props.onDragOver(dropEvent())
|
|
2903
|
+
await flush()
|
|
2904
|
+
|
|
2905
|
+
const node = bar(harness)
|
|
2906
|
+
const text = JSON.stringify(node.props.children)
|
|
2907
|
+
|
|
2908
|
+
// The dictionary entry is `松手删除「{name}」`, but the interpolation map carries
|
|
2909
|
+
// `n`/`done`/`total`/`ok`/`fail`/`path` — not `name`. Passing the title as a bare
|
|
2910
|
+
// string therefore left the braces in the label.
|
|
2911
|
+
assert.doesNotMatch(text, /\{name\}/, 'no unsubstituted placeholder in the label')
|
|
2912
|
+
assert.match(text, /松手删除/, 'the sentence is still there')
|
|
2913
|
+
})
|
|
2914
|
+
|
|
2915
|
+
test('the drop label carries the dragged conversation title', async () => {
|
|
2916
|
+
const harness = await loadPlugin()
|
|
2917
|
+
const row = mountRow(harness, SESSION_A)
|
|
2918
|
+
row.textContent = 'BiliLearn-AI 仓库'
|
|
2919
|
+
|
|
2920
|
+
startRowDrag(harness, row)
|
|
2921
|
+
await flush()
|
|
2922
|
+
bar(harness).props.onDragOver(dropEvent())
|
|
2923
|
+
await flush()
|
|
2924
|
+
|
|
2925
|
+
const text = JSON.stringify(bar(harness).props.children)
|
|
2926
|
+
assert.match(text, /BiliLearn-AI 仓库/, 'the title reaches the sentence')
|
|
2927
|
+
})
|
|
2928
|
+
test('a workspace header offers a select-all box', async () => {
|
|
2929
|
+
const harness = await loadPlugin()
|
|
2930
|
+
const section = harness.document.createElement('div')
|
|
2931
|
+
section.setAttribute('role', 'group')
|
|
2932
|
+
|
|
2933
|
+
const header = harness.document.createElement('div')
|
|
2934
|
+
header.setAttribute('role', 'treeitem')
|
|
2935
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
2936
|
+
section.appendChild(header)
|
|
2937
|
+
|
|
2938
|
+
mountRow(harness, SESSION_A, section)
|
|
2939
|
+
mountRow(harness, SESSION_B, section)
|
|
2940
|
+
harness.document.body.appendChild(section)
|
|
2941
|
+
|
|
2942
|
+
await enterMulti(harness)
|
|
2943
|
+
observerPass(harness)
|
|
2944
|
+
await flush()
|
|
2945
|
+
|
|
2946
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
2947
|
+
assert.ok(box, 'the header carries one')
|
|
2948
|
+
assert.equal(box.getAttribute('role'), 'checkbox')
|
|
2949
|
+
assert.equal(box.getAttribute('aria-checked'), 'false', 'nothing picked yet')
|
|
2950
|
+
})
|
|
2951
|
+
|
|
2952
|
+
test('the workspace box selects only its own sessions', async () => {
|
|
2953
|
+
const harness = await loadPlugin()
|
|
2954
|
+
const sectionA = harness.document.createElement('div')
|
|
2955
|
+
sectionA.setAttribute('role', 'group')
|
|
2956
|
+
const headA = harness.document.createElement('div')
|
|
2957
|
+
headA.setAttribute('role', 'treeitem')
|
|
2958
|
+
headA.setAttribute('data-row-key', 'workspace:ws-a')
|
|
2959
|
+
sectionA.appendChild(headA)
|
|
2960
|
+
mountRow(harness, SESSION_A, sectionA)
|
|
2961
|
+
harness.document.body.appendChild(sectionA)
|
|
2962
|
+
|
|
2963
|
+
const sectionB = harness.document.createElement('div')
|
|
2964
|
+
sectionB.setAttribute('role', 'group')
|
|
2965
|
+
const headB = harness.document.createElement('div')
|
|
2966
|
+
headB.setAttribute('role', 'treeitem')
|
|
2967
|
+
headB.setAttribute('data-row-key', 'workspace:ws-b')
|
|
2968
|
+
sectionB.appendChild(headB)
|
|
2969
|
+
mountRow(harness, SESSION_B, sectionB)
|
|
2970
|
+
harness.document.body.appendChild(sectionB)
|
|
2971
|
+
|
|
2972
|
+
await enterMulti(harness)
|
|
2973
|
+
observerPass(harness)
|
|
2974
|
+
await flush()
|
|
2975
|
+
|
|
2976
|
+
headA.querySelector('.dsdel-select-all').fire('click')
|
|
2977
|
+
await flush()
|
|
2978
|
+
|
|
2979
|
+
assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true', 'A turned on')
|
|
2980
|
+
const boxB = headB.querySelector('.dsdel-select-all')
|
|
2981
|
+
assert.equal(boxB.getAttribute('aria-checked'), 'false', 'B untouched')
|
|
2982
|
+
})
|
|
2983
|
+
|
|
2984
|
+
test('a second press clears the workspace again', async () => {
|
|
2985
|
+
const harness = await loadPlugin()
|
|
2986
|
+
const section = harness.document.createElement('div')
|
|
2987
|
+
section.setAttribute('role', 'group')
|
|
2988
|
+
const header = harness.document.createElement('div')
|
|
2989
|
+
header.setAttribute('role', 'treeitem')
|
|
2990
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
2991
|
+
section.appendChild(header)
|
|
2992
|
+
mountRow(harness, SESSION_A, section)
|
|
2993
|
+
harness.document.body.appendChild(section)
|
|
2994
|
+
|
|
2995
|
+
await enterMulti(harness)
|
|
2996
|
+
observerPass(harness)
|
|
2997
|
+
await flush()
|
|
2998
|
+
|
|
2999
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
3000
|
+
box.fire('click')
|
|
3001
|
+
await flush()
|
|
3002
|
+
assert.equal(box.getAttribute('aria-checked'), 'true')
|
|
3003
|
+
|
|
3004
|
+
box.fire('click')
|
|
3005
|
+
await flush()
|
|
3006
|
+
assert.equal(box.getAttribute('aria-checked'), 'false')
|
|
3007
|
+
})
|
|
3008
|
+
|
|
3009
|
+
test('the box reports a partly picked workspace as mixed', async () => {
|
|
3010
|
+
const harness = await loadPlugin()
|
|
3011
|
+
const section = harness.document.createElement('div')
|
|
3012
|
+
section.setAttribute('role', 'group')
|
|
3013
|
+
const header = harness.document.createElement('div')
|
|
3014
|
+
header.setAttribute('role', 'treeitem')
|
|
3015
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3016
|
+
section.appendChild(header)
|
|
3017
|
+
const rowA = mountRow(harness, SESSION_A, section)
|
|
3018
|
+
mountRow(harness, SESSION_B, section)
|
|
3019
|
+
harness.document.body.appendChild(section)
|
|
3020
|
+
|
|
3021
|
+
await enterMulti(harness)
|
|
3022
|
+
observerPass(harness)
|
|
3023
|
+
await flush()
|
|
3024
|
+
|
|
3025
|
+
clickRowIn(harness, rowA)
|
|
3026
|
+
observerPass(harness)
|
|
3027
|
+
await flush()
|
|
3028
|
+
|
|
3029
|
+
assert.equal(header.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'mixed')
|
|
3030
|
+
})
|
|
3031
|
+
|
|
3032
|
+
test('the heading row selects every workspace at once', async () => {
|
|
3033
|
+
const harness = await loadPlugin()
|
|
3034
|
+
const heading = harness.document.createElement('div')
|
|
3035
|
+
heading.setAttribute('data-sidebar-workspace-header', '')
|
|
3036
|
+
harness.document.body.appendChild(heading)
|
|
3037
|
+
|
|
3038
|
+
const sectionA = harness.document.createElement('div')
|
|
3039
|
+
sectionA.setAttribute('role', 'group')
|
|
3040
|
+
const headA = harness.document.createElement('div')
|
|
3041
|
+
headA.setAttribute('role', 'treeitem')
|
|
3042
|
+
headA.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3043
|
+
sectionA.appendChild(headA)
|
|
3044
|
+
mountRow(harness, SESSION_A, sectionA)
|
|
3045
|
+
harness.document.body.appendChild(sectionA)
|
|
3046
|
+
|
|
3047
|
+
const sectionB = harness.document.createElement('div')
|
|
3048
|
+
sectionB.setAttribute('role', 'group')
|
|
3049
|
+
const headB = harness.document.createElement('div')
|
|
3050
|
+
headB.setAttribute('role', 'treeitem')
|
|
3051
|
+
headB.setAttribute('data-row-key', 'workspace:ws-b')
|
|
3052
|
+
sectionB.appendChild(headB)
|
|
3053
|
+
mountRow(harness, SESSION_B, sectionB)
|
|
3054
|
+
harness.document.body.appendChild(sectionB)
|
|
3055
|
+
|
|
3056
|
+
await enterMulti(harness)
|
|
3057
|
+
observerPass(harness)
|
|
3058
|
+
await flush()
|
|
3059
|
+
|
|
3060
|
+
const all = heading.querySelector('.dsdel-select-all-workspaces')
|
|
3061
|
+
assert.ok(all, 'the heading carries the global box')
|
|
3062
|
+
all.fire('click')
|
|
3063
|
+
await flush()
|
|
3064
|
+
|
|
3065
|
+
assert.equal(all.getAttribute('aria-checked'), 'true', 'everything picked')
|
|
3066
|
+
assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
|
|
3067
|
+
assert.equal(headB.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
|
|
3068
|
+
})
|
|
3069
|
+
|
|
3070
|
+
test('both boxes go away when the mode ends', async () => {
|
|
3071
|
+
const harness = await loadPlugin()
|
|
3072
|
+
const heading = harness.document.createElement('div')
|
|
3073
|
+
heading.setAttribute('data-sidebar-workspace-header', '')
|
|
3074
|
+
harness.document.body.appendChild(heading)
|
|
3075
|
+
|
|
3076
|
+
const section = harness.document.createElement('div')
|
|
3077
|
+
section.setAttribute('role', 'group')
|
|
3078
|
+
const header = harness.document.createElement('div')
|
|
3079
|
+
header.setAttribute('role', 'treeitem')
|
|
3080
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3081
|
+
section.appendChild(header)
|
|
3082
|
+
mountRow(harness, SESSION_A, section)
|
|
3083
|
+
harness.document.body.appendChild(section)
|
|
3084
|
+
|
|
3085
|
+
await enterMulti(harness)
|
|
3086
|
+
observerPass(harness)
|
|
3087
|
+
await flush()
|
|
3088
|
+
assert.ok(header.querySelector('.dsdel-select-all'), 'present during the mode')
|
|
3089
|
+
assert.ok(heading.querySelector('.dsdel-select-all-workspaces'))
|
|
3090
|
+
|
|
3091
|
+
harness.document.dispatchToDocument('keydown', { key: 'Escape', stopPropagation() {} })
|
|
3092
|
+
observerPass(harness)
|
|
3093
|
+
await flush()
|
|
3094
|
+
|
|
3095
|
+
assert.equal(header.querySelector('.dsdel-select-all'), null, 'removed with the mode')
|
|
3096
|
+
assert.equal(heading.querySelector('.dsdel-select-all-workspaces'), null)
|
|
3097
|
+
})
|
|
3098
|
+
|
|
3099
|
+
test('the select-all boxes do not lean on the page token scope', async () => {
|
|
3100
|
+
const harness = await loadPlugin()
|
|
3101
|
+
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3102
|
+
|
|
3103
|
+
// The boxes render inside the SIDEBAR. The `--dsdel-*` tokens are declared on
|
|
3104
|
+
// `.dsdel-page`, `.dsdel-modal` and `.dsdel-bar` only, so any rule outside those
|
|
3105
|
+
// scopes that reads them gets an invalid value and loses the whole declaration.
|
|
3106
|
+
// That is how the first version shipped an invisible button: `border` was
|
|
3107
|
+
// dropped, leaving no box and nothing to click.
|
|
3108
|
+
const rules = [...css.matchAll(/(?:^|\})\s*\.dsdel-select-all[^{]*\{([^}]*)\}/g)]
|
|
3109
|
+
assert.ok(rules.length > 0, 'the rules are in the stylesheet')
|
|
3110
|
+
for (const match of rules) {
|
|
3111
|
+
assert.equal(match[1].includes('--dsdel-'), false,
|
|
3112
|
+
'a sidebar rule must not read the page tokens: ' + match[0].slice(0, 60))
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
// Every host alias carries a literal fallback, so the box still draws when the
|
|
3116
|
+
// host renames its palette.
|
|
3117
|
+
assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-border-l2,[^)]*\)/, 'border has a fallback')
|
|
3118
|
+
assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-brand-primary,[^)]*\)/, 'brand has a fallback')
|
|
3119
|
+
})
|
|
3120
|
+
|
|
3121
|
+
test('a box always keeps a visible 15px square', async () => {
|
|
3122
|
+
const harness = await loadPlugin()
|
|
3123
|
+
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3124
|
+
|
|
3125
|
+
// A flex child with no width collapses to its content, and the empty state has
|
|
3126
|
+
// no content: `width` plus `min-width` plus content-box sizing is what makes the
|
|
3127
|
+
// square exist before anything is ticked.
|
|
3128
|
+
assert.match(css, /\.dsdel-select-all[^}]*width:15px/, 'a fixed width')
|
|
3129
|
+
assert.match(css, /\.dsdel-select-all[^}]*height:15px/, 'and a fixed height')
|
|
3130
|
+
assert.match(css, /\.dsdel-select-all[^}]*min-width:15px/, 'that flex cannot shrink away')
|
|
3131
|
+
assert.match(css, /\.dsdel-select-all[^}]*box-sizing:border-box/, 'with the border inside it')
|
|
3132
|
+
})
|
|
3133
|
+
|
|
3134
|
+
test('the workspace box sits beside the name, not at the row edge', async () => {
|
|
3135
|
+
const harness = await loadPlugin()
|
|
3136
|
+
const section = harness.document.createElement('div')
|
|
3137
|
+
section.setAttribute('role', 'group')
|
|
3138
|
+
|
|
3139
|
+
const header = harness.document.createElement('div')
|
|
3140
|
+
header.setAttribute('role', 'treeitem')
|
|
3141
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3142
|
+
|
|
3143
|
+
// The host row: label block, then the action cluster (which carries margin-left:auto).
|
|
3144
|
+
const label = harness.document.createElement('span')
|
|
3145
|
+
label.className = 'YDXeBa_projectText'
|
|
3146
|
+
header.appendChild(label)
|
|
3147
|
+
const actions = harness.document.createElement('span')
|
|
3148
|
+
actions.className = 'YDXeBa_rowActions'
|
|
3149
|
+
header.appendChild(actions)
|
|
3150
|
+
|
|
3151
|
+
section.appendChild(header)
|
|
3152
|
+
mountRow(harness, SESSION_A, section)
|
|
3153
|
+
harness.document.body.appendChild(section)
|
|
3154
|
+
|
|
3155
|
+
await enterMulti(harness)
|
|
3156
|
+
observerPass(harness)
|
|
3157
|
+
await flush()
|
|
3158
|
+
|
|
3159
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
3160
|
+
assert.ok(box, 'the box exists')
|
|
3161
|
+
|
|
3162
|
+
// Appending put it after the action cluster, whose auto margin pushes it into the
|
|
3163
|
+
// far right of the row — that is the "靠右" the screenshot showed. It has to be
|
|
3164
|
+
// inserted before the actions instead.
|
|
3165
|
+
const index = header.children.indexOf(box)
|
|
3166
|
+
const actionsIndex = header.children.indexOf(actions)
|
|
3167
|
+
assert.equal(index < actionsIndex, true, 'the box comes before the action cluster')
|
|
3168
|
+
assert.equal(header.children[index - 1].className, 'YDXeBa_projectText', 'and right after the label')
|
|
3169
|
+
})
|
|
3170
|
+
|
|
3171
|
+
test('the global box sits after the heading label, before the search slot', async () => {
|
|
3172
|
+
const harness = await loadPlugin()
|
|
3173
|
+
|
|
3174
|
+
const heading = harness.document.createElement('div')
|
|
3175
|
+
heading.setAttribute('data-sidebar-workspace-header', '')
|
|
3176
|
+
|
|
3177
|
+
const label = harness.document.createElement('span')
|
|
3178
|
+
label.className = 'bhn1Oq_sectionLabel'
|
|
3179
|
+
heading.appendChild(label)
|
|
3180
|
+
const search = harness.document.createElement('div')
|
|
3181
|
+
search.className = 'bhn1Oq_searchSlot'
|
|
3182
|
+
heading.appendChild(search)
|
|
3183
|
+
|
|
3184
|
+
harness.document.body.appendChild(heading)
|
|
3185
|
+
|
|
3186
|
+
const section = harness.document.createElement('div')
|
|
3187
|
+
section.setAttribute('role', 'group')
|
|
3188
|
+
const header = harness.document.createElement('div')
|
|
3189
|
+
header.setAttribute('role', 'treeitem')
|
|
3190
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3191
|
+
section.appendChild(header)
|
|
3192
|
+
mountRow(harness, SESSION_A, section)
|
|
3193
|
+
harness.document.body.appendChild(section)
|
|
3194
|
+
|
|
3195
|
+
await enterMulti(harness)
|
|
3196
|
+
observerPass(harness)
|
|
3197
|
+
await flush()
|
|
3198
|
+
|
|
3199
|
+
const box = heading.querySelector('.dsdel-select-all-workspaces')
|
|
3200
|
+
assert.ok(box, 'the global box exists')
|
|
3201
|
+
const index = heading.children.indexOf(box)
|
|
3202
|
+
assert.equal(index < heading.children.indexOf(search), true, 'before the search slot')
|
|
3203
|
+
assert.equal(heading.children[index - 1].className, 'bhn1Oq_sectionLabel', 'and after the label')
|
|
3204
|
+
})
|
|
3205
|
+
|
|
3206
|
+
test('a box left at the wrong edge is moved on the next pass', async () => {
|
|
3207
|
+
const harness = await loadPlugin()
|
|
3208
|
+
const section = harness.document.createElement('div')
|
|
3209
|
+
section.setAttribute('role', 'group')
|
|
3210
|
+
|
|
3211
|
+
const header = harness.document.createElement('div')
|
|
3212
|
+
header.setAttribute('role', 'treeitem')
|
|
3213
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3214
|
+
|
|
3215
|
+
const label = harness.document.createElement('span')
|
|
3216
|
+
label.className = 'wnFoaW_projectText'
|
|
3217
|
+
header.appendChild(label)
|
|
3218
|
+
const actions = harness.document.createElement('span')
|
|
3219
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3220
|
+
header.appendChild(actions)
|
|
3221
|
+
|
|
3222
|
+
// An earlier build left its box AFTER the actions: the far edge.
|
|
3223
|
+
const stale = harness.document.createElement('button')
|
|
3224
|
+
stale.className = 'dsdel-select-all'
|
|
3225
|
+
header.appendChild(stale)
|
|
3226
|
+
|
|
3227
|
+
section.appendChild(header)
|
|
3228
|
+
mountRow(harness, SESSION_A, section)
|
|
3229
|
+
harness.document.body.appendChild(section)
|
|
3230
|
+
|
|
3231
|
+
await enterMulti(harness)
|
|
3232
|
+
observerPass(harness)
|
|
3233
|
+
await flush()
|
|
3234
|
+
|
|
3235
|
+
// The insert used to live inside the "created" branch, so an existing box was
|
|
3236
|
+
// never repositioned: the heading box moved and the workspace box stayed put.
|
|
3237
|
+
const index = header.children.indexOf(stale)
|
|
3238
|
+
assert.equal(index < header.children.indexOf(actions), true, 'moved before the actions')
|
|
3239
|
+
assert.equal(header.children[index - 1].className, 'wnFoaW_projectText', 'and beside the label')
|
|
3240
|
+
})
|
|
3241
|
+
|
|
3242
|
+
test('the workspace name stops absorbing the row while the mode runs', async () => {
|
|
3243
|
+
const harness = await loadPlugin()
|
|
3244
|
+
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3245
|
+
|
|
3246
|
+
// `.projectText` carries `flex:1`, so it fills whatever the actions do not take.
|
|
3247
|
+
// A box inserted after it therefore lands at the row's far edge even though it
|
|
3248
|
+
// is early in the child list — that is why the workspace box stayed right while
|
|
3249
|
+
// the header box (whose label is not flexed) moved. The rule only applies while
|
|
3250
|
+
// the mode runs, so the host keeps its normal layout otherwise.
|
|
3251
|
+
assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*flex:0 1 auto/,
|
|
3252
|
+
'the name sizes to its text during the mode')
|
|
3253
|
+
assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*min-width:0/,
|
|
3254
|
+
'and can still truncate a long name')
|
|
3255
|
+
})
|
|
3256
|
+
|
|
3257
|
+
test('a spacer keeps the right-hand cluster in place', async () => {
|
|
3258
|
+
const harness = await loadPlugin()
|
|
3259
|
+
const section = harness.document.createElement('div')
|
|
3260
|
+
section.setAttribute('role', 'group')
|
|
3261
|
+
|
|
3262
|
+
const header = harness.document.createElement('div')
|
|
3263
|
+
header.setAttribute('role', 'treeitem')
|
|
3264
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3265
|
+
|
|
3266
|
+
const label = harness.document.createElement('span')
|
|
3267
|
+
label.className = 'wnFoaW_projectText'
|
|
3268
|
+
header.appendChild(label)
|
|
3269
|
+
// The cluster that must NOT move: count, menu, new-session.
|
|
3270
|
+
const actions = harness.document.createElement('span')
|
|
3271
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3272
|
+
header.appendChild(actions)
|
|
3273
|
+
|
|
3274
|
+
section.appendChild(header)
|
|
3275
|
+
mountRow(harness, SESSION_A, section)
|
|
3276
|
+
harness.document.body.appendChild(section)
|
|
3277
|
+
|
|
3278
|
+
await enterMulti(harness)
|
|
3279
|
+
observerPass(harness)
|
|
3280
|
+
await flush()
|
|
3281
|
+
|
|
3282
|
+
// Order has to be: label, box, spacer, actions. With the spacer growing, the
|
|
3283
|
+
// name keeps its natural width and the cluster stays at the row's end; without
|
|
3284
|
+
// it, every flex child simply packs left and the count/menu/new buttons slid
|
|
3285
|
+
// over with the box.
|
|
3286
|
+
const kids = header.children
|
|
3287
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
3288
|
+
const spacer = header.querySelector('.dsdel-flex-spacer')
|
|
3289
|
+
assert.ok(box, 'the box exists')
|
|
3290
|
+
assert.ok(spacer, 'the spacer exists')
|
|
3291
|
+
|
|
3292
|
+
assert.equal(kids.indexOf(box) < kids.indexOf(spacer), true, 'box before spacer')
|
|
3293
|
+
assert.equal(kids.indexOf(spacer) < kids.indexOf(actions), true, 'spacer before the cluster')
|
|
3294
|
+
assert.equal(kids.indexOf(label) < kids.indexOf(box), true, 'label first')
|
|
3295
|
+
})
|
|
3296
|
+
|
|
3297
|
+
test('the spacer is removed with the mode', async () => {
|
|
3298
|
+
const harness = await loadPlugin()
|
|
3299
|
+
const section = harness.document.createElement('div')
|
|
3300
|
+
section.setAttribute('role', 'group')
|
|
3301
|
+
const header = harness.document.createElement('div')
|
|
3302
|
+
header.setAttribute('role', 'treeitem')
|
|
3303
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3304
|
+
const label = harness.document.createElement('span')
|
|
3305
|
+
label.className = 'wnFoaW_projectText'
|
|
3306
|
+
header.appendChild(label)
|
|
3307
|
+
const actions = harness.document.createElement('span')
|
|
3308
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3309
|
+
header.appendChild(actions)
|
|
3310
|
+
section.appendChild(header)
|
|
3311
|
+
mountRow(harness, SESSION_A, section)
|
|
3312
|
+
harness.document.body.appendChild(section)
|
|
3313
|
+
|
|
3314
|
+
await enterMulti(harness)
|
|
3315
|
+
observerPass(harness)
|
|
3316
|
+
await flush()
|
|
3317
|
+
assert.ok(header.querySelector('.dsdel-flex-spacer'), 'spacer present during the mode')
|
|
3318
|
+
|
|
3319
|
+
// The bar's Cancel is the mode's own exit route. Escape would also reach
|
|
3320
|
+
// handlers left behind by earlier tests: the stub never unregisters one.
|
|
3321
|
+
clickBar(barCancel(harness))
|
|
3322
|
+
observerPass(harness)
|
|
3323
|
+
await flush()
|
|
3324
|
+
assert.equal(header.querySelector('.dsdel-flex-spacer'), null, 'gone with the mode')
|
|
3325
|
+
assert.equal(header.querySelector('.dsdel-select-all'), null, 'and so is the box')
|
|
3326
|
+
})
|
|
3327
|
+
|
|
3328
|
+
test('PROBE exit removes spacer', async () => {
|
|
3329
|
+
const harness = await loadPlugin()
|
|
3330
|
+
const section = harness.document.createElement('div')
|
|
3331
|
+
section.setAttribute('role', 'group')
|
|
3332
|
+
const header = harness.document.createElement('div')
|
|
3333
|
+
header.setAttribute('role', 'treeitem')
|
|
3334
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3335
|
+
const actions = harness.document.createElement('span')
|
|
3336
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3337
|
+
header.appendChild(actions)
|
|
3338
|
+
section.appendChild(header)
|
|
3339
|
+
mountRow(harness, SESSION_A, section)
|
|
3340
|
+
harness.document.body.appendChild(section)
|
|
3341
|
+
|
|
3342
|
+
await enterMulti(harness)
|
|
3343
|
+
observerPass(harness)
|
|
3344
|
+
await flush()
|
|
3345
|
+
|
|
3346
|
+
const before = harness.document.querySelectorAll('.dsdel-flex-spacer').length
|
|
3347
|
+
console.log('PROBE 装饰后 spacer 数:', before)
|
|
3348
|
+
for (const el of harness.document.querySelectorAll('.dsdel-flex-spacer')) {
|
|
3349
|
+
console.log('PROBE spacer parent:', el.parentElement && el.parentElement.getAttribute('data-row-key'), 'idx:', el.parentElement ? el.parentElement.children.indexOf(el) : -1)
|
|
3350
|
+
}
|
|
3351
|
+
const cancel = barCancel(harness)
|
|
3352
|
+
console.log('PROBE cancel 节点:', cancel && cancel.props && cancel.props.className)
|
|
3353
|
+
clickBar(cancel)
|
|
3354
|
+
await flush()
|
|
3355
|
+
console.log('PROBE 退出后 spacer 数:', harness.document.querySelectorAll('.dsdel-flex-spacer').length)
|
|
3356
|
+
assert.ok(true)
|
|
3357
|
+
})
|
|
3358
|
+
|
|
3359
|
+
test('the spacer is the growing child, so the cluster keeps its seat', async () => {
|
|
3360
|
+
const harness = await loadPlugin()
|
|
3361
|
+
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3362
|
+
|
|
3363
|
+
// Without a growing child the flex row simply packs left, which drags the count
|
|
3364
|
+
// and the action buttons along with the box. The spacer is what holds them at
|
|
3365
|
+
// the row's end while the box sits beside the name.
|
|
3366
|
+
assert.match(css, /\.dsdel-flex-spacer\{[^}]*flex:1/, 'the spacer grows')
|
|
3367
|
+
assert.match(css, /\.dsdel-flex-spacer\{[^}]*min-width:0/, 'and can collapse when space is tight')
|
|
3368
|
+
assert.match(css, /\.dsdel-select-all[^}]*flex:0 0 auto/, 'the box itself does not grow')
|
|
3369
|
+
})
|
|
3370
|
+
|
|
3371
|
+
test('a document click on a plugin-drawn element leaves the session alone', async () => {
|
|
3372
|
+
const harness = await loadPlugin()
|
|
3373
|
+
const row = mountRow(harness, SESSION_A)
|
|
3374
|
+
await enterMulti(harness)
|
|
3375
|
+
observerPass(harness)
|
|
3376
|
+
await flush()
|
|
3377
|
+
assert.equal(harness.document.body.className.includes('dsdel-selecting'), true)
|
|
3378
|
+
|
|
3379
|
+
// The document capture listener runs before any element handler. It must ignore
|
|
3380
|
+
// elements this plugin drew — a box inside a workspace row is the everyday case,
|
|
3381
|
+
// and inside a session row it would otherwise toggle that session.
|
|
3382
|
+
const box = harness.document.createElement('button')
|
|
3383
|
+
box.className = 'dsdel-select-all'
|
|
3384
|
+
box.setAttribute('data-dsh-delete-session', 'select-all')
|
|
3385
|
+
row.appendChild(box)
|
|
3386
|
+
|
|
3387
|
+
clickRowIn(harness, box)
|
|
3388
|
+
observerPass(harness)
|
|
3389
|
+
await flush()
|
|
3390
|
+
|
|
3391
|
+
const check = row.querySelector('.dsdel-check')
|
|
3392
|
+
assert.equal(check.classList.contains('dsdel-check-on'), false, 'no session was toggled')
|
|
3393
|
+
})
|
|
3394
|
+
|
|
3395
|
+
test('the row handler still works for a real session row', async () => {
|
|
3396
|
+
const harness = await loadPlugin()
|
|
3397
|
+
const row = mountRow(harness, SESSION_A)
|
|
3398
|
+
await enterMulti(harness)
|
|
3399
|
+
observerPass(harness)
|
|
3400
|
+
await flush()
|
|
3401
|
+
|
|
3402
|
+
clickRowIn(harness, row)
|
|
3403
|
+
await flush()
|
|
3404
|
+
|
|
3405
|
+
const check = row.querySelector('.dsdel-check')
|
|
3406
|
+
assert.equal(check.classList.contains('dsdel-check-on'), true, 'a plain row still toggles')
|
|
3407
|
+
})
|
|
3408
|
+
|
|
3409
|
+
test('a decorate pass with nothing to move keeps the box where it is', async () => {
|
|
3410
|
+
const harness = await loadPlugin()
|
|
3411
|
+
const section = harness.document.createElement('div')
|
|
3412
|
+
section.setAttribute('role', 'group')
|
|
3413
|
+
const header = harness.document.createElement('div')
|
|
3414
|
+
header.setAttribute('role', 'treeitem')
|
|
3415
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3416
|
+
const label = harness.document.createElement('span')
|
|
3417
|
+
label.className = 'wnFoaW_projectText'
|
|
3418
|
+
header.appendChild(label)
|
|
3419
|
+
const actions = harness.document.createElement('span')
|
|
3420
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3421
|
+
header.appendChild(actions)
|
|
3422
|
+
section.appendChild(header)
|
|
3423
|
+
mountRow(harness, SESSION_A, section)
|
|
3424
|
+
harness.document.body.appendChild(section)
|
|
3425
|
+
|
|
3426
|
+
await enterMulti(harness)
|
|
3427
|
+
observerPass(harness)
|
|
3428
|
+
await flush()
|
|
3429
|
+
|
|
3430
|
+
// Every insertBefore is a mutation, and the list observer counted it as a
|
|
3431
|
+
// reason to scan again: each pass scheduled the next one, forever, and the box
|
|
3432
|
+
// was detached and re-attached under the pointer. Nothing may move here — the
|
|
3433
|
+
// box and its spacer are already in the right place.
|
|
3434
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
3435
|
+
const spacer = header.querySelector('.dsdel-flex-spacer')
|
|
3436
|
+
const index = header.children.indexOf(box)
|
|
3437
|
+
|
|
3438
|
+
// Re-inserting a node where it already sits leaves its index unchanged, so the
|
|
3439
|
+
// index alone cannot prove the pass was quiet. Count the calls instead: a real
|
|
3440
|
+
// insertBefore produces a MutationRecord, and the observer used to feed on them.
|
|
3441
|
+
const realInsert = header.insertBefore.bind(header)
|
|
3442
|
+
let inserts = 0
|
|
3443
|
+
header.insertBefore = (child, ref) => { inserts += 1; return realInsert(child, ref) }
|
|
3444
|
+
|
|
3445
|
+
observerPass(harness)
|
|
3446
|
+
observerPass(harness)
|
|
3447
|
+
await flush()
|
|
3448
|
+
|
|
3449
|
+
assert.equal(inserts, 0, 'a settled row is left untouched')
|
|
3450
|
+
|
|
3451
|
+
assert.equal(header.children.indexOf(box), index, 'the box did not move')
|
|
3452
|
+
assert.equal(header.children.indexOf(spacer), index + 1, 'nor did the spacer')
|
|
3453
|
+
assert.equal(header.children.filter((el) => el === box).length, 1, 'and there is only one')
|
|
3454
|
+
})
|
|
3455
|
+
|
|
3456
|
+
test('a mutation naming only our own nodes schedules no pass', async () => {
|
|
3457
|
+
const harness = await loadPlugin()
|
|
3458
|
+
|
|
3459
|
+
// Drive the frame queue by hand: a timer-based flush made this test flaky,
|
|
3460
|
+
// because a pass can queue another callback while it runs.
|
|
3461
|
+
//
|
|
3462
|
+
// Note the drain: emptying the queue without running its callbacks leaves the
|
|
3463
|
+
// plugin's `decorateRaf` handle truthy, and every later `scheduleDecorate`
|
|
3464
|
+
// silently returns. That is a harness trap, not a product bug.
|
|
3465
|
+
const queued = []
|
|
3466
|
+
const realRaf = globalThis.requestAnimationFrame
|
|
3467
|
+
const realCancel = globalThis.cancelAnimationFrame
|
|
3468
|
+
globalThis.requestAnimationFrame = (fn) => { queued.push(fn); return queued.length }
|
|
3469
|
+
globalThis.cancelAnimationFrame = () => {}
|
|
3470
|
+
const drain = () => { let guard = 0; while (queued.length > 0 && guard < 50) { guard += 1; queued.shift()() } }
|
|
3471
|
+
|
|
3472
|
+
try {
|
|
3473
|
+
await enterMulti(harness)
|
|
3474
|
+
drain()
|
|
3475
|
+
|
|
3476
|
+
// A row that arrives after the last pass carries no checkbox, so whether a
|
|
3477
|
+
// pass runs is readable straight off the DOM.
|
|
3478
|
+
const section = harness.document.createElement('div')
|
|
3479
|
+
section.setAttribute('role', 'group')
|
|
3480
|
+
const hostRow = harness.document.createElement('div')
|
|
3481
|
+
hostRow.setAttribute('role', 'treeitem')
|
|
3482
|
+
hostRow.setAttribute('data-row-key', 'session:session-cccc1111-2222-4333-8444-555555555555')
|
|
3483
|
+
section.appendChild(hostRow)
|
|
3484
|
+
harness.document.body.appendChild(section)
|
|
3485
|
+
assert.equal(hostRow.querySelector('.dsdel-check'), null, 'the row is undecorated')
|
|
3486
|
+
|
|
3487
|
+
// Decorate inserts checkboxes, and the list observer reports them right back.
|
|
3488
|
+
// Every such record used to schedule another pass, so the loop never settled:
|
|
3489
|
+
// the box was re-inserted under the pointer and a click often missed.
|
|
3490
|
+
const own = harness.document.createElement('span')
|
|
3491
|
+
own.setAttribute('data-dsh-delete-session', 'check')
|
|
3492
|
+
harness.observers[0].callback([{ addedNodes: [own], removedNodes: [] }])
|
|
3493
|
+
assert.equal(queued.length, 0, 'our own node schedules nothing')
|
|
3494
|
+
|
|
3495
|
+
// A host change must still get through.
|
|
3496
|
+
harness.observers[0].callback([{ addedNodes: [hostRow], removedNodes: [] }])
|
|
3497
|
+
assert.equal(queued.length, 1, 'a real host row schedules one pass')
|
|
3498
|
+
drain()
|
|
3499
|
+
assert.ok(hostRow.querySelector('.dsdel-check'), 'and that pass decorates it')
|
|
3500
|
+
} finally {
|
|
3501
|
+
globalThis.requestAnimationFrame = realRaf
|
|
3502
|
+
globalThis.cancelAnimationFrame = realCancel
|
|
3503
|
+
}
|
|
3504
|
+
})
|
|
3505
|
+
|
|
3506
|
+
test('the plugin never calls array methods on a live child list', async () => {
|
|
3507
|
+
const source = await readFile(new URL('../src/client.js', import.meta.url), 'utf8')
|
|
3508
|
+
|
|
3509
|
+
// In a browser `element.children` is an HTMLCollection: it has `length` and
|
|
3510
|
+
// indexing, and none of the Array methods. The test stub uses a plain array, so
|
|
3511
|
+
// `children.indexOf(...)` passed here and threw a TypeError in the real host —
|
|
3512
|
+
// the decorate pass died before inserting anything, and the select-all box never
|
|
3513
|
+
// appeared. Index it by hand (`childIndex`) or spread it first.
|
|
3514
|
+
const offenders = []
|
|
3515
|
+
for (const match of source.matchAll(/\.children\.([A-Za-z]+)\s*\(/g)) {
|
|
3516
|
+
offenders.push(match[0])
|
|
3517
|
+
}
|
|
3518
|
+
assert.deepEqual(offenders, [], 'no Array methods on `children`')
|
|
3519
|
+
})
|
|
3520
|
+
|
|
3521
|
+
test('the workspace box reaches past a wrapping element', async () => {
|
|
3522
|
+
const harness = await loadPlugin()
|
|
3523
|
+
const section = harness.document.createElement('div')
|
|
3524
|
+
section.setAttribute('role', 'group')
|
|
3525
|
+
|
|
3526
|
+
// The real host wraps the workspace row in HoverCard's <span>, so the row's
|
|
3527
|
+
// parentElement is that span, not the section. A subtree query from the span
|
|
3528
|
+
// returns only the workspace row itself and the box ends up with no ids —
|
|
3529
|
+
// `toggleGroup` then returns without doing anything, which is exactly the
|
|
3530
|
+
// "single-workspace select-all does nothing" report.
|
|
3531
|
+
const wrapper = harness.document.createElement('span')
|
|
3532
|
+
wrapper.className = 'HoverCard_root'
|
|
3533
|
+
const header = harness.document.createElement('div')
|
|
3534
|
+
header.setAttribute('role', 'treeitem')
|
|
3535
|
+
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3536
|
+
const label = harness.document.createElement('span')
|
|
3537
|
+
label.className = 'wnFoaW_projectText'
|
|
3538
|
+
header.appendChild(label)
|
|
3539
|
+
const actions = harness.document.createElement('span')
|
|
3540
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3541
|
+
header.appendChild(actions)
|
|
3542
|
+
wrapper.appendChild(header)
|
|
3543
|
+
section.appendChild(wrapper)
|
|
3544
|
+
|
|
3545
|
+
mountRow(harness, SESSION_A, section)
|
|
3546
|
+
mountRow(harness, SESSION_B, section)
|
|
3547
|
+
harness.document.body.appendChild(section)
|
|
3548
|
+
|
|
3549
|
+
await enterMulti(harness)
|
|
3550
|
+
observerPass(harness)
|
|
3551
|
+
await flush()
|
|
3552
|
+
|
|
3553
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
3554
|
+
assert.ok(box, 'the box exists')
|
|
3555
|
+
assert.deepEqual(box.__dsdelIds, [SESSION_A.id, SESSION_B.id], 'both sessions were found')
|
|
3556
|
+
|
|
3557
|
+
box.fire('click')
|
|
3558
|
+
await flush()
|
|
3559
|
+
assert.equal(box.getAttribute('aria-checked'), 'true', 'and pressing it selects them')
|
|
3560
|
+
})
|
|
3561
|
+
|
|
3562
|
+
test('a workspace box never reaches into a nested workspace', async () => {
|
|
3563
|
+
const harness = await loadPlugin()
|
|
3564
|
+
const section = harness.document.createElement('div')
|
|
3565
|
+
section.setAttribute('role', 'group')
|
|
3566
|
+
|
|
3567
|
+
const header = harness.document.createElement('div')
|
|
3568
|
+
header.setAttribute('role', 'treeitem')
|
|
3569
|
+
header.setAttribute('data-row-key', 'workspace:outer')
|
|
3570
|
+
const actions = harness.document.createElement('span')
|
|
3571
|
+
actions.className = 'wnFoaW_rowActions'
|
|
3572
|
+
header.appendChild(actions)
|
|
3573
|
+
section.appendChild(header)
|
|
3574
|
+
mountRow(harness, SESSION_A, section)
|
|
3575
|
+
|
|
3576
|
+
// A nested workspace is a `div[role="group"]` holding its own rows.
|
|
3577
|
+
const nested = harness.document.createElement('div')
|
|
3578
|
+
nested.setAttribute('role', 'group')
|
|
3579
|
+
const nestedHeader = harness.document.createElement('div')
|
|
3580
|
+
nestedHeader.setAttribute('role', 'treeitem')
|
|
3581
|
+
nestedHeader.setAttribute('data-row-key', 'workspace:inner')
|
|
3582
|
+
nested.appendChild(nestedHeader)
|
|
3583
|
+
mountRow(harness, SESSION_B, nested)
|
|
3584
|
+
section.appendChild(nested)
|
|
3585
|
+
|
|
3586
|
+
harness.document.body.appendChild(section)
|
|
3587
|
+
|
|
3588
|
+
await enterMulti(harness)
|
|
3589
|
+
observerPass(harness)
|
|
3590
|
+
await flush()
|
|
3591
|
+
|
|
3592
|
+
const box = header.querySelector('.dsdel-select-all')
|
|
3593
|
+
assert.deepEqual(box.__dsdelIds, [SESSION_A.id], 'only the outer group\'s own session')
|
|
2881
3594
|
})
|
|
2882
3595
|
|
|
2883
|
-
test('
|
|
2884
|
-
const harness = await loadPlugin()
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
await flush()
|
|
2891
|
-
|
|
2892
|
-
const node = bar(harness)
|
|
2893
|
-
const text = JSON.stringify(node.props.children)
|
|
2894
|
-
|
|
2895
|
-
// The dictionary entry is `松手删除「{name}」`, but the interpolation map carries
|
|
2896
|
-
// `n`/`done`/`total`/`ok`/`fail`/`path` — not `name`. Passing the title as a bare
|
|
2897
|
-
// string therefore left the braces in the label.
|
|
2898
|
-
assert.doesNotMatch(text, /\{name\}/, 'no unsubstituted placeholder in the label')
|
|
2899
|
-
assert.match(text, /松手删除/, 'the sentence is still there')
|
|
2900
|
-
})
|
|
2901
|
-
|
|
2902
|
-
test('the drop label carries the dragged conversation title', async () => {
|
|
2903
|
-
const harness = await loadPlugin()
|
|
2904
|
-
const row = mountRow(harness, SESSION_A)
|
|
2905
|
-
row.textContent = 'BiliLearn-AI 仓库'
|
|
2906
|
-
|
|
2907
|
-
startRowDrag(harness, row)
|
|
2908
|
-
await flush()
|
|
2909
|
-
bar(harness).props.onDragOver(dropEvent())
|
|
2910
|
-
await flush()
|
|
2911
|
-
|
|
2912
|
-
const text = JSON.stringify(bar(harness).props.children)
|
|
2913
|
-
assert.match(text, /BiliLearn-AI 仓库/, 'the title reaches the sentence')
|
|
2914
|
-
})
|
|
2915
|
-
test('a workspace header offers a select-all box', async () => {
|
|
2916
|
-
const harness = await loadPlugin()
|
|
2917
|
-
const section = harness.document.createElement('div')
|
|
2918
|
-
section.setAttribute('role', 'group')
|
|
2919
|
-
|
|
2920
|
-
const header = harness.document.createElement('div')
|
|
2921
|
-
header.setAttribute('role', 'treeitem')
|
|
2922
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
2923
|
-
section.appendChild(header)
|
|
2924
|
-
|
|
2925
|
-
mountRow(harness, SESSION_A, section)
|
|
2926
|
-
mountRow(harness, SESSION_B, section)
|
|
2927
|
-
harness.document.body.appendChild(section)
|
|
2928
|
-
|
|
2929
|
-
await enterMulti(harness)
|
|
2930
|
-
observerPass(harness)
|
|
2931
|
-
await flush()
|
|
2932
|
-
|
|
2933
|
-
const box = header.querySelector('.dsdel-select-all')
|
|
2934
|
-
assert.ok(box, 'the header carries one')
|
|
2935
|
-
assert.equal(box.getAttribute('role'), 'checkbox')
|
|
2936
|
-
assert.equal(box.getAttribute('aria-checked'), 'false', 'nothing picked yet')
|
|
2937
|
-
})
|
|
2938
|
-
|
|
2939
|
-
test('the workspace box selects only its own sessions', async () => {
|
|
2940
|
-
const harness = await loadPlugin()
|
|
2941
|
-
const sectionA = harness.document.createElement('div')
|
|
2942
|
-
sectionA.setAttribute('role', 'group')
|
|
2943
|
-
const headA = harness.document.createElement('div')
|
|
2944
|
-
headA.setAttribute('role', 'treeitem')
|
|
2945
|
-
headA.setAttribute('data-row-key', 'workspace:ws-a')
|
|
2946
|
-
sectionA.appendChild(headA)
|
|
2947
|
-
mountRow(harness, SESSION_A, sectionA)
|
|
2948
|
-
harness.document.body.appendChild(sectionA)
|
|
2949
|
-
|
|
2950
|
-
const sectionB = harness.document.createElement('div')
|
|
2951
|
-
sectionB.setAttribute('role', 'group')
|
|
2952
|
-
const headB = harness.document.createElement('div')
|
|
2953
|
-
headB.setAttribute('role', 'treeitem')
|
|
2954
|
-
headB.setAttribute('data-row-key', 'workspace:ws-b')
|
|
2955
|
-
sectionB.appendChild(headB)
|
|
2956
|
-
mountRow(harness, SESSION_B, sectionB)
|
|
2957
|
-
harness.document.body.appendChild(sectionB)
|
|
2958
|
-
|
|
2959
|
-
await enterMulti(harness)
|
|
2960
|
-
observerPass(harness)
|
|
2961
|
-
await flush()
|
|
2962
|
-
|
|
2963
|
-
headA.querySelector('.dsdel-select-all').fire('click')
|
|
2964
|
-
await flush()
|
|
2965
|
-
|
|
2966
|
-
assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true', 'A turned on')
|
|
2967
|
-
const boxB = headB.querySelector('.dsdel-select-all')
|
|
2968
|
-
assert.equal(boxB.getAttribute('aria-checked'), 'false', 'B untouched')
|
|
2969
|
-
})
|
|
2970
|
-
|
|
2971
|
-
test('a second press clears the workspace again', async () => {
|
|
2972
|
-
const harness = await loadPlugin()
|
|
2973
|
-
const section = harness.document.createElement('div')
|
|
2974
|
-
section.setAttribute('role', 'group')
|
|
2975
|
-
const header = harness.document.createElement('div')
|
|
2976
|
-
header.setAttribute('role', 'treeitem')
|
|
2977
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
2978
|
-
section.appendChild(header)
|
|
2979
|
-
mountRow(harness, SESSION_A, section)
|
|
2980
|
-
harness.document.body.appendChild(section)
|
|
2981
|
-
|
|
2982
|
-
await enterMulti(harness)
|
|
2983
|
-
observerPass(harness)
|
|
2984
|
-
await flush()
|
|
2985
|
-
|
|
2986
|
-
const box = header.querySelector('.dsdel-select-all')
|
|
2987
|
-
box.fire('click')
|
|
2988
|
-
await flush()
|
|
2989
|
-
assert.equal(box.getAttribute('aria-checked'), 'true')
|
|
2990
|
-
|
|
2991
|
-
box.fire('click')
|
|
2992
|
-
await flush()
|
|
2993
|
-
assert.equal(box.getAttribute('aria-checked'), 'false')
|
|
2994
|
-
})
|
|
2995
|
-
|
|
2996
|
-
test('the box reports a partly picked workspace as mixed', async () => {
|
|
2997
|
-
const harness = await loadPlugin()
|
|
2998
|
-
const section = harness.document.createElement('div')
|
|
2999
|
-
section.setAttribute('role', 'group')
|
|
3000
|
-
const header = harness.document.createElement('div')
|
|
3001
|
-
header.setAttribute('role', 'treeitem')
|
|
3002
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3003
|
-
section.appendChild(header)
|
|
3004
|
-
const rowA = mountRow(harness, SESSION_A, section)
|
|
3005
|
-
mountRow(harness, SESSION_B, section)
|
|
3006
|
-
harness.document.body.appendChild(section)
|
|
3007
|
-
|
|
3008
|
-
await enterMulti(harness)
|
|
3009
|
-
observerPass(harness)
|
|
3010
|
-
await flush()
|
|
3011
|
-
|
|
3012
|
-
clickRowIn(harness, rowA)
|
|
3013
|
-
observerPass(harness)
|
|
3014
|
-
await flush()
|
|
3015
|
-
|
|
3016
|
-
assert.equal(header.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'mixed')
|
|
3017
|
-
})
|
|
3018
|
-
|
|
3019
|
-
test('the heading row selects every workspace at once', async () => {
|
|
3020
|
-
const harness = await loadPlugin()
|
|
3021
|
-
const heading = harness.document.createElement('div')
|
|
3022
|
-
heading.setAttribute('data-sidebar-workspace-header', '')
|
|
3023
|
-
harness.document.body.appendChild(heading)
|
|
3024
|
-
|
|
3025
|
-
const sectionA = harness.document.createElement('div')
|
|
3026
|
-
sectionA.setAttribute('role', 'group')
|
|
3027
|
-
const headA = harness.document.createElement('div')
|
|
3028
|
-
headA.setAttribute('role', 'treeitem')
|
|
3029
|
-
headA.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3030
|
-
sectionA.appendChild(headA)
|
|
3031
|
-
mountRow(harness, SESSION_A, sectionA)
|
|
3032
|
-
harness.document.body.appendChild(sectionA)
|
|
3033
|
-
|
|
3034
|
-
const sectionB = harness.document.createElement('div')
|
|
3035
|
-
sectionB.setAttribute('role', 'group')
|
|
3036
|
-
const headB = harness.document.createElement('div')
|
|
3037
|
-
headB.setAttribute('role', 'treeitem')
|
|
3038
|
-
headB.setAttribute('data-row-key', 'workspace:ws-b')
|
|
3039
|
-
sectionB.appendChild(headB)
|
|
3040
|
-
mountRow(harness, SESSION_B, sectionB)
|
|
3041
|
-
harness.document.body.appendChild(sectionB)
|
|
3042
|
-
|
|
3043
|
-
await enterMulti(harness)
|
|
3044
|
-
observerPass(harness)
|
|
3045
|
-
await flush()
|
|
3046
|
-
|
|
3047
|
-
const all = heading.querySelector('.dsdel-select-all-workspaces')
|
|
3048
|
-
assert.ok(all, 'the heading carries the global box')
|
|
3049
|
-
all.fire('click')
|
|
3050
|
-
await flush()
|
|
3051
|
-
|
|
3052
|
-
assert.equal(all.getAttribute('aria-checked'), 'true', 'everything picked')
|
|
3053
|
-
assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
|
|
3054
|
-
assert.equal(headB.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
|
|
3055
|
-
})
|
|
3056
|
-
|
|
3057
|
-
test('both boxes go away when the mode ends', async () => {
|
|
3058
|
-
const harness = await loadPlugin()
|
|
3059
|
-
const heading = harness.document.createElement('div')
|
|
3060
|
-
heading.setAttribute('data-sidebar-workspace-header', '')
|
|
3061
|
-
harness.document.body.appendChild(heading)
|
|
3062
|
-
|
|
3063
|
-
const section = harness.document.createElement('div')
|
|
3064
|
-
section.setAttribute('role', 'group')
|
|
3065
|
-
const header = harness.document.createElement('div')
|
|
3066
|
-
header.setAttribute('role', 'treeitem')
|
|
3067
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3068
|
-
section.appendChild(header)
|
|
3069
|
-
mountRow(harness, SESSION_A, section)
|
|
3070
|
-
harness.document.body.appendChild(section)
|
|
3071
|
-
|
|
3072
|
-
await enterMulti(harness)
|
|
3073
|
-
observerPass(harness)
|
|
3074
|
-
await flush()
|
|
3075
|
-
assert.ok(header.querySelector('.dsdel-select-all'), 'present during the mode')
|
|
3076
|
-
assert.ok(heading.querySelector('.dsdel-select-all-workspaces'))
|
|
3077
|
-
|
|
3078
|
-
harness.document.dispatchToDocument('keydown', { key: 'Escape', stopPropagation() {} })
|
|
3079
|
-
observerPass(harness)
|
|
3080
|
-
await flush()
|
|
3081
|
-
|
|
3082
|
-
assert.equal(header.querySelector('.dsdel-select-all'), null, 'removed with the mode')
|
|
3083
|
-
assert.equal(heading.querySelector('.dsdel-select-all-workspaces'), null)
|
|
3084
|
-
})
|
|
3085
|
-
|
|
3086
|
-
test('the select-all boxes do not lean on the page token scope', async () => {
|
|
3087
|
-
const harness = await loadPlugin()
|
|
3088
|
-
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3089
|
-
|
|
3090
|
-
// The boxes render inside the SIDEBAR. The `--dsdel-*` tokens are declared on
|
|
3091
|
-
// `.dsdel-page`, `.dsdel-modal` and `.dsdel-bar` only, so any rule outside those
|
|
3092
|
-
// scopes that reads them gets an invalid value and loses the whole declaration.
|
|
3093
|
-
// That is how the first version shipped an invisible button: `border` was
|
|
3094
|
-
// dropped, leaving no box and nothing to click.
|
|
3095
|
-
const rules = [...css.matchAll(/(?:^|\})\s*\.dsdel-select-all[^{]*\{([^}]*)\}/g)]
|
|
3096
|
-
assert.ok(rules.length > 0, 'the rules are in the stylesheet')
|
|
3097
|
-
for (const match of rules) {
|
|
3098
|
-
assert.equal(match[1].includes('--dsdel-'), false,
|
|
3099
|
-
'a sidebar rule must not read the page tokens: ' + match[0].slice(0, 60))
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
// Every host alias carries a literal fallback, so the box still draws when the
|
|
3103
|
-
// host renames its palette.
|
|
3104
|
-
assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-border-l2,[^)]*\)/, 'border has a fallback')
|
|
3105
|
-
assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-brand-primary,[^)]*\)/, 'brand has a fallback')
|
|
3106
|
-
})
|
|
3107
|
-
|
|
3108
|
-
test('a box always keeps a visible 15px square', async () => {
|
|
3109
|
-
const harness = await loadPlugin()
|
|
3110
|
-
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3111
|
-
|
|
3112
|
-
// A flex child with no width collapses to its content, and the empty state has
|
|
3113
|
-
// no content: `width` plus `min-width` plus content-box sizing is what makes the
|
|
3114
|
-
// square exist before anything is ticked.
|
|
3115
|
-
assert.match(css, /\.dsdel-select-all[^}]*width:15px/, 'a fixed width')
|
|
3116
|
-
assert.match(css, /\.dsdel-select-all[^}]*height:15px/, 'and a fixed height')
|
|
3117
|
-
assert.match(css, /\.dsdel-select-all[^}]*min-width:15px/, 'that flex cannot shrink away')
|
|
3118
|
-
assert.match(css, /\.dsdel-select-all[^}]*box-sizing:border-box/, 'with the border inside it')
|
|
3119
|
-
})
|
|
3120
|
-
|
|
3121
|
-
test('the workspace box sits beside the name, not at the row edge', async () => {
|
|
3122
|
-
const harness = await loadPlugin()
|
|
3123
|
-
const section = harness.document.createElement('div')
|
|
3124
|
-
section.setAttribute('role', 'group')
|
|
3125
|
-
|
|
3126
|
-
const header = harness.document.createElement('div')
|
|
3127
|
-
header.setAttribute('role', 'treeitem')
|
|
3128
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3129
|
-
|
|
3130
|
-
// The host row: label block, then the action cluster (which carries margin-left:auto).
|
|
3131
|
-
const label = harness.document.createElement('span')
|
|
3132
|
-
label.className = 'YDXeBa_projectText'
|
|
3133
|
-
header.appendChild(label)
|
|
3134
|
-
const actions = harness.document.createElement('span')
|
|
3135
|
-
actions.className = 'YDXeBa_rowActions'
|
|
3136
|
-
header.appendChild(actions)
|
|
3137
|
-
|
|
3138
|
-
section.appendChild(header)
|
|
3139
|
-
mountRow(harness, SESSION_A, section)
|
|
3140
|
-
harness.document.body.appendChild(section)
|
|
3141
|
-
|
|
3142
|
-
await enterMulti(harness)
|
|
3143
|
-
observerPass(harness)
|
|
3144
|
-
await flush()
|
|
3145
|
-
|
|
3146
|
-
const box = header.querySelector('.dsdel-select-all')
|
|
3147
|
-
assert.ok(box, 'the box exists')
|
|
3148
|
-
|
|
3149
|
-
// Appending put it after the action cluster, whose auto margin pushes it into the
|
|
3150
|
-
// far right of the row — that is the "靠右" the screenshot showed. It has to be
|
|
3151
|
-
// inserted before the actions instead.
|
|
3152
|
-
const index = header.children.indexOf(box)
|
|
3153
|
-
const actionsIndex = header.children.indexOf(actions)
|
|
3154
|
-
assert.equal(index < actionsIndex, true, 'the box comes before the action cluster')
|
|
3155
|
-
assert.equal(header.children[index - 1].className, 'YDXeBa_projectText', 'and right after the label')
|
|
3156
|
-
})
|
|
3157
|
-
|
|
3158
|
-
test('the global box sits after the heading label, before the search slot', async () => {
|
|
3159
|
-
const harness = await loadPlugin()
|
|
3160
|
-
|
|
3161
|
-
const heading = harness.document.createElement('div')
|
|
3162
|
-
heading.setAttribute('data-sidebar-workspace-header', '')
|
|
3163
|
-
|
|
3164
|
-
const label = harness.document.createElement('span')
|
|
3165
|
-
label.className = 'bhn1Oq_sectionLabel'
|
|
3166
|
-
heading.appendChild(label)
|
|
3167
|
-
const search = harness.document.createElement('div')
|
|
3168
|
-
search.className = 'bhn1Oq_searchSlot'
|
|
3169
|
-
heading.appendChild(search)
|
|
3170
|
-
|
|
3171
|
-
harness.document.body.appendChild(heading)
|
|
3172
|
-
|
|
3173
|
-
const section = harness.document.createElement('div')
|
|
3174
|
-
section.setAttribute('role', 'group')
|
|
3175
|
-
const header = harness.document.createElement('div')
|
|
3176
|
-
header.setAttribute('role', 'treeitem')
|
|
3177
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3178
|
-
section.appendChild(header)
|
|
3179
|
-
mountRow(harness, SESSION_A, section)
|
|
3180
|
-
harness.document.body.appendChild(section)
|
|
3181
|
-
|
|
3182
|
-
await enterMulti(harness)
|
|
3183
|
-
observerPass(harness)
|
|
3184
|
-
await flush()
|
|
3185
|
-
|
|
3186
|
-
const box = heading.querySelector('.dsdel-select-all-workspaces')
|
|
3187
|
-
assert.ok(box, 'the global box exists')
|
|
3188
|
-
const index = heading.children.indexOf(box)
|
|
3189
|
-
assert.equal(index < heading.children.indexOf(search), true, 'before the search slot')
|
|
3190
|
-
assert.equal(heading.children[index - 1].className, 'bhn1Oq_sectionLabel', 'and after the label')
|
|
3191
|
-
})
|
|
3192
|
-
|
|
3193
|
-
test('a box left at the wrong edge is moved on the next pass', async () => {
|
|
3194
|
-
const harness = await loadPlugin()
|
|
3195
|
-
const section = harness.document.createElement('div')
|
|
3196
|
-
section.setAttribute('role', 'group')
|
|
3197
|
-
|
|
3198
|
-
const header = harness.document.createElement('div')
|
|
3199
|
-
header.setAttribute('role', 'treeitem')
|
|
3200
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3201
|
-
|
|
3202
|
-
const label = harness.document.createElement('span')
|
|
3203
|
-
label.className = 'wnFoaW_projectText'
|
|
3204
|
-
header.appendChild(label)
|
|
3205
|
-
const actions = harness.document.createElement('span')
|
|
3206
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3207
|
-
header.appendChild(actions)
|
|
3208
|
-
|
|
3209
|
-
// An earlier build left its box AFTER the actions: the far edge.
|
|
3210
|
-
const stale = harness.document.createElement('button')
|
|
3211
|
-
stale.className = 'dsdel-select-all'
|
|
3212
|
-
header.appendChild(stale)
|
|
3213
|
-
|
|
3214
|
-
section.appendChild(header)
|
|
3215
|
-
mountRow(harness, SESSION_A, section)
|
|
3216
|
-
harness.document.body.appendChild(section)
|
|
3217
|
-
|
|
3218
|
-
await enterMulti(harness)
|
|
3219
|
-
observerPass(harness)
|
|
3220
|
-
await flush()
|
|
3221
|
-
|
|
3222
|
-
// The insert used to live inside the "created" branch, so an existing box was
|
|
3223
|
-
// never repositioned: the heading box moved and the workspace box stayed put.
|
|
3224
|
-
const index = header.children.indexOf(stale)
|
|
3225
|
-
assert.equal(index < header.children.indexOf(actions), true, 'moved before the actions')
|
|
3226
|
-
assert.equal(header.children[index - 1].className, 'wnFoaW_projectText', 'and beside the label')
|
|
3227
|
-
})
|
|
3228
|
-
|
|
3229
|
-
test('the workspace name stops absorbing the row while the mode runs', async () => {
|
|
3230
|
-
const harness = await loadPlugin()
|
|
3231
|
-
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3232
|
-
|
|
3233
|
-
// `.projectText` carries `flex:1`, so it fills whatever the actions do not take.
|
|
3234
|
-
// A box inserted after it therefore lands at the row's far edge even though it
|
|
3235
|
-
// is early in the child list — that is why the workspace box stayed right while
|
|
3236
|
-
// the header box (whose label is not flexed) moved. The rule only applies while
|
|
3237
|
-
// the mode runs, so the host keeps its normal layout otherwise.
|
|
3238
|
-
assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*flex:0 1 auto/,
|
|
3239
|
-
'the name sizes to its text during the mode')
|
|
3240
|
-
assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*min-width:0/,
|
|
3241
|
-
'and can still truncate a long name')
|
|
3242
|
-
})
|
|
3243
|
-
|
|
3244
|
-
test('a spacer keeps the right-hand cluster in place', async () => {
|
|
3245
|
-
const harness = await loadPlugin()
|
|
3246
|
-
const section = harness.document.createElement('div')
|
|
3247
|
-
section.setAttribute('role', 'group')
|
|
3248
|
-
|
|
3249
|
-
const header = harness.document.createElement('div')
|
|
3250
|
-
header.setAttribute('role', 'treeitem')
|
|
3251
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3252
|
-
|
|
3253
|
-
const label = harness.document.createElement('span')
|
|
3254
|
-
label.className = 'wnFoaW_projectText'
|
|
3255
|
-
header.appendChild(label)
|
|
3256
|
-
// The cluster that must NOT move: count, menu, new-session.
|
|
3257
|
-
const actions = harness.document.createElement('span')
|
|
3258
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3259
|
-
header.appendChild(actions)
|
|
3260
|
-
|
|
3261
|
-
section.appendChild(header)
|
|
3262
|
-
mountRow(harness, SESSION_A, section)
|
|
3263
|
-
harness.document.body.appendChild(section)
|
|
3264
|
-
|
|
3265
|
-
await enterMulti(harness)
|
|
3266
|
-
observerPass(harness)
|
|
3267
|
-
await flush()
|
|
3268
|
-
|
|
3269
|
-
// Order has to be: label, box, spacer, actions. With the spacer growing, the
|
|
3270
|
-
// name keeps its natural width and the cluster stays at the row's end; without
|
|
3271
|
-
// it, every flex child simply packs left and the count/menu/new buttons slid
|
|
3272
|
-
// over with the box.
|
|
3273
|
-
const kids = header.children
|
|
3274
|
-
const box = header.querySelector('.dsdel-select-all')
|
|
3275
|
-
const spacer = header.querySelector('.dsdel-flex-spacer')
|
|
3276
|
-
assert.ok(box, 'the box exists')
|
|
3277
|
-
assert.ok(spacer, 'the spacer exists')
|
|
3278
|
-
|
|
3279
|
-
assert.equal(kids.indexOf(box) < kids.indexOf(spacer), true, 'box before spacer')
|
|
3280
|
-
assert.equal(kids.indexOf(spacer) < kids.indexOf(actions), true, 'spacer before the cluster')
|
|
3281
|
-
assert.equal(kids.indexOf(label) < kids.indexOf(box), true, 'label first')
|
|
3282
|
-
})
|
|
3283
|
-
|
|
3284
|
-
test('the spacer is removed with the mode', async () => {
|
|
3285
|
-
const harness = await loadPlugin()
|
|
3286
|
-
const section = harness.document.createElement('div')
|
|
3287
|
-
section.setAttribute('role', 'group')
|
|
3288
|
-
const header = harness.document.createElement('div')
|
|
3289
|
-
header.setAttribute('role', 'treeitem')
|
|
3290
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3291
|
-
const label = harness.document.createElement('span')
|
|
3292
|
-
label.className = 'wnFoaW_projectText'
|
|
3293
|
-
header.appendChild(label)
|
|
3294
|
-
const actions = harness.document.createElement('span')
|
|
3295
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3296
|
-
header.appendChild(actions)
|
|
3297
|
-
section.appendChild(header)
|
|
3298
|
-
mountRow(harness, SESSION_A, section)
|
|
3299
|
-
harness.document.body.appendChild(section)
|
|
3300
|
-
|
|
3301
|
-
await enterMulti(harness)
|
|
3302
|
-
observerPass(harness)
|
|
3303
|
-
await flush()
|
|
3304
|
-
assert.ok(header.querySelector('.dsdel-flex-spacer'), 'spacer present during the mode')
|
|
3305
|
-
|
|
3306
|
-
// The bar's Cancel is the mode's own exit route. Escape would also reach
|
|
3307
|
-
// handlers left behind by earlier tests: the stub never unregisters one.
|
|
3308
|
-
clickBar(barCancel(harness))
|
|
3309
|
-
observerPass(harness)
|
|
3310
|
-
await flush()
|
|
3311
|
-
assert.equal(header.querySelector('.dsdel-flex-spacer'), null, 'gone with the mode')
|
|
3312
|
-
assert.equal(header.querySelector('.dsdel-select-all'), null, 'and so is the box')
|
|
3313
|
-
})
|
|
3314
|
-
|
|
3315
|
-
test('PROBE exit removes spacer', async () => {
|
|
3316
|
-
const harness = await loadPlugin()
|
|
3317
|
-
const section = harness.document.createElement('div')
|
|
3318
|
-
section.setAttribute('role', 'group')
|
|
3319
|
-
const header = harness.document.createElement('div')
|
|
3320
|
-
header.setAttribute('role', 'treeitem')
|
|
3321
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3322
|
-
const actions = harness.document.createElement('span')
|
|
3323
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3324
|
-
header.appendChild(actions)
|
|
3325
|
-
section.appendChild(header)
|
|
3326
|
-
mountRow(harness, SESSION_A, section)
|
|
3327
|
-
harness.document.body.appendChild(section)
|
|
3328
|
-
|
|
3596
|
+
test('multi-select delete carries the artifact switch to every request', async () => {
|
|
3597
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
3598
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
3599
|
+
localStorage.setItem(AUTO_KEY, '1')
|
|
3600
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
3601
|
+
const first = mountRow(harness, SESSION_A)
|
|
3602
|
+
const second = mountRow(harness, SESSION_B)
|
|
3329
3603
|
await enterMulti(harness)
|
|
3330
|
-
|
|
3604
|
+
clickRowIn(harness, first)
|
|
3605
|
+
clickRowIn(harness, second)
|
|
3331
3606
|
await flush()
|
|
3332
3607
|
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3608
|
+
clickBar(barDelete(harness))
|
|
3609
|
+
// The batch runs several workers and settles asynchronously; waiting only one
|
|
3610
|
+
// tick left them running into the NEXT test, whose harness swapped the document
|
|
3611
|
+
// out from under them. Drain until the bar is gone.
|
|
3612
|
+
await settle()
|
|
3613
|
+
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3614
|
+
|
|
3615
|
+
// The single-delete path sends `quarantine`; batch used to call postDelete(id)
|
|
3616
|
+
// with nothing, so "quarantine the produced files" was silently skipped while
|
|
3617
|
+
// that same switch stayed on. Every request here has to carry it.
|
|
3618
|
+
const bodies = harness.requests
|
|
3619
|
+
.filter((call) => call.url === '/dsh-delete-session/delete')
|
|
3620
|
+
.map((call) => JSON.parse(call.init.body))
|
|
3621
|
+
assert.equal(bodies.length, 2, 'one request per selected session')
|
|
3622
|
+
for (const body of bodies) {
|
|
3623
|
+
assert.deepEqual(body.quarantine, { scope: 'created' }, 'the produced files follow the switch')
|
|
3337
3624
|
}
|
|
3338
|
-
const cancel = barCancel(harness)
|
|
3339
|
-
console.log('PROBE cancel 节点:', cancel && cancel.props && cancel.props.className)
|
|
3340
|
-
clickBar(cancel)
|
|
3341
|
-
await flush()
|
|
3342
|
-
console.log('PROBE 退出后 spacer 数:', harness.document.querySelectorAll('.dsdel-flex-spacer').length)
|
|
3343
|
-
assert.ok(true)
|
|
3344
|
-
})
|
|
3345
|
-
|
|
3346
|
-
test('the spacer is the growing child, so the cluster keeps its seat', async () => {
|
|
3347
|
-
const harness = await loadPlugin()
|
|
3348
|
-
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
3349
|
-
|
|
3350
|
-
// Without a growing child the flex row simply packs left, which drags the count
|
|
3351
|
-
// and the action buttons along with the box. The spacer is what holds them at
|
|
3352
|
-
// the row's end while the box sits beside the name.
|
|
3353
|
-
assert.match(css, /\.dsdel-flex-spacer\{[^}]*flex:1/, 'the spacer grows')
|
|
3354
|
-
assert.match(css, /\.dsdel-flex-spacer\{[^}]*min-width:0/, 'and can collapse when space is tight')
|
|
3355
|
-
assert.match(css, /\.dsdel-select-all[^}]*flex:0 0 auto/, 'the box itself does not grow')
|
|
3356
|
-
})
|
|
3357
|
-
|
|
3358
|
-
test('a document click on a plugin-drawn element leaves the session alone', async () => {
|
|
3359
|
-
const harness = await loadPlugin()
|
|
3360
|
-
const row = mountRow(harness, SESSION_A)
|
|
3361
|
-
await enterMulti(harness)
|
|
3362
|
-
observerPass(harness)
|
|
3363
|
-
await flush()
|
|
3364
|
-
assert.equal(harness.document.body.className.includes('dsdel-selecting'), true)
|
|
3365
|
-
|
|
3366
|
-
// The document capture listener runs before any element handler. It must ignore
|
|
3367
|
-
// elements this plugin drew — a box inside a workspace row is the everyday case,
|
|
3368
|
-
// and inside a session row it would otherwise toggle that session.
|
|
3369
|
-
const box = harness.document.createElement('button')
|
|
3370
|
-
box.className = 'dsdel-select-all'
|
|
3371
|
-
box.setAttribute('data-dsh-delete-session', 'select-all')
|
|
3372
|
-
row.appendChild(box)
|
|
3373
|
-
|
|
3374
|
-
clickRowIn(harness, box)
|
|
3375
|
-
observerPass(harness)
|
|
3376
|
-
await flush()
|
|
3377
|
-
|
|
3378
|
-
const check = row.querySelector('.dsdel-check')
|
|
3379
|
-
assert.equal(check.classList.contains('dsdel-check-on'), false, 'no session was toggled')
|
|
3380
3625
|
})
|
|
3381
3626
|
|
|
3382
|
-
test('
|
|
3627
|
+
test('multi-select delete leaves the files alone when the switch is off', async () => {
|
|
3383
3628
|
const harness = await loadPlugin()
|
|
3384
|
-
const
|
|
3629
|
+
const first = mountRow(harness, SESSION_A)
|
|
3385
3630
|
await enterMulti(harness)
|
|
3386
|
-
|
|
3631
|
+
clickRowIn(harness, first)
|
|
3387
3632
|
await flush()
|
|
3388
3633
|
|
|
3389
|
-
|
|
3390
|
-
await
|
|
3634
|
+
clickBar(barDelete(harness))
|
|
3635
|
+
await settle()
|
|
3636
|
+
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3391
3637
|
|
|
3392
|
-
const
|
|
3393
|
-
|
|
3638
|
+
const bodies = harness.requests
|
|
3639
|
+
.filter((call) => call.url === '/dsh-delete-session/delete')
|
|
3640
|
+
.map((call) => JSON.parse(call.init.body))
|
|
3641
|
+
assert.equal(bodies.length, 1, 'the delete went out')
|
|
3642
|
+
assert.equal('quarantine' in bodies[0], false, 'and does not move any file')
|
|
3394
3643
|
})
|
|
3395
3644
|
|
|
3396
|
-
test('a
|
|
3645
|
+
test('a batch in asking mode says the files were left alone', async () => {
|
|
3397
3646
|
const harness = await loadPlugin()
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
const
|
|
3401
|
-
header.setAttribute('role', 'treeitem')
|
|
3402
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3403
|
-
const label = harness.document.createElement('span')
|
|
3404
|
-
label.className = 'wnFoaW_projectText'
|
|
3405
|
-
header.appendChild(label)
|
|
3406
|
-
const actions = harness.document.createElement('span')
|
|
3407
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3408
|
-
header.appendChild(actions)
|
|
3409
|
-
section.appendChild(header)
|
|
3410
|
-
mountRow(harness, SESSION_A, section)
|
|
3411
|
-
harness.document.body.appendChild(section)
|
|
3412
|
-
|
|
3647
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
3648
|
+
localStorage.setItem(AUTO_KEY, '0')
|
|
3649
|
+
const first = mountRow(harness, SESSION_A)
|
|
3413
3650
|
await enterMulti(harness)
|
|
3414
|
-
|
|
3415
|
-
await flush()
|
|
3416
|
-
|
|
3417
|
-
// Every insertBefore is a mutation, and the list observer counted it as a
|
|
3418
|
-
// reason to scan again: each pass scheduled the next one, forever, and the box
|
|
3419
|
-
// was detached and re-attached under the pointer. Nothing may move here — the
|
|
3420
|
-
// box and its spacer are already in the right place.
|
|
3421
|
-
const box = header.querySelector('.dsdel-select-all')
|
|
3422
|
-
const spacer = header.querySelector('.dsdel-flex-spacer')
|
|
3423
|
-
const index = header.children.indexOf(box)
|
|
3424
|
-
|
|
3425
|
-
// Re-inserting a node where it already sits leaves its index unchanged, so the
|
|
3426
|
-
// index alone cannot prove the pass was quiet. Count the calls instead: a real
|
|
3427
|
-
// insertBefore produces a MutationRecord, and the observer used to feed on them.
|
|
3428
|
-
const realInsert = header.insertBefore.bind(header)
|
|
3429
|
-
let inserts = 0
|
|
3430
|
-
header.insertBefore = (child, ref) => { inserts += 1; return realInsert(child, ref) }
|
|
3431
|
-
|
|
3432
|
-
observerPass(harness)
|
|
3433
|
-
observerPass(harness)
|
|
3651
|
+
clickRowIn(harness, first)
|
|
3434
3652
|
await flush()
|
|
3435
3653
|
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
assert.equal(header.children.indexOf(spacer), index + 1, 'nor did the spacer')
|
|
3440
|
-
assert.equal(header.children.filter((el) => el === box).length, 1, 'and there is only one')
|
|
3441
|
-
})
|
|
3442
|
-
|
|
3443
|
-
test('a mutation naming only our own nodes schedules no pass', async () => {
|
|
3444
|
-
const harness = await loadPlugin()
|
|
3445
|
-
|
|
3446
|
-
// Drive the frame queue by hand: a timer-based flush made this test flaky,
|
|
3447
|
-
// because a pass can queue another callback while it runs.
|
|
3448
|
-
//
|
|
3449
|
-
// Note the drain: emptying the queue without running its callbacks leaves the
|
|
3450
|
-
// plugin's `decorateRaf` handle truthy, and every later `scheduleDecorate`
|
|
3451
|
-
// silently returns. That is a harness trap, not a product bug.
|
|
3452
|
-
const queued = []
|
|
3453
|
-
const realRaf = globalThis.requestAnimationFrame
|
|
3454
|
-
const realCancel = globalThis.cancelAnimationFrame
|
|
3455
|
-
globalThis.requestAnimationFrame = (fn) => { queued.push(fn); return queued.length }
|
|
3456
|
-
globalThis.cancelAnimationFrame = () => {}
|
|
3457
|
-
const drain = () => { let guard = 0; while (queued.length > 0 && guard < 50) { guard += 1; queued.shift()() } }
|
|
3458
|
-
|
|
3459
|
-
try {
|
|
3460
|
-
await enterMulti(harness)
|
|
3461
|
-
drain()
|
|
3462
|
-
|
|
3463
|
-
// A row that arrives after the last pass carries no checkbox, so whether a
|
|
3464
|
-
// pass runs is readable straight off the DOM.
|
|
3465
|
-
const section = harness.document.createElement('div')
|
|
3466
|
-
section.setAttribute('role', 'group')
|
|
3467
|
-
const hostRow = harness.document.createElement('div')
|
|
3468
|
-
hostRow.setAttribute('role', 'treeitem')
|
|
3469
|
-
hostRow.setAttribute('data-row-key', 'session:session-cccc1111-2222-4333-8444-555555555555')
|
|
3470
|
-
section.appendChild(hostRow)
|
|
3471
|
-
harness.document.body.appendChild(section)
|
|
3472
|
-
assert.equal(hostRow.querySelector('.dsdel-check'), null, 'the row is undecorated')
|
|
3473
|
-
|
|
3474
|
-
// Decorate inserts checkboxes, and the list observer reports them right back.
|
|
3475
|
-
// Every such record used to schedule another pass, so the loop never settled:
|
|
3476
|
-
// the box was re-inserted under the pointer and a click often missed.
|
|
3477
|
-
const own = harness.document.createElement('span')
|
|
3478
|
-
own.setAttribute('data-dsh-delete-session', 'check')
|
|
3479
|
-
harness.observers[0].callback([{ addedNodes: [own], removedNodes: [] }])
|
|
3480
|
-
assert.equal(queued.length, 0, 'our own node schedules nothing')
|
|
3481
|
-
|
|
3482
|
-
// A host change must still get through.
|
|
3483
|
-
harness.observers[0].callback([{ addedNodes: [hostRow], removedNodes: [] }])
|
|
3484
|
-
assert.equal(queued.length, 1, 'a real host row schedules one pass')
|
|
3485
|
-
drain()
|
|
3486
|
-
assert.ok(hostRow.querySelector('.dsdel-check'), 'and that pass decorates it')
|
|
3487
|
-
} finally {
|
|
3488
|
-
globalThis.requestAnimationFrame = realRaf
|
|
3489
|
-
globalThis.cancelAnimationFrame = realCancel
|
|
3490
|
-
}
|
|
3491
|
-
})
|
|
3492
|
-
|
|
3493
|
-
test('the plugin never calls array methods on a live child list', async () => {
|
|
3494
|
-
const source = await readFile(new URL('../src/client.js', import.meta.url), 'utf8')
|
|
3495
|
-
|
|
3496
|
-
// In a browser `element.children` is an HTMLCollection: it has `length` and
|
|
3497
|
-
// indexing, and none of the Array methods. The test stub uses a plain array, so
|
|
3498
|
-
// `children.indexOf(...)` passed here and threw a TypeError in the real host —
|
|
3499
|
-
// the decorate pass died before inserting anything, and the select-all box never
|
|
3500
|
-
// appeared. Index it by hand (`childIndex`) or spread it first.
|
|
3501
|
-
const offenders = []
|
|
3502
|
-
for (const match of source.matchAll(/\.children\.([A-Za-z]+)\s*\(/g)) {
|
|
3503
|
-
offenders.push(match[0])
|
|
3504
|
-
}
|
|
3505
|
-
assert.deepEqual(offenders, [], 'no Array methods on `children`')
|
|
3506
|
-
})
|
|
3507
|
-
|
|
3508
|
-
test('the workspace box reaches past a wrapping element', async () => {
|
|
3509
|
-
const harness = await loadPlugin()
|
|
3510
|
-
const section = harness.document.createElement('div')
|
|
3511
|
-
section.setAttribute('role', 'group')
|
|
3512
|
-
|
|
3513
|
-
// The real host wraps the workspace row in HoverCard's <span>, so the row's
|
|
3514
|
-
// parentElement is that span, not the section. A subtree query from the span
|
|
3515
|
-
// returns only the workspace row itself and the box ends up with no ids —
|
|
3516
|
-
// `toggleGroup` then returns without doing anything, which is exactly the
|
|
3517
|
-
// "single-workspace select-all does nothing" report.
|
|
3518
|
-
const wrapper = harness.document.createElement('span')
|
|
3519
|
-
wrapper.className = 'HoverCard_root'
|
|
3520
|
-
const header = harness.document.createElement('div')
|
|
3521
|
-
header.setAttribute('role', 'treeitem')
|
|
3522
|
-
header.setAttribute('data-row-key', 'workspace:ws-a')
|
|
3523
|
-
const label = harness.document.createElement('span')
|
|
3524
|
-
label.className = 'wnFoaW_projectText'
|
|
3525
|
-
header.appendChild(label)
|
|
3526
|
-
const actions = harness.document.createElement('span')
|
|
3527
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3528
|
-
header.appendChild(actions)
|
|
3529
|
-
wrapper.appendChild(header)
|
|
3530
|
-
section.appendChild(wrapper)
|
|
3531
|
-
|
|
3532
|
-
mountRow(harness, SESSION_A, section)
|
|
3533
|
-
mountRow(harness, SESSION_B, section)
|
|
3534
|
-
harness.document.body.appendChild(section)
|
|
3535
|
-
|
|
3536
|
-
await enterMulti(harness)
|
|
3537
|
-
observerPass(harness)
|
|
3538
|
-
await flush()
|
|
3539
|
-
|
|
3540
|
-
const box = header.querySelector('.dsdel-select-all')
|
|
3541
|
-
assert.ok(box, 'the box exists')
|
|
3542
|
-
assert.deepEqual(box.__dsdelIds, [SESSION_A.id, SESSION_B.id], 'both sessions were found')
|
|
3543
|
-
|
|
3544
|
-
box.fire('click')
|
|
3545
|
-
await flush()
|
|
3546
|
-
assert.equal(box.getAttribute('aria-checked'), 'true', 'and pressing it selects them')
|
|
3547
|
-
})
|
|
3548
|
-
|
|
3549
|
-
test('a workspace box never reaches into a nested workspace', async () => {
|
|
3550
|
-
const harness = await loadPlugin()
|
|
3551
|
-
const section = harness.document.createElement('div')
|
|
3552
|
-
section.setAttribute('role', 'group')
|
|
3553
|
-
|
|
3554
|
-
const header = harness.document.createElement('div')
|
|
3555
|
-
header.setAttribute('role', 'treeitem')
|
|
3556
|
-
header.setAttribute('data-row-key', 'workspace:outer')
|
|
3557
|
-
const actions = harness.document.createElement('span')
|
|
3558
|
-
actions.className = 'wnFoaW_rowActions'
|
|
3559
|
-
header.appendChild(actions)
|
|
3560
|
-
section.appendChild(header)
|
|
3561
|
-
mountRow(harness, SESSION_A, section)
|
|
3562
|
-
|
|
3563
|
-
// A nested workspace is a `div[role="group"]` holding its own rows.
|
|
3564
|
-
const nested = harness.document.createElement('div')
|
|
3565
|
-
nested.setAttribute('role', 'group')
|
|
3566
|
-
const nestedHeader = harness.document.createElement('div')
|
|
3567
|
-
nestedHeader.setAttribute('role', 'treeitem')
|
|
3568
|
-
nestedHeader.setAttribute('data-row-key', 'workspace:inner')
|
|
3569
|
-
nested.appendChild(nestedHeader)
|
|
3570
|
-
mountRow(harness, SESSION_B, nested)
|
|
3571
|
-
section.appendChild(nested)
|
|
3572
|
-
|
|
3573
|
-
harness.document.body.appendChild(section)
|
|
3574
|
-
|
|
3575
|
-
await enterMulti(harness)
|
|
3576
|
-
observerPass(harness)
|
|
3577
|
-
await flush()
|
|
3654
|
+
clickBar(barDelete(harness))
|
|
3655
|
+
await settle()
|
|
3656
|
+
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3578
3657
|
|
|
3579
|
-
|
|
3580
|
-
|
|
3658
|
+
// Asking means a per-file checklist, which a batch has nowhere to show. Silence
|
|
3659
|
+
// would look like the files had been handled.
|
|
3660
|
+
const said = toasts(harness).join(' | ')
|
|
3661
|
+
assert.equal(said.includes('产出文件没有处理'), true, 'the user is told: ' + said)
|
|
3662
|
+
assert.equal('quarantine' in deleteBody(harness), false, 'and nothing was moved')
|
|
3581
3663
|
})
|