dsh-progress-union 0.6.3 → 0.7.0-rc.2
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/CHANGELOG.md +401 -373
- package/LICENSE +21 -21
- package/README.md +286 -286
- package/anchor.js +39 -39
- package/client.js +3078 -2993
- package/cordis.patch.yml +4 -4
- package/docs/slot-models-comparison.md +23 -23
- package/docs/slot-trail-fanout.md +31 -31
- package/docs/spirit-reference.md +38 -38
- package/dsh.plugin.json +1 -1
- package/icon.svg +7 -7
- package/index.js +5206 -4568
- package/package.json +93 -79
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +274 -190
- package/test/download-classify.test.mjs +199 -0
- package/test/e2e.test.mjs +77 -77
- package/test/goal-drive.test.mjs +17 -17
- package/test/harness.mjs +249 -249
- package/test/host.test.mjs +251 -251
- package/test/observer.test.mjs +170 -170
- package/test/parse-progress.test.mjs +78 -0
- package/test/settings.test.mjs +81 -81
- package/test/star-panel.test.mjs +181 -181
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
- package/test/tool-gloss.test.mjs +137 -0
package/test/star-panel.test.mjs
CHANGED
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
// star 面板内联实现的行为契约测试(v1→v2→v3 阶梯,_tools/star-row 计划)。
|
|
2
|
-
// 无 jsdom:手写最小 DOM,从 client.js 抽出 __STAR_INLINE 块直接执行,按当前 STAR_GEN 断言。
|
|
3
|
-
import { test } from 'node:test'
|
|
4
|
-
import assert from 'node:assert/strict'
|
|
5
|
-
import { readFileSync } from 'node:fs'
|
|
6
|
-
import { join, dirname } from 'node:path'
|
|
7
|
-
import { fileURLToPath } from 'node:url'
|
|
8
|
-
|
|
9
|
-
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
10
|
-
const src = readFileSync(join(ROOT, 'client.js'), 'utf8')
|
|
11
|
-
const begin = src.indexOf('/* __STAR_INLINE_BEGIN__')
|
|
12
|
-
const endMark = src.indexOf('/* __STAR_INLINE_END__')
|
|
13
|
-
assert.ok(begin >= 0 && endMark > begin, 'client.js 应含内联 star 面板块')
|
|
14
|
-
const end = src.indexOf('*/', endMark) + 2 // 含收尾注释,避免残留未闭合 /*
|
|
15
|
-
const block = src.slice(begin, end)
|
|
16
|
-
const GEN = (block.match(/var STAR_GEN = "([^"]*)";/) || [])[1]
|
|
17
|
-
const NS = (block.match(/var STAR_NS = "([^"]*)";/) || [])[1]
|
|
18
|
-
assert.ok(['v1', 'v2', 'v3', 'v4'].includes(GEN), 'STAR_GEN 合法: ' + GEN)
|
|
19
|
-
assert.equal(NS, 'progress-union', 'STAR_NS 固定为 im-union')
|
|
20
|
-
|
|
21
|
-
// ── 最小 DOM ──
|
|
22
|
-
class El {
|
|
23
|
-
constructor(tag) {
|
|
24
|
-
this.tagName = tag; this.children = []; this.parentNode = null
|
|
25
|
-
this.className = ''; this.textContent = ''; this.attrs = {}; this.dataset = {}
|
|
26
|
-
this._listeners = {}; this.style = {}; this.type = ''; this.title = ''
|
|
27
|
-
}
|
|
28
|
-
get firstChild() { return this.children[0] || null }
|
|
29
|
-
appendChild(c) { c.parentNode = this; this.children.push(c); return c }
|
|
30
|
-
removeChild(c) { this.children = this.children.filter((x) => x !== c); c.parentNode = null; return c }
|
|
31
|
-
replaceChild(nu, old) {
|
|
32
|
-
const i = this.children.indexOf(old); if (i < 0) throw new Error('replaceChild: 非子节点')
|
|
33
|
-
old.parentNode = null; nu.parentNode = this; this.children[i] = nu; return old
|
|
34
|
-
}
|
|
35
|
-
setAttribute(k, v) { this.attrs[k] = v }
|
|
36
|
-
getAttribute(k) { return this.attrs[k] }
|
|
37
|
-
addEventListener(ev, fn) { (this._listeners[ev] = this._listeners[ev] || []).push(fn) }
|
|
38
|
-
dispatch(ev) { for (const fn of this._listeners[ev] || []) fn({ preventDefault() {}, stopPropagation() {} }) }
|
|
39
|
-
set href(v) { this.attrs.href = v } get href() { return this.attrs.href }
|
|
40
|
-
set target(v) { this.attrs.target = v } get target() { return this.attrs.target }
|
|
41
|
-
set rel(v) { this.attrs.rel = v } get rel() { return this.attrs.rel }
|
|
42
|
-
// 锚点点击 = 打开仓库页(测试里只记一笔,真正跳转由浏览器负责)
|
|
43
|
-
click() { this.dispatch('click'); this._clicked = true }
|
|
44
|
-
}
|
|
45
|
-
function makeEnv(lang) {
|
|
46
|
-
const store = {}
|
|
47
|
-
const head = new El('head'); const documentElement = { lang: lang || 'zh' }
|
|
48
|
-
const ids = {}
|
|
49
|
-
const document = {
|
|
50
|
-
documentElement,
|
|
51
|
-
head: { appendChild(c) { if (c.attrs && c.attrs.id) ids[c.attrs.id] = c; head.children.push(c) } },
|
|
52
|
-
createElement(t) { return new El(t) },
|
|
53
|
-
createElementNS(_ns, t) { return new El(t) },
|
|
54
|
-
getElementById(id) { return ids[id] || null },
|
|
55
|
-
}
|
|
56
|
-
const localStorage = {
|
|
57
|
-
getItem(k) { return Object.prototype.hasOwnProperty.call(store, k) ? store[k] : null },
|
|
58
|
-
setItem(k, v) { store[k] = String(v) },
|
|
59
|
-
removeItem(k) { delete store[k] },
|
|
60
|
-
_store: store,
|
|
61
|
-
}
|
|
62
|
-
return { window: {}, document, localStorage }
|
|
63
|
-
}
|
|
64
|
-
function runPanel(lang, seedStore) {
|
|
65
|
-
const env = makeEnv(lang)
|
|
66
|
-
if (seedStore) Object.assign(env.localStorage._store, seedStore)
|
|
67
|
-
const fn = new Function('window', 'document', 'localStorage', block + '\nreturn window.__StarPanel;')
|
|
68
|
-
const panel = fn(env.window, env.document, env.localStorage)
|
|
69
|
-
return { panel, env, mount: panel.mount(env.document) }
|
|
70
|
-
}
|
|
71
|
-
function find(el, pred, out = []) {
|
|
72
|
-
for (const c of el.children || []) { if (pred(c)) out.push(c); find(c, pred, out) }
|
|
73
|
-
return out
|
|
74
|
-
}
|
|
75
|
-
const K1 = 'dsh.star.progress-union.dismissed'
|
|
76
|
-
const K2 = 'dsh.star.progress-union.v2.dismissed'
|
|
77
|
-
const K3 = 'dsh.star.progress-union.v3.supported'
|
|
78
|
-
const K4 = 'dsh.star.progress-union.v4.supported'
|
|
79
|
-
|
|
80
|
-
test('star 面板:渲染出 GitHub 仓库链接(各代通用)', () => {
|
|
81
|
-
const { mount } = runPanel('zh')
|
|
82
|
-
const links = find(mount, (e) => e.tagName === 'a' && /github\.com/.test(e.href || ''))
|
|
83
|
-
assert.ok(links.length >= 1, '至少一个仓库链接')
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test('star 面板:10 语文案随 documentElement.lang 自选', () => {
|
|
87
|
-
const zh = find(runPanel('zh').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
88
|
-
const en = find(runPanel('en').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
89
|
-
const t = (arr) => arr.map((e) => e.textContent).join('|')
|
|
90
|
-
assert.notEqual(t(zh), t(en), 'zh 与 en 文案不同')
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
if (GEN === 'v1') {
|
|
94
|
-
test('v1:★ CTA 只跳转不写键;× 才写 dismissed 并收起话术', () => {
|
|
95
|
-
const { mount, env } = runPanel('zh')
|
|
96
|
-
assert.equal(mount.className, 'dsh-star-row-s', 'v1 S 档行')
|
|
97
|
-
const cta = find(mount, (e) => e.className === 'dsh-star-cta')[0]
|
|
98
|
-
const hide = find(mount, (e) => e.className === 'dsh-star-hide')[0]
|
|
99
|
-
assert.ok(cta && hide, 'v1 应有 ★ 与 × 两个按钮')
|
|
100
|
-
cta.click()
|
|
101
|
-
assert.equal(env.localStorage.getItem(K1), null, '点 ★ 不写 dismissed')
|
|
102
|
-
hide.dispatch('click')
|
|
103
|
-
assert.equal(env.localStorage.getItem(K1), '1', '点 × 写 dismissed')
|
|
104
|
-
assert.ok(mount.parentNode === null || mount.className !== 'dsh-star-row-s', '× 后行被替换')
|
|
105
|
-
})
|
|
106
|
-
test('v1:已 dismissed → 只留中性链接行,无按钮', () => {
|
|
107
|
-
const { mount } = runPanel('zh', { [K1]: '1' })
|
|
108
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-cta').length, 0, 'dismissed 后无 ★')
|
|
109
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-hide').length, 0, 'dismissed 后无 ×')
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (GEN === 'v2') {
|
|
114
|
-
test('v2:纯链接一行页脚,无按钮;点 ⭐ 或 💬 即写 v2.dismissed 收敛', () => {
|
|
115
|
-
const { mount, env } = runPanel('zh')
|
|
116
|
-
assert.equal(mount.className, 'dsh-star-foot', 'v2 页脚行')
|
|
117
|
-
assert.equal(find(mount, (e) => e.tagName === 'button').length, 0, 'v2 无按钮')
|
|
118
|
-
const stars = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))
|
|
119
|
-
assert.ok(stars.length === 1, 'v2 一个 ⭐ 链接')
|
|
120
|
-
stars[0].click()
|
|
121
|
-
assert.equal(env.localStorage.getItem(K2), '1', '点 ⭐ 写 v2.dismissed')
|
|
122
|
-
})
|
|
123
|
-
test('v2:加载即清 v1 键、不迁值', () => {
|
|
124
|
-
const { env } = runPanel('zh', { [K1]: '1' })
|
|
125
|
-
assert.equal(env.localStorage.getItem(K1), null, 'v1 键被清掉')
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (GEN === 'v3') {
|
|
130
|
-
test('v3:两行页脚;⭐/💬 只跳转不收敛,只有「我已支持」写 v3.supported', () => {
|
|
131
|
-
const { mount, env } = runPanel('zh')
|
|
132
|
-
assert.equal(mount.className, 'dsh-star-foot', 'v3 页脚')
|
|
133
|
-
const btns = find(mount, (e) => e.className === 'dsh-star-support')
|
|
134
|
-
assert.equal(btns.length, 1, 'v3 一个「我已支持」按钮')
|
|
135
|
-
const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
|
|
136
|
-
star.click()
|
|
137
|
-
assert.equal(env.localStorage.getItem(K3), null, '点 ⭐ 不写 supported')
|
|
138
|
-
btns[0].dispatch('click')
|
|
139
|
-
assert.equal(env.localStorage.getItem(K3), '1', '按「我已支持」写 supported')
|
|
140
|
-
})
|
|
141
|
-
test('v3:加载即清 v1/v2 旧键、不迁值', () => {
|
|
142
|
-
const { env } = runPanel('zh', { [K1]: '1', [K2]: '1' })
|
|
143
|
-
assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
|
|
144
|
-
assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
|
|
145
|
-
})
|
|
146
|
-
test('v3:已 supported → 收敛态(仓库地址 + 💬 issue),无「我已支持」按钮', () => {
|
|
147
|
-
const { mount } = runPanel('zh', { [K3]: '1' })
|
|
148
|
-
assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v3 收敛态')
|
|
149
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-support').length, 0, '收敛后无按钮')
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (GEN === 'v4') {
|
|
154
|
-
test('v4:三动作统一描边胶囊 dsh-star-btn;⭐/💬 只跳转不收敛,只有「我已支持」写 v4.supported', () => {
|
|
155
|
-
const { mount, env } = runPanel('zh')
|
|
156
|
-
assert.equal(mount.className, 'dsh-star-foot', 'v4 页脚')
|
|
157
|
-
const isBtn = (e) => (e.className || '').split(' ').includes('dsh-star-btn')
|
|
158
|
-
const caps = find(mount, isBtn)
|
|
159
|
-
assert.equal(caps.length, 3, 'v4 三个动作都是胶囊:⭐ / 我已支持 / 💬')
|
|
160
|
-
const sup = find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support')
|
|
161
|
-
assert.equal(sup.length, 1, 'v4 一个「我已支持」胶囊按钮')
|
|
162
|
-
const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
|
|
163
|
-
assert.ok(isBtn(star), '⭐ 是胶囊链接')
|
|
164
|
-
star.click()
|
|
165
|
-
assert.equal(env.localStorage.getItem(K4), null, '点 ⭐ 不写 supported')
|
|
166
|
-
sup[0].dispatch('click')
|
|
167
|
-
assert.equal(env.localStorage.getItem(K4), '1', '按「我已支持」写 v4.supported')
|
|
168
|
-
})
|
|
169
|
-
test('v4:加载即清 v3/v2/v1 三旧键、不迁值', () => {
|
|
170
|
-
const { env } = runPanel('zh', { [K1]: '1', [K2]: '1', [K3]: '1' })
|
|
171
|
-
assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
|
|
172
|
-
assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
|
|
173
|
-
assert.equal(env.localStorage.getItem(K3), null, 'v3 键清')
|
|
174
|
-
})
|
|
175
|
-
test('v4:已 supported → 收敛态(仓库地址 + 💬),无「我已支持」按钮', () => {
|
|
176
|
-
const { mount } = runPanel('zh', { [K4]: '1' })
|
|
177
|
-
assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v4 收敛态')
|
|
178
|
-
assert.equal(find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support').length, 0, '收敛后无按钮')
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
|
|
1
|
+
// star 面板内联实现的行为契约测试(v1→v2→v3 阶梯,_tools/star-row 计划)。
|
|
2
|
+
// 无 jsdom:手写最小 DOM,从 client.js 抽出 __STAR_INLINE 块直接执行,按当前 STAR_GEN 断言。
|
|
3
|
+
import { test } from 'node:test'
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import { readFileSync } from 'node:fs'
|
|
6
|
+
import { join, dirname } from 'node:path'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
10
|
+
const src = readFileSync(join(ROOT, 'client.js'), 'utf8')
|
|
11
|
+
const begin = src.indexOf('/* __STAR_INLINE_BEGIN__')
|
|
12
|
+
const endMark = src.indexOf('/* __STAR_INLINE_END__')
|
|
13
|
+
assert.ok(begin >= 0 && endMark > begin, 'client.js 应含内联 star 面板块')
|
|
14
|
+
const end = src.indexOf('*/', endMark) + 2 // 含收尾注释,避免残留未闭合 /*
|
|
15
|
+
const block = src.slice(begin, end)
|
|
16
|
+
const GEN = (block.match(/var STAR_GEN = "([^"]*)";/) || [])[1]
|
|
17
|
+
const NS = (block.match(/var STAR_NS = "([^"]*)";/) || [])[1]
|
|
18
|
+
assert.ok(['v1', 'v2', 'v3', 'v4'].includes(GEN), 'STAR_GEN 合法: ' + GEN)
|
|
19
|
+
assert.equal(NS, 'progress-union', 'STAR_NS 固定为 im-union')
|
|
20
|
+
|
|
21
|
+
// ── 最小 DOM ──
|
|
22
|
+
class El {
|
|
23
|
+
constructor(tag) {
|
|
24
|
+
this.tagName = tag; this.children = []; this.parentNode = null
|
|
25
|
+
this.className = ''; this.textContent = ''; this.attrs = {}; this.dataset = {}
|
|
26
|
+
this._listeners = {}; this.style = {}; this.type = ''; this.title = ''
|
|
27
|
+
}
|
|
28
|
+
get firstChild() { return this.children[0] || null }
|
|
29
|
+
appendChild(c) { c.parentNode = this; this.children.push(c); return c }
|
|
30
|
+
removeChild(c) { this.children = this.children.filter((x) => x !== c); c.parentNode = null; return c }
|
|
31
|
+
replaceChild(nu, old) {
|
|
32
|
+
const i = this.children.indexOf(old); if (i < 0) throw new Error('replaceChild: 非子节点')
|
|
33
|
+
old.parentNode = null; nu.parentNode = this; this.children[i] = nu; return old
|
|
34
|
+
}
|
|
35
|
+
setAttribute(k, v) { this.attrs[k] = v }
|
|
36
|
+
getAttribute(k) { return this.attrs[k] }
|
|
37
|
+
addEventListener(ev, fn) { (this._listeners[ev] = this._listeners[ev] || []).push(fn) }
|
|
38
|
+
dispatch(ev) { for (const fn of this._listeners[ev] || []) fn({ preventDefault() {}, stopPropagation() {} }) }
|
|
39
|
+
set href(v) { this.attrs.href = v } get href() { return this.attrs.href }
|
|
40
|
+
set target(v) { this.attrs.target = v } get target() { return this.attrs.target }
|
|
41
|
+
set rel(v) { this.attrs.rel = v } get rel() { return this.attrs.rel }
|
|
42
|
+
// 锚点点击 = 打开仓库页(测试里只记一笔,真正跳转由浏览器负责)
|
|
43
|
+
click() { this.dispatch('click'); this._clicked = true }
|
|
44
|
+
}
|
|
45
|
+
function makeEnv(lang) {
|
|
46
|
+
const store = {}
|
|
47
|
+
const head = new El('head'); const documentElement = { lang: lang || 'zh' }
|
|
48
|
+
const ids = {}
|
|
49
|
+
const document = {
|
|
50
|
+
documentElement,
|
|
51
|
+
head: { appendChild(c) { if (c.attrs && c.attrs.id) ids[c.attrs.id] = c; head.children.push(c) } },
|
|
52
|
+
createElement(t) { return new El(t) },
|
|
53
|
+
createElementNS(_ns, t) { return new El(t) },
|
|
54
|
+
getElementById(id) { return ids[id] || null },
|
|
55
|
+
}
|
|
56
|
+
const localStorage = {
|
|
57
|
+
getItem(k) { return Object.prototype.hasOwnProperty.call(store, k) ? store[k] : null },
|
|
58
|
+
setItem(k, v) { store[k] = String(v) },
|
|
59
|
+
removeItem(k) { delete store[k] },
|
|
60
|
+
_store: store,
|
|
61
|
+
}
|
|
62
|
+
return { window: {}, document, localStorage }
|
|
63
|
+
}
|
|
64
|
+
function runPanel(lang, seedStore) {
|
|
65
|
+
const env = makeEnv(lang)
|
|
66
|
+
if (seedStore) Object.assign(env.localStorage._store, seedStore)
|
|
67
|
+
const fn = new Function('window', 'document', 'localStorage', block + '\nreturn window.__StarPanel;')
|
|
68
|
+
const panel = fn(env.window, env.document, env.localStorage)
|
|
69
|
+
return { panel, env, mount: panel.mount(env.document) }
|
|
70
|
+
}
|
|
71
|
+
function find(el, pred, out = []) {
|
|
72
|
+
for (const c of el.children || []) { if (pred(c)) out.push(c); find(c, pred, out) }
|
|
73
|
+
return out
|
|
74
|
+
}
|
|
75
|
+
const K1 = 'dsh.star.progress-union.dismissed'
|
|
76
|
+
const K2 = 'dsh.star.progress-union.v2.dismissed'
|
|
77
|
+
const K3 = 'dsh.star.progress-union.v3.supported'
|
|
78
|
+
const K4 = 'dsh.star.progress-union.v4.supported'
|
|
79
|
+
|
|
80
|
+
test('star 面板:渲染出 GitHub 仓库链接(各代通用)', () => {
|
|
81
|
+
const { mount } = runPanel('zh')
|
|
82
|
+
const links = find(mount, (e) => e.tagName === 'a' && /github\.com/.test(e.href || ''))
|
|
83
|
+
assert.ok(links.length >= 1, '至少一个仓库链接')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('star 面板:10 语文案随 documentElement.lang 自选', () => {
|
|
87
|
+
const zh = find(runPanel('zh').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
88
|
+
const en = find(runPanel('en').mount, (e) => e.textContent && e.textContent.length > 1)
|
|
89
|
+
const t = (arr) => arr.map((e) => e.textContent).join('|')
|
|
90
|
+
assert.notEqual(t(zh), t(en), 'zh 与 en 文案不同')
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
if (GEN === 'v1') {
|
|
94
|
+
test('v1:★ CTA 只跳转不写键;× 才写 dismissed 并收起话术', () => {
|
|
95
|
+
const { mount, env } = runPanel('zh')
|
|
96
|
+
assert.equal(mount.className, 'dsh-star-row-s', 'v1 S 档行')
|
|
97
|
+
const cta = find(mount, (e) => e.className === 'dsh-star-cta')[0]
|
|
98
|
+
const hide = find(mount, (e) => e.className === 'dsh-star-hide')[0]
|
|
99
|
+
assert.ok(cta && hide, 'v1 应有 ★ 与 × 两个按钮')
|
|
100
|
+
cta.click()
|
|
101
|
+
assert.equal(env.localStorage.getItem(K1), null, '点 ★ 不写 dismissed')
|
|
102
|
+
hide.dispatch('click')
|
|
103
|
+
assert.equal(env.localStorage.getItem(K1), '1', '点 × 写 dismissed')
|
|
104
|
+
assert.ok(mount.parentNode === null || mount.className !== 'dsh-star-row-s', '× 后行被替换')
|
|
105
|
+
})
|
|
106
|
+
test('v1:已 dismissed → 只留中性链接行,无按钮', () => {
|
|
107
|
+
const { mount } = runPanel('zh', { [K1]: '1' })
|
|
108
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-cta').length, 0, 'dismissed 后无 ★')
|
|
109
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-hide').length, 0, 'dismissed 后无 ×')
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (GEN === 'v2') {
|
|
114
|
+
test('v2:纯链接一行页脚,无按钮;点 ⭐ 或 💬 即写 v2.dismissed 收敛', () => {
|
|
115
|
+
const { mount, env } = runPanel('zh')
|
|
116
|
+
assert.equal(mount.className, 'dsh-star-foot', 'v2 页脚行')
|
|
117
|
+
assert.equal(find(mount, (e) => e.tagName === 'button').length, 0, 'v2 无按钮')
|
|
118
|
+
const stars = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))
|
|
119
|
+
assert.ok(stars.length === 1, 'v2 一个 ⭐ 链接')
|
|
120
|
+
stars[0].click()
|
|
121
|
+
assert.equal(env.localStorage.getItem(K2), '1', '点 ⭐ 写 v2.dismissed')
|
|
122
|
+
})
|
|
123
|
+
test('v2:加载即清 v1 键、不迁值', () => {
|
|
124
|
+
const { env } = runPanel('zh', { [K1]: '1' })
|
|
125
|
+
assert.equal(env.localStorage.getItem(K1), null, 'v1 键被清掉')
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (GEN === 'v3') {
|
|
130
|
+
test('v3:两行页脚;⭐/💬 只跳转不收敛,只有「我已支持」写 v3.supported', () => {
|
|
131
|
+
const { mount, env } = runPanel('zh')
|
|
132
|
+
assert.equal(mount.className, 'dsh-star-foot', 'v3 页脚')
|
|
133
|
+
const btns = find(mount, (e) => e.className === 'dsh-star-support')
|
|
134
|
+
assert.equal(btns.length, 1, 'v3 一个「我已支持」按钮')
|
|
135
|
+
const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
|
|
136
|
+
star.click()
|
|
137
|
+
assert.equal(env.localStorage.getItem(K3), null, '点 ⭐ 不写 supported')
|
|
138
|
+
btns[0].dispatch('click')
|
|
139
|
+
assert.equal(env.localStorage.getItem(K3), '1', '按「我已支持」写 supported')
|
|
140
|
+
})
|
|
141
|
+
test('v3:加载即清 v1/v2 旧键、不迁值', () => {
|
|
142
|
+
const { env } = runPanel('zh', { [K1]: '1', [K2]: '1' })
|
|
143
|
+
assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
|
|
144
|
+
assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
|
|
145
|
+
})
|
|
146
|
+
test('v3:已 supported → 收敛态(仓库地址 + 💬 issue),无「我已支持」按钮', () => {
|
|
147
|
+
const { mount } = runPanel('zh', { [K3]: '1' })
|
|
148
|
+
assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v3 收敛态')
|
|
149
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-support').length, 0, '收敛后无按钮')
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (GEN === 'v4') {
|
|
154
|
+
test('v4:三动作统一描边胶囊 dsh-star-btn;⭐/💬 只跳转不收敛,只有「我已支持」写 v4.supported', () => {
|
|
155
|
+
const { mount, env } = runPanel('zh')
|
|
156
|
+
assert.equal(mount.className, 'dsh-star-foot', 'v4 页脚')
|
|
157
|
+
const isBtn = (e) => (e.className || '').split(' ').includes('dsh-star-btn')
|
|
158
|
+
const caps = find(mount, isBtn)
|
|
159
|
+
assert.equal(caps.length, 3, 'v4 三个动作都是胶囊:⭐ / 我已支持 / 💬')
|
|
160
|
+
const sup = find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support')
|
|
161
|
+
assert.equal(sup.length, 1, 'v4 一个「我已支持」胶囊按钮')
|
|
162
|
+
const star = find(mount, (e) => e.tagName === 'a' && (e.textContent || '').includes('⭐'))[0]
|
|
163
|
+
assert.ok(isBtn(star), '⭐ 是胶囊链接')
|
|
164
|
+
star.click()
|
|
165
|
+
assert.equal(env.localStorage.getItem(K4), null, '点 ⭐ 不写 supported')
|
|
166
|
+
sup[0].dispatch('click')
|
|
167
|
+
assert.equal(env.localStorage.getItem(K4), '1', '按「我已支持」写 v4.supported')
|
|
168
|
+
})
|
|
169
|
+
test('v4:加载即清 v3/v2/v1 三旧键、不迁值', () => {
|
|
170
|
+
const { env } = runPanel('zh', { [K1]: '1', [K2]: '1', [K3]: '1' })
|
|
171
|
+
assert.equal(env.localStorage.getItem(K1), null, 'v1 键清')
|
|
172
|
+
assert.equal(env.localStorage.getItem(K2), null, 'v2 键清')
|
|
173
|
+
assert.equal(env.localStorage.getItem(K3), null, 'v3 键清')
|
|
174
|
+
})
|
|
175
|
+
test('v4:已 supported → 收敛态(仓库地址 + 💬),无「我已支持」按钮', () => {
|
|
176
|
+
const { mount } = runPanel('zh', { [K4]: '1' })
|
|
177
|
+
assert.equal(mount.className, 'dsh-star-foot-collapsed', 'v4 收敛态')
|
|
178
|
+
assert.equal(find(mount, (e) => e.className === 'dsh-star-btn dsh-star-support').length, 0, '收敛后无按钮')
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|