mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-22 14:13:49 +08:00
feat(favorites): add cloud favorite management
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/vue";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import FavoriteFolderManager from "@/components/FavoriteFolderManager.vue";
|
||||
import type {
|
||||
FavoriteFolder,
|
||||
ResolvedFavoriteItem,
|
||||
} from "@/global/typedefinition";
|
||||
|
||||
const folder: FavoriteFolder = {
|
||||
id: 1,
|
||||
name: "默认收藏夹",
|
||||
itemCount: 1,
|
||||
createdAt: "2026-05-18T00:00:00Z",
|
||||
updatedAt: "2026-05-18T00:00:00Z",
|
||||
};
|
||||
|
||||
const item: ResolvedFavoriteItem = {
|
||||
item: {
|
||||
id: 2,
|
||||
appKey: "app:office:wps",
|
||||
pkgname: "wps",
|
||||
name: "WPS",
|
||||
category: "office",
|
||||
iconUrl: "",
|
||||
createdAt: "2026-05-18T00:00:00Z",
|
||||
},
|
||||
status: "downlisted",
|
||||
reason: "已下架",
|
||||
selectedApp: null,
|
||||
};
|
||||
|
||||
describe("FavoriteFolderManager", () => {
|
||||
it("shows downlisted favorites and emits bulk delete", async () => {
|
||||
const rendered = render(FavoriteFolderManager, {
|
||||
props: {
|
||||
folders: [folder],
|
||||
activeFolderId: 1,
|
||||
items: [item],
|
||||
loading: false,
|
||||
error: "",
|
||||
},
|
||||
});
|
||||
|
||||
expect(screen.getByText("已下架")).toBeTruthy();
|
||||
await fireEvent.click(screen.getByLabelText("选择 WPS"));
|
||||
await fireEvent.click(screen.getByRole("button", { name: "移除选中" }));
|
||||
|
||||
expect(rendered.emitted("remove-selected")?.[0]?.[0]).toEqual([2]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveFavoriteItems } from "@/modules/favoriteAvailability";
|
||||
import type { App, FavoriteItem } from "@/global/typedefinition";
|
||||
|
||||
const app = (origin: "spark" | "apm", overrides: Partial<App> = {}): App => ({
|
||||
name: "WPS",
|
||||
pkgname: "wps",
|
||||
version: "1.0.0",
|
||||
filename: "wps_1.0.0_amd64.deb",
|
||||
torrent_address: "",
|
||||
author: "",
|
||||
contributor: "",
|
||||
website: "",
|
||||
update: "",
|
||||
size: "",
|
||||
more: "",
|
||||
tags: "",
|
||||
img_urls: [],
|
||||
icons: "",
|
||||
category: "office",
|
||||
origin,
|
||||
currentStatus: "not-installed",
|
||||
arch: "amd64",
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const favorite: FavoriteItem = {
|
||||
id: 1,
|
||||
appKey: "app:office:wps",
|
||||
pkgname: "wps",
|
||||
name: "WPS",
|
||||
category: "office",
|
||||
iconUrl: "",
|
||||
createdAt: "2026-05-18T00:00:00Z",
|
||||
};
|
||||
|
||||
describe("favoriteAvailability", () => {
|
||||
it("marks downlisted favorites", () => {
|
||||
expect(
|
||||
resolveFavoriteItems(
|
||||
[favorite],
|
||||
[],
|
||||
[],
|
||||
{ spark: true, apm: true },
|
||||
"both",
|
||||
)[0].status,
|
||||
).toBe("downlisted");
|
||||
});
|
||||
|
||||
it("selects preferred installable variant", () => {
|
||||
const resolved = resolveFavoriteItems(
|
||||
[favorite],
|
||||
[app("spark"), app("apm")],
|
||||
[],
|
||||
{ spark: true, apm: true },
|
||||
"both",
|
||||
)[0];
|
||||
expect(resolved.status).toBe("installable");
|
||||
expect(resolved.selectedApp?.origin).toBe("apm");
|
||||
});
|
||||
|
||||
it("marks installed favorites", () => {
|
||||
const resolved = resolveFavoriteItems(
|
||||
[favorite],
|
||||
[app("apm")],
|
||||
[app("apm", { currentStatus: "installed" })],
|
||||
{ spark: true, apm: true },
|
||||
"both",
|
||||
)[0];
|
||||
expect(resolved.status).toBe("installed");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user