Files
lionwebsite-frontend-mobile/tests/search.test.mjs
T
lion c9af72dc85 移动下载端改用共享核心包,与桌面端共用任务业务
- 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。
2026-10-07 16:15:24 +08:00

39 lines
1.7 KiB
JavaScript

import test from "node:test"
import assert from "node:assert/strict"
import {buildSearchParams, fetchGalleries, readResponse} from "lionwebsite-frontend-shared"
test("keyword request never hand-builds the query string", () => {
assert.deepEqual(buildSearchParams({keyword: "cat girl"}), {keyword: "cat girl"})
})
test("next page forwards the upstream cursor instead of the keyword", () => {
const params = buildSearchParams({
keyword: "cat girl", direction: "next",
href: "https://exhentai.org/?f_search=cat+girl&next=777",
})
assert.equal(params.next, "777")
assert.equal(params.keyword, "cat girl")
})
test("fetchGalleries decodes object and JSON-string payloads identically", async () => {
const asObject = {get: async () => ({data: {result: "success", data: [{gid: 1}], next: "n1"}})}
const asString = {get: async () => ({data: {result: "success", data: '[{"gid":1}]', next: "n1"}})}
const one = await fetchGalleries(asObject, {keyword: "k"})
const two = await fetchGalleries(asString, {keyword: "k"})
assert.deepEqual(one.galleries, two.galleries)
assert.equal(one.pagination.next, "n1")
})
test("fetchGalleries surfaces the backend message on failure", async () => {
const http = {get: async () => ({data: {result: "failure", data: "没有搜索到结果"}})}
await assert.rejects(() => fetchGalleries(http, {keyword: "k"}),
error => error.payload === "没有搜索到结果")
})
test("readResponse keeps all four pagination cursors", () => {
const parsed = readResponse({data: {result: "success", data: "[]",
first: "f", previous: "p", next: "n", last: "l"}})
assert.deepEqual(parsed.pagination, {first: "f", previous: "p", next: "n", last: "l"})
})