- store 改由 createGalleryStore(variant:"mobile") 生成,保留“继续加载”交互 - 与桌面端共用同一份 API 解码、任务规范化、派生与排序实现 - 取消收藏不再因本地找不到 gid 抛 TypeError - 删除重复的 taskSocket/progressiveImages/validate/thumbnail,改从共享包导入 - 远端搜索改用共享 fetchGalleries,翻页按游标转发 - main.js 按需注册 Element Plus,入口 JS 由约 1.13MB 降到约 486KB - 依赖新增 file:../lionwebsite-frontend-shared 测试:12 项通过;构建成功,入口仍为 /asserts/mobile/index.js|css。
92 lines
3.8 KiB
JavaScript
92 lines
3.8 KiB
JavaScript
import test from "node:test"
|
|
import assert from "node:assert/strict"
|
|
|
|
// 直接加载真实的移动端 store;在 Node 里 import 到的就是下发到浏览器的那份配置。
|
|
const store = (await import("../src/store/index.js")).default
|
|
|
|
const tasks = () => [
|
|
{gid: 1, name: "beta [tag]", status: "下载完成", pages: 10, proceeding: 10,
|
|
thumb_link: "", createTime: 2, downloader: 7, isCollect: true},
|
|
{gid: 2, name: "alpha", status: "下载中", pages: 10, proceeding: 5,
|
|
thumb_link: "", createTime: 1, downloader: 7, isCollect: false},
|
|
{gid: 3, name: "gamma", status: "已提交", pages: 10, proceeding: 0,
|
|
thumb_link: "", createTime: 3, downloader: 8, isCollect: false},
|
|
]
|
|
|
|
function reset() {
|
|
store.state.AuthCode = "test-auth"
|
|
store.state.userId = 7
|
|
store.state.category = "total"
|
|
store.state.sortType = "createTime"
|
|
store.state.length = 2
|
|
store.state.visiblePages = 1
|
|
store.state.isAdmin = false
|
|
store.state.downloaderFilter = null
|
|
store.commit("_updateGalleryTasks", tasks())
|
|
}
|
|
|
|
test("mobile variant shares one task list with the desktop core", () => {
|
|
reset()
|
|
assert.equal(store.state.totalGalleryTask.length, 3)
|
|
assert.equal(store.getters.downloadGallery.length, 2)
|
|
assert.equal(store.getters.collectGallery.length, 1)
|
|
})
|
|
|
|
test("continue-loading reveals every task beyond the first page", () => {
|
|
reset()
|
|
assert.equal(store.getters.visibleTasks.length, 2)
|
|
assert.equal(store.getters.taskRemaining, 1)
|
|
store.commit("_showMoreTasks")
|
|
assert.equal(store.getters.visibleTasks.length, 3)
|
|
assert.equal(store.getters.taskRemaining, 0)
|
|
})
|
|
|
|
test("json-string and object payloads decode to the same store result", () => {
|
|
reset()
|
|
const fromObjects = store.state.totalGalleryTask.map(task => task.gid)
|
|
store.state.totalGalleryTask = []
|
|
store.commit("_updateGalleryTasks", JSON.parse(JSON.stringify(tasks())))
|
|
assert.deepEqual(store.state.totalGalleryTask.map(task => task.gid), fromObjects)
|
|
})
|
|
|
|
test("cancelling a collect for a task missing from the list never throws", () => {
|
|
reset()
|
|
// 旧实现会在 collectGallery 里找不到 gid 时抛 TypeError。
|
|
assert.doesNotThrow(() => store.commit("_setCollect", {gid: 999, collect: false}))
|
|
store.commit("_setCollect", {gid: 1, collect: false})
|
|
assert.equal(store.getters.collectGallery.length, 0)
|
|
})
|
|
|
|
test("sorting never reorders the single source array", () => {
|
|
reset()
|
|
const before = store.state.totalGalleryTask.map(task => task.gid)
|
|
store.commit("_setSortType", "name")
|
|
assert.deepEqual(store.state.totalGalleryTask.map(task => task.gid), before)
|
|
assert.deepEqual(store.getters.visibleTasks.map(task => task.name), ["alpha", "beta [tag]"])
|
|
})
|
|
|
|
test("link search surfaces the match as a search result on mobile", () => {
|
|
const messages = []
|
|
reset()
|
|
store.commit("_searchLocalByLink", "https://example.org/g/3/key/")
|
|
assert.equal(store.state.isSearch, true)
|
|
assert.equal(store.getters.searchResults.length, 1)
|
|
assert.equal(store.getters.searchResults[0].gid, 3)
|
|
})
|
|
|
|
test("thumbnail and online image urls carry the active auth code", () => {
|
|
store.state.AuthCode = "code with spaces"
|
|
store.commit("_updateGalleryTasks", [{
|
|
gid: 123, name: "sample", status: "已提交",
|
|
thumb_link: "https://example.org/thumb?a=1&b=2", createTime: 1, downloader: 7,
|
|
}])
|
|
const thumbnail = new URL(store.state.totalGalleryTask[0].thumb_link)
|
|
assert.equal(thumbnail.searchParams.get("AuthCode"), "code with spaces")
|
|
assert.equal(thumbnail.searchParams.get("path"), "https://example.org/thumb?a=1&b=2")
|
|
|
|
store.commit("_setReadingGallery", {gid: 123, pages: 1})
|
|
const image = new URL(store.state.readingGallery.images[0])
|
|
assert.equal(image.searchParams.get("gid"), "123")
|
|
assert.equal(image.searchParams.get("AuthCode"), "code with spaces")
|
|
})
|