@gongfpp/dsh-novel-fish 0.1.4 → 1.0.0
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 +67 -55
- package/assets/icon.png +0 -0
- package/docs/community-markets.md +48 -29
- package/docs/compatibility-017.md +70 -0
- package/docs/continuous-reading-020.md +46 -0
- package/docs/evidence/banner-100.png +0 -0
- package/docs/evidence/compatibility-017-result.json +65 -0
- package/docs/evidence/continuous-reading-020-result.json +72 -0
- package/docs/evidence/native-settings-sample.md +11 -0
- package/docs/evidence/native-settings-types-015.png +0 -0
- package/docs/evidence/npm-market-014-result.json +132 -0
- package/docs/evidence/plugin-settings-details.png +0 -0
- package/docs/evidence/public-release-015-result.json +36 -0
- package/docs/evidence/reading-demo-100.png +0 -0
- package/docs/evidence/settings-100.png +0 -0
- package/docs/host-adapter.md +3 -3
- package/docs/icon-metadata-021.md +40 -0
- package/docs/interaction-paths-020.md +39 -0
- package/docs/marketplace.md +3 -3
- package/docs/native-settings-update.md +48 -0
- package/docs/plugin-settings-update.md +61 -0
- package/docs/release.md +70 -1
- package/index.json +70 -6
- package/lib/client.js +306 -185
- package/locale/en.json +15 -6
- package/locale/zh.json +15 -6
- package/package.json +15 -13
- package/scripts/check-host-contracts.mjs +246 -0
- package/src/chat-adapter.js +22 -2
- package/src/client.js +5 -5
- package/src/settings.js +155 -95
- package/src/store.js +22 -3
- package/test/chat-adapter.test.js +61 -3
- package/test/client.test.js +82 -0
- package/test/helpers/host-primitives.js +28 -0
- package/test/host-contracts.test.js +32 -0
- package/test/release.test.js +19 -5
- package/test/settings.test.js +214 -65
- package/test/store.test.js +40 -0
- package/assets/icon.svg +0 -1
package/test/release.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import test from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
|
+
import semver from 'semver'
|
|
3
4
|
import { readFile, access } from 'node:fs/promises'
|
|
4
5
|
|
|
5
6
|
const root = new URL('../', import.meta.url)
|
|
@@ -9,15 +10,26 @@ test('public package identity matches the Host patch and browser module', async
|
|
|
9
10
|
const manifest = JSON.parse(await read('package.json'))
|
|
10
11
|
assert.equal(manifest.name, '@gongfpp/dsh-novel-fish')
|
|
11
12
|
assert.equal(manifest.repository.url, 'https://github.com/gongfpp/dsh-novel-fish.git')
|
|
12
|
-
assert.equal(manifest.engines.dsh, '0.2.1-rc.2')
|
|
13
|
+
assert.equal(manifest.engines.dsh, '>=0.2.1-rc.2 <=0.2.2-alpha.2')
|
|
13
14
|
assert.ok((await read('cordis.patch.yml')).includes(`name: '${manifest.name}'`))
|
|
14
15
|
assert.ok((await read('src/client.js')).includes(`const MODULE_ID = '${manifest.name}'`))
|
|
15
16
|
assert.ok((await read('lib/client.js')).includes(manifest.name))
|
|
16
|
-
for (const path of ['./index.js', './lib/client.js', './assets/icon.
|
|
17
|
+
for (const path of ['./index.js', './lib/client.js', './assets/icon.png', './locale/en.json', './locale/zh.json']) {
|
|
17
18
|
await access(new URL(path, root))
|
|
18
19
|
}
|
|
19
20
|
})
|
|
20
21
|
|
|
22
|
+
test('host compatibility includes rc.2–rc.5 and alpha.2 but does not promise unknown releases', async () => {
|
|
23
|
+
const { engines } = JSON.parse(await read('package.json'))
|
|
24
|
+
// DSH preflight evaluates prereleases explicitly, unlike npm's default semver rules.
|
|
25
|
+
for (const version of ['0.2.1-rc.2', '0.2.1-rc.3', '0.2.1-rc.4', '0.2.1-rc.5', '0.2.2-alpha.2']) {
|
|
26
|
+
assert.equal(semver.satisfies(version, engines.dsh, { includePrerelease: true }), true, version)
|
|
27
|
+
}
|
|
28
|
+
for (const version of ['0.2.0', '0.2.1-alpha.5', '0.2.1-rc.1', '0.2.2-alpha.3', '0.2.2', '0.3.0', '1.0.0']) {
|
|
29
|
+
assert.equal(semver.satisfies(version, engines.dsh, { includePrerelease: true }), false, version)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
21
33
|
test('notices include JSZip prebundled libraries and the zlib copyright', async () => {
|
|
22
34
|
const notices = await read('THIRD-PARTY-NOTICES.txt')
|
|
23
35
|
for (const name of ['pako@1.0.11', 'lie@3.3.0', 'immediate@3.0.6', 'setimmediate@1.0.5', 'crc-32@1.2.2', 'Jean-loup Gailly and Mark Adler']) {
|
|
@@ -39,7 +51,8 @@ test('市场索引保留固定提交来源、版本唯一和宿主兼容范围',
|
|
|
39
51
|
for (const version of entry.versions) {
|
|
40
52
|
assert.match(version.version, /^\d+\.\d+\.\d+$/u)
|
|
41
53
|
assert.ok(Number.isSafeInteger(version.publishTimestamp) && version.publishTimestamp > 0)
|
|
42
|
-
assert.equal(version.engines.dsh, manifest.engines.dsh)
|
|
54
|
+
if (version.version === manifest.version) assert.equal(version.engines.dsh, manifest.engines.dsh)
|
|
55
|
+
else assert.match(version.engines.dsh, /^(?:\^|~|>=)?\d+\.\d+\.\d+(?:-[\w.-]+)?/u)
|
|
43
56
|
assert.equal(version.source.type, 'git')
|
|
44
57
|
assert.equal(version.source.url, entry.repository.url)
|
|
45
58
|
assert.match(version.source.commit, /^[a-f0-9]{40}$/u)
|
|
@@ -49,8 +62,9 @@ test('市场索引保留固定提交来源、版本唯一和宿主兼容范围',
|
|
|
49
62
|
test('README local links resolve and installation contains no personal absolute path', async () => {
|
|
50
63
|
const readme = await read('README.md')
|
|
51
64
|
assert.doesNotMatch(readme, /\/Users\/|C:\\Users\\/u)
|
|
52
|
-
const
|
|
53
|
-
|
|
65
|
+
const index = JSON.parse(await read('index.json'))
|
|
66
|
+
const published = index.plugins.find(plugin => plugin.name === '@gongfpp/dsh-novel-fish').versions[0]
|
|
67
|
+
assert.ok(readme.includes(`github:gongfpp/dsh-novel-fish#v${published.version}`), 'installation uses an actually published version')
|
|
54
68
|
for (const match of readme.matchAll(/\]\(([^)]+)\)/gu)) {
|
|
55
69
|
const path = match[1].replace(/^<|>$/gu, '').split('#')[0]
|
|
56
70
|
if (!path || /^[a-z]+:/iu.test(path)) continue
|
package/test/settings.test.js
CHANGED
|
@@ -4,117 +4,266 @@ import React from 'react'
|
|
|
4
4
|
import TestRenderer, { act } from 'react-test-renderer'
|
|
5
5
|
import { createSettingsRow } from '../src/settings.js'
|
|
6
6
|
import { DEFAULT_SETTINGS } from '../src/store.js'
|
|
7
|
+
import { HostSwitch, HostMenu, HostModal, hostPrimitives } from './helpers/host-primitives.js'
|
|
7
8
|
import zh from '../locale/zh.json' with { type: 'json' }
|
|
8
9
|
import en from '../locale/en.json' with { type: 'json' }
|
|
9
10
|
|
|
10
11
|
const t = (key, vars = {}) => key.split('.').reduce((value, field) => value?.[field], zh)?.replace(/\{(\w+)\}/gu, (_, key) => String(vars[key])) ?? key
|
|
12
|
+
const SettingsRow = createSettingsRow(React, hostPrimitives)
|
|
13
|
+
const control = (view, key, value = true) => view.root.find(node => typeof node.type === 'string' && node.props[key] === value)
|
|
14
|
+
const menu = (view, key, value = true) => view.root.findAllByType(HostMenu).find(node => node.props.anchor.props[key] === value)
|
|
11
15
|
|
|
12
16
|
function setup(settings = {}) {
|
|
13
|
-
const state = { hydrated: true, books: [{id:'book-a',title:'测试书籍',format:'txt',progress:1,segmentCount:3}], settings:{...DEFAULT_SETTINGS,currentBookId:'book-a'
|
|
14
|
-
const options = [], books = []
|
|
17
|
+
const state = { hydrated: true, books: [{ id: 'book-a', title: '测试书籍', format: 'txt', progress: 1, segmentCount: 3 }], settings: { ...DEFAULT_SETTINGS, currentBookId: 'book-a', ...settings } }
|
|
18
|
+
const options = [], books = [], notices = []
|
|
15
19
|
const props = { t,
|
|
16
|
-
useNovelState: select => select(state), useNovelUi: select => select({ notice:null }),
|
|
17
|
-
onSetOption: async (
|
|
18
|
-
|
|
20
|
+
useNovelState: select => select(state), useNovelUi: select => select({ notice: null }),
|
|
21
|
+
onSetOption: async (key, value) => { options.push([key, value]); state.settings[key] = value },
|
|
22
|
+
onSelectBook: async id => { books.push(id); state.settings.currentBookId = id },
|
|
23
|
+
onSetNotice: notice => notices.push(notice), onDeleteBook: async () => {}, onImportFile: async () => {},
|
|
19
24
|
}
|
|
20
|
-
return { props, state, options, books }
|
|
25
|
+
return { props, state, options, books, notices }
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
const model = setup()
|
|
28
|
+
async function mount(model, options) {
|
|
25
29
|
let view
|
|
26
|
-
await act(async () => { view = TestRenderer.create(React.createElement(
|
|
30
|
+
await act(async () => { view = TestRenderer.create(React.createElement(SettingsRow, model.props), options) })
|
|
31
|
+
return view
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test('区域多选使用宿主 Menu,保留五类、全选和空选语义,不创建阅读入口', async () => {
|
|
35
|
+
const model = setup(), view = await mount(model)
|
|
27
36
|
try {
|
|
28
|
-
const
|
|
29
|
-
assert.
|
|
30
|
-
assert.
|
|
31
|
-
|
|
32
|
-
assert.
|
|
33
|
-
|
|
34
|
-
assert.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
assert.
|
|
41
|
-
assert.
|
|
42
|
-
assert.match(JSON.stringify(view.toJSON()), /保留真实内容.*分隔线下追加纯文本小说/u)
|
|
37
|
+
const picker = () => menu(view, 'data-novel-type-select')
|
|
38
|
+
assert.deepEqual(picker().props.items.map(item => item.id), ['reasoning', 'tool-call', 'read-file', 'command', 'file-search'])
|
|
39
|
+
assert.deepEqual(picker().props.selectedIds, ['reasoning'])
|
|
40
|
+
await act(async () => picker().props.anchor.props.onClick())
|
|
41
|
+
assert.equal(picker().props.open, true)
|
|
42
|
+
await act(async () => picker().props.onSelect('read-file'))
|
|
43
|
+
assert.deepEqual(model.options.at(-1), ['targetTypes', ['reasoning', 'read-file']])
|
|
44
|
+
assert.equal(picker().props.open, true)
|
|
45
|
+
await act(async () => picker().props.onSelect('__all'))
|
|
46
|
+
assert.deepEqual(model.options.at(-1), ['targetTypes', ['reasoning', 'tool-call', 'read-file', 'command', 'file-search']])
|
|
47
|
+
await act(async () => picker().props.onSelect('__all'))
|
|
48
|
+
assert.deepEqual(model.options.at(-1), ['targetTypes', []])
|
|
49
|
+
assert.equal(view.root.findAllByType('select').length, 0)
|
|
50
|
+
assert.equal(view.root.findAllByType('details').length, 0)
|
|
43
51
|
assert.equal(view.root.findAllByType('textarea').length, 0)
|
|
44
|
-
assert.equal(view.root.
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
assert.equal(view.root.findAllByType('h3').length, 3)
|
|
53
|
+
assert.doesNotMatch(JSON.stringify(view.toJSON()), /选择一个真实思考步骤|刷新步骤列表|阅读位置|粘贴文本|会话 session-/u)
|
|
54
|
+
assert.equal(control(view, 'data-novel-progress').children.join(''), t('settings.progressValue', { progress: 1, total: 3, percent: 33 }))
|
|
55
|
+
await act(async () => menu(view, 'data-novel-book-select').props.onSelect('book-a'))
|
|
47
56
|
assert.deepEqual(model.books, ['book-a'])
|
|
48
57
|
} finally { await act(async () => view.unmount()) }
|
|
49
58
|
})
|
|
50
59
|
|
|
51
|
-
test('
|
|
60
|
+
test('多选存储未完成时快速重复选择只写一次,书籍进度不受影响', async () => {
|
|
52
61
|
const model = setup()
|
|
53
|
-
let
|
|
54
|
-
|
|
62
|
+
let release
|
|
63
|
+
const saving = new Promise(resolve => { release = resolve })
|
|
64
|
+
model.props.onSetOption = async (...values) => { model.options.push(values); await saving }
|
|
65
|
+
const view = await mount(model)
|
|
66
|
+
try {
|
|
67
|
+
const select = menu(view, 'data-novel-type-select').props.onSelect
|
|
68
|
+
await act(async () => { select('read-file'); select('command') })
|
|
69
|
+
assert.deepEqual(model.options, [['targetTypes', ['reasoning', 'read-file']]])
|
|
70
|
+
assert.equal(menu(view, 'data-novel-type-select').props.items.every(item => item.disabled), true)
|
|
71
|
+
await act(async () => release())
|
|
72
|
+
assert.equal(menu(view, 'data-novel-type-select').props.items.some(item => item.disabled), false)
|
|
73
|
+
assert.equal(model.state.books[0].progress, 1)
|
|
74
|
+
} finally { release(); await act(async () => view.unmount()) }
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('图标跟随 DSH,标题使用原生菜单,自定义后才出现宿主 Input', async () => {
|
|
78
|
+
const model = setup(), view = await mount(model)
|
|
55
79
|
try {
|
|
56
|
-
assert.equal(view.root.findAllByType('input').filter(node =>
|
|
57
|
-
assert.equal(view.root.findAllByProps({'data-novel-preset':'icon'}).length, 0)
|
|
58
|
-
assert.match(JSON.stringify(view.toJSON()),
|
|
80
|
+
assert.equal(view.root.findAllByType('input').filter(node => node.props.type !== 'file').length, 0)
|
|
81
|
+
assert.equal(view.root.findAllByProps({ 'data-novel-preset': 'icon' }).length, 0)
|
|
82
|
+
assert.match(JSON.stringify(view.toJSON()), /图标与折叠交互跟随 DSH/u)
|
|
59
83
|
assert.deepEqual(model.options, [])
|
|
60
|
-
|
|
61
|
-
await act(async () => title.props.onChange({currentTarget:{value:'
|
|
62
|
-
|
|
63
|
-
await act(async () => custom.props.onChange({currentTarget:{value:'我的标题'}}))
|
|
64
|
-
assert.deepEqual(model.options.at(-1), ['mainTitle','我的标题'])
|
|
84
|
+
await act(async () => menu(view, 'data-novel-preset', 'title').props.onSelect('__custom'))
|
|
85
|
+
await act(async () => control(view, 'data-novel-title').props.onChange({ currentTarget: { value: '我的标题' } }))
|
|
86
|
+
assert.deepEqual(model.options.at(-1), ['mainTitle', '我的标题'])
|
|
65
87
|
} finally { await act(async () => view.unmount()) }
|
|
66
88
|
})
|
|
67
89
|
|
|
68
90
|
test('已保存的自定义内容保留,打开设置不会写入选项', async () => {
|
|
69
|
-
const model = setup({mainTitle:'已存标题'})
|
|
70
|
-
let view
|
|
71
|
-
await act(async () => { view = TestRenderer.create(React.createElement(createSettingsRow(React), model.props)) })
|
|
91
|
+
const model = setup({ mainTitle: '已存标题' }), view = await mount(model)
|
|
72
92
|
try {
|
|
73
|
-
assert.equal(view
|
|
93
|
+
assert.equal(control(view, 'data-novel-title').props.defaultValue, '已存标题')
|
|
74
94
|
assert.deepEqual(model.options, [])
|
|
75
95
|
} finally { await act(async () => view.unmount()) }
|
|
76
96
|
})
|
|
77
97
|
|
|
78
|
-
test('
|
|
79
|
-
const model = setup({mainTitle:'已存标题'})
|
|
98
|
+
test('宿主 Input 不受异步落盘旧快照控制,连续输入不会被 React 回退', async () => {
|
|
99
|
+
const model = setup({ mainTitle: '已存标题' })
|
|
80
100
|
let release
|
|
81
101
|
const saving = new Promise(resolve => { release = resolve })
|
|
82
102
|
model.props.onSetOption = async () => saving
|
|
83
|
-
|
|
84
|
-
await act(async () => { view = TestRenderer.create(React.createElement(createSettingsRow(React), model.props)) })
|
|
103
|
+
const view = await mount(model)
|
|
85
104
|
try {
|
|
86
|
-
const input = view
|
|
87
|
-
await act(async () => {
|
|
105
|
+
const input = control(view, 'data-novel-title')
|
|
106
|
+
await act(async () => { input.props.onChange({ currentTarget: { value: '已存标题连续输入' } }) })
|
|
88
107
|
assert.equal(Object.hasOwn(input.props, 'value'), false)
|
|
89
108
|
assert.equal(input.props.defaultValue, '已存标题')
|
|
90
|
-
await act(async () =>
|
|
109
|
+
await act(async () => release())
|
|
91
110
|
} finally { release(); await act(async () => view.unmount()) }
|
|
92
111
|
})
|
|
93
112
|
|
|
94
|
-
test('
|
|
95
|
-
const model = setup({mainTitle:'已存标题'})
|
|
96
|
-
const notices = []
|
|
113
|
+
test('预设保存失败保留自定义模式,菜单的选中项仍然有效', async () => {
|
|
114
|
+
const model = setup({ mainTitle: '已存标题' })
|
|
97
115
|
let reject
|
|
98
116
|
const saving = new Promise((resolve, fail) => { reject = fail })
|
|
99
117
|
model.props.onSetOption = async () => saving
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
const view = await mount(model)
|
|
119
|
+
try {
|
|
120
|
+
await act(async () => menu(view, 'data-novel-preset', 'title').props.onSelect('思考'))
|
|
121
|
+
assert.equal(menu(view, 'data-novel-preset', 'title').props.selectedId, '__custom')
|
|
122
|
+
await act(async () => reject(new Error('模拟保存失败')))
|
|
123
|
+
const picker = menu(view, 'data-novel-preset', 'title')
|
|
124
|
+
assert.equal(picker.props.selectedId, '__custom')
|
|
125
|
+
assert.ok(picker.props.items.some(item => item.id === picker.props.selectedId))
|
|
126
|
+
assert.equal(control(view, 'data-novel-title').props.defaultValue, '已存标题')
|
|
127
|
+
assert.match(model.notices.at(-1), /模拟保存失败/u)
|
|
128
|
+
} finally { await act(async () => view.unmount()) }
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('原生导入按钮触发隐藏文件选择;导入失败清空文件值并允许重试', async () => {
|
|
132
|
+
const model = setup()
|
|
133
|
+
let clicked = 0, attempts = 0, reject
|
|
134
|
+
const importing = new Promise((resolve, fail) => { reject = fail })
|
|
135
|
+
model.props.onImportFile = async () => { attempts++; return importing }
|
|
136
|
+
const view = await mount(model, { createNodeMock: element => element.props['data-novel-file-input'] ? { click: () => { clicked++ } } : null })
|
|
137
|
+
try {
|
|
138
|
+
const button = () => control(view, 'data-novel-import')
|
|
139
|
+
await act(async () => button().props.onClick())
|
|
140
|
+
assert.equal(clicked, 1)
|
|
141
|
+
const input = control(view, 'data-novel-file-input')
|
|
142
|
+
assert.equal(input.props.hidden, true)
|
|
143
|
+
const file = { files: [{ name: '示例.md' }], value: '示例.md' }
|
|
144
|
+
await act(async () => { input.props.onChange({ currentTarget: file }); input.props.onChange({ currentTarget: file }) })
|
|
145
|
+
assert.equal(attempts, 1)
|
|
146
|
+
assert.equal(button().props.disabled, true)
|
|
147
|
+
await act(async () => reject(new Error('模拟导入失败')))
|
|
148
|
+
assert.equal(file.value, '')
|
|
149
|
+
assert.equal(button().props.disabled, false)
|
|
150
|
+
assert.match(model.notices.at(-1), /模拟导入失败/u)
|
|
151
|
+
model.props.onImportFile = async () => { attempts++; return { segmentCount: 2 } }
|
|
152
|
+
await act(async () => view.update(React.createElement(SettingsRow, { ...model.props })))
|
|
153
|
+
await act(async () => control(view, 'data-novel-file-input').props.onChange({ currentTarget: file }))
|
|
154
|
+
assert.equal(attempts, 2)
|
|
155
|
+
assert.match(model.notices.at(-1), /导入完成:2 段/u)
|
|
156
|
+
assert.equal(model.state.books[0].progress, 1)
|
|
157
|
+
} finally { await act(async () => view.unmount()) }
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('删除使用宿主 Modal;取消不删除、保存失败可重试、快速确认不重复删除', async () => {
|
|
161
|
+
const model = setup(), deleted = []
|
|
162
|
+
let reject
|
|
163
|
+
const removing = new Promise((resolve, fail) => { reject = fail })
|
|
164
|
+
model.props.onDeleteBook = async id => { deleted.push(id); return removing }
|
|
165
|
+
const view = await mount(model)
|
|
166
|
+
try {
|
|
167
|
+
await act(async () => control(view, 'data-novel-delete').props.onClick())
|
|
168
|
+
assert.equal(view.root.findByType(HostModal).props.open, true)
|
|
169
|
+
assert.match(view.root.findByType(HostModal).props.description, /测试书籍/u)
|
|
170
|
+
await act(async () => view.root.findByType(HostModal).props.onClose())
|
|
171
|
+
assert.equal(view.root.findByType(HostModal).props.open, false)
|
|
172
|
+
assert.deepEqual(deleted, [])
|
|
173
|
+
await act(async () => control(view, 'data-novel-delete').props.onClick())
|
|
174
|
+
const confirm = control(view, 'data-novel-delete-confirm').props.onClick
|
|
175
|
+
await act(async () => { confirm(); confirm() })
|
|
176
|
+
assert.deepEqual(deleted, ['book-a'])
|
|
177
|
+
await act(async () => view.root.findByType(HostModal).props.onClose())
|
|
178
|
+
assert.equal(view.root.findByType(HostModal).props.open, true)
|
|
179
|
+
await act(async () => reject(new Error('模拟删除失败')))
|
|
180
|
+
assert.match(view.root.findByProps({ role: 'alert' }).children.join(''), /模拟删除失败/u)
|
|
181
|
+
assert.equal(model.state.books[0].progress, 1)
|
|
182
|
+
model.props.onDeleteBook = async id => deleted.push(id)
|
|
183
|
+
await act(async () => view.update(React.createElement(SettingsRow, { ...model.props })))
|
|
184
|
+
await act(async () => control(view, 'data-novel-delete-confirm').props.onClick())
|
|
185
|
+
assert.deepEqual(deleted, ['book-a', 'book-a'])
|
|
186
|
+
assert.equal(view.root.findByType(HostModal).props.open, false)
|
|
187
|
+
} finally { await act(async () => view.unmount()) }
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
test('原生阅读开关保存时禁用并合并快速点击,不影响书籍进度', async () => {
|
|
191
|
+
const model = setup({ enabled: false })
|
|
192
|
+
let release, view
|
|
193
|
+
const saving = new Promise(resolve => { release = resolve })
|
|
194
|
+
model.props.onSetOption = async (key, value) => {
|
|
195
|
+
model.options.push([key, value]); await saving
|
|
196
|
+
model.state.settings[key] = value
|
|
197
|
+
view.update(React.createElement(SettingsRow, { ...model.props }))
|
|
198
|
+
}
|
|
199
|
+
view = await mount(model)
|
|
200
|
+
try {
|
|
201
|
+
const toggle = () => view.root.findByProps({ 'aria-label': t('settings.enabled') })
|
|
202
|
+
assert.equal(toggle().props['aria-label'], zh.settings.enabled)
|
|
203
|
+
assert.equal(toggle().props['aria-checked'], false)
|
|
204
|
+
const change = view.root.findAllByType(HostSwitch).find(node => node.props.label === t('settings.enabled')).props.onChange
|
|
205
|
+
await act(async () => { change(true); change(true) })
|
|
206
|
+
assert.deepEqual(model.options, [['enabled', true]])
|
|
207
|
+
assert.equal(toggle().props.disabled, true)
|
|
208
|
+
assert.equal(toggle().props['aria-checked'], false)
|
|
209
|
+
await act(async () => release())
|
|
210
|
+
assert.equal(toggle().props.disabled, false)
|
|
211
|
+
assert.equal(toggle().props['aria-checked'], true)
|
|
212
|
+
assert.equal(model.state.books[0].progress, 1)
|
|
213
|
+
assert.equal(model.state.settings.currentBookId, 'book-a')
|
|
214
|
+
assert.deepEqual(model.state.settings.targetTypes, DEFAULT_SETTINGS.targetTypes)
|
|
215
|
+
} finally { release(); await act(async () => view.unmount()) }
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('阅读开关保存失败不假装开启,报错后可以重试', async () => {
|
|
219
|
+
const model = setup({ enabled: false })
|
|
220
|
+
model.props.onSetOption = async () => { throw new Error('模拟存储失败') }
|
|
221
|
+
const view = await mount(model)
|
|
222
|
+
try {
|
|
223
|
+
await act(async () => view.root.findByProps({ 'aria-label': t('settings.enabled') }).props.onClick())
|
|
224
|
+
const toggle = view.root.findByProps({ 'aria-label': t('settings.enabled') })
|
|
225
|
+
assert.equal(toggle.props.disabled, false)
|
|
226
|
+
assert.equal(toggle.props['aria-checked'], false)
|
|
227
|
+
assert.match(model.notices.at(-1), /操作失败.*模拟存储失败/u)
|
|
228
|
+
model.props.onSetOption = async (...values) => model.options.push(values)
|
|
229
|
+
await act(async () => view.update(React.createElement(SettingsRow, { ...model.props })))
|
|
230
|
+
await act(async () => view.root.findByProps({ 'aria-label': t('settings.enabled') }).props.onClick())
|
|
231
|
+
assert.deepEqual(model.options, [['enabled', true]])
|
|
232
|
+
} finally { await act(async () => view.unmount()) }
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('书库未就绪或出错时原生控件禁用,不写设置', async () => {
|
|
236
|
+
for (const state of [{ hydrated: false }, { error: '模拟书库错误' }]) {
|
|
237
|
+
const model = setup({ enabled: false })
|
|
238
|
+
Object.assign(model.state, state)
|
|
239
|
+
const view = await mount(model)
|
|
240
|
+
try {
|
|
241
|
+
const toggle = view.root.findByProps({ 'aria-label': t('settings.enabled') })
|
|
242
|
+
assert.equal(toggle.props.disabled, true)
|
|
243
|
+
assert.equal(control(view, 'data-novel-import').props.disabled, true)
|
|
244
|
+
assert.equal(menu(view, 'data-novel-type-select').props.items.every(item => item.disabled), true)
|
|
245
|
+
await act(async () => toggle.props.onClick())
|
|
246
|
+
assert.deepEqual(model.options, [])
|
|
247
|
+
} finally { await act(async () => view.unmount()) }
|
|
248
|
+
}
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
test('同一区域续读是默认关闭的设置项,开启后写入 continueOnReopen', async () => {
|
|
252
|
+
const model = setup()
|
|
253
|
+
const view = await mount(model)
|
|
103
254
|
try {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
assert.equal(
|
|
107
|
-
await act(async () =>
|
|
108
|
-
assert.
|
|
109
|
-
assert.equal(
|
|
110
|
-
assert.ok(select.findAllByType('option').some(option => option.props.value === select.props.value))
|
|
111
|
-
assert.match(notices.at(-1), /模拟保存失败/u)
|
|
255
|
+
const toggle = view.root.findByProps({ 'aria-label': t('settings.continueOnReopen') })
|
|
256
|
+
assert.equal(toggle.props['aria-checked'], false)
|
|
257
|
+
assert.equal(view.root.findAllByType(HostSwitch).length, 2)
|
|
258
|
+
await act(async () => toggle.props.onClick())
|
|
259
|
+
assert.deepEqual(model.options.at(-1), ['continueOnReopen', true])
|
|
260
|
+
assert.equal(model.state.settings.continueOnReopen, true)
|
|
112
261
|
} finally { await act(async () => view.unmount()) }
|
|
113
262
|
})
|
|
114
263
|
|
|
115
|
-
test('
|
|
264
|
+
test('中英文设置文案键一致,不再含位置选择翻译', () => {
|
|
116
265
|
assert.deepEqual(Object.keys(zh.settings).sort(), Object.keys(en.settings).sort())
|
|
117
|
-
for (const key of ['targetType','typeReasoning','typeHint']) {
|
|
266
|
+
for (const key of ['targetType', 'typeReasoning', 'typeHint', 'importBook', 'cancel', 'confirmDelete']) {
|
|
118
267
|
assert.equal(typeof zh.settings[key], 'string')
|
|
119
268
|
assert.equal(typeof en.settings[key], 'string')
|
|
120
269
|
}
|
package/test/store.test.js
CHANGED
|
@@ -575,3 +575,43 @@ test('end of book does not wrap and target settings contain no passage binding',
|
|
|
575
575
|
assert.equal(Object.hasOwn(store.getSettingsSnapshot(), 'targets'), false)
|
|
576
576
|
assert.equal(Object.hasOwn(storage.settings, 'targets'), false)
|
|
577
577
|
})
|
|
578
|
+
|
|
579
|
+
test('续读设置默认关闭、按布尔归一化,未知设置项仍被拒绝', async () => {
|
|
580
|
+
const { store } = makeStore()
|
|
581
|
+
await store.ready
|
|
582
|
+
assert.equal(store.getSettingsSnapshot().continueOnReopen, false)
|
|
583
|
+
await store.setOption('continueOnReopen', 'yes')
|
|
584
|
+
assert.equal(store.getSettingsSnapshot().continueOnReopen, true)
|
|
585
|
+
await store.setOption('continueOnReopen', 0)
|
|
586
|
+
assert.equal(store.getSettingsSnapshot().continueOnReopen, false)
|
|
587
|
+
await assert.rejects(() => store.setOption('unknown', true), /未知设置项/u)
|
|
588
|
+
store.dispose()
|
|
589
|
+
})
|
|
590
|
+
|
|
591
|
+
test('claimPassage 保留该区域已读段,continuePassage 才在同一区域推进', async () => {
|
|
592
|
+
const { store, storage } = makeStore()
|
|
593
|
+
await store.ready
|
|
594
|
+
assert.equal((await store.claimPassage('A')).passage.text, 'A')
|
|
595
|
+
assert.equal((await store.claimPassage('A')).passage.text, 'A', '重复展开仍显示这一页')
|
|
596
|
+
assert.equal((await store.continuePassage('A')).passage.text, 'B')
|
|
597
|
+
assert.equal(storage.books.get('book-a').progress, 2)
|
|
598
|
+
assert.equal((await store.claimPassage('A')).passage.text, 'B', '关闭续读后显示该区域最后读到的段落')
|
|
599
|
+
assert.equal((await store.continuePassage('A')).passage.text, 'C')
|
|
600
|
+
assert.equal(storage.books.get('book-a').progress, 3)
|
|
601
|
+
assert.equal((await store.continuePassage('A')).kind, 'end')
|
|
602
|
+
assert.equal((await store.continuePassage('A')).kind, 'end', '读完后不再推进')
|
|
603
|
+
store.dispose()
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
test('continuePassage 对未读区域等同首次读取,并遵守停读与切书', async () => {
|
|
607
|
+
const { store, storage } = makeStore()
|
|
608
|
+
await store.ready
|
|
609
|
+
assert.equal((await store.continuePassage('A')).passage.text, 'A')
|
|
610
|
+
await store.setOption('enabled', false)
|
|
611
|
+
assert.equal((await store.continuePassage('A')).kind, 'empty')
|
|
612
|
+
assert.equal(storage.books.get('book-a').progress, 1, '停读后续读不再推进进度')
|
|
613
|
+
await store.setOption('enabled', true)
|
|
614
|
+
await store.selectBook('book-b')
|
|
615
|
+
assert.equal((await store.continuePassage('A')).passage.text, 'X', '切书后从新书自己的进度续读')
|
|
616
|
+
store.dispose()
|
|
617
|
+
})
|
package/assets/icon.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect x="8" y="9" width="48" height="46" rx="12" fill="#3076a8"/><path d="M19 20c7-4 13-4 20 0v27c-7-4-13-4-20 0zm26 0c-7-4-13-4-20 0v27c7-4 13-4 20 0z" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"/><path d="M32 21v27" stroke="#fff" stroke-width="2"/></svg>
|