pluginStoreListing.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. import { describe, expect, it } from "vitest";
  2. import type {
  3. ZCodeAvailablePluginSummary,
  4. ZCodeInstalledPluginSummary,
  5. ZCodePluginInfo,
  6. ZCodePluginMarketplaceSummary,
  7. } from "@zcode/shared";
  8. import {
  9. buildStoreItems,
  10. canUpdatePluginItem,
  11. formatCanonicalPluginName,
  12. formatCanonicalMarketplaceName,
  13. groupItemsByCategory,
  14. resolveItemDisplayName,
  15. resolvePluginDisplayName,
  16. resolveUniquePluginListingByName,
  17. resolveLocalizedList,
  18. resolveLocalizedText,
  19. selectFeaturedItems,
  20. sortMarketplaceSources,
  21. sortInstalledStripItems,
  22. sortPersonalMarketplaceGroups,
  23. } from "../src/settings/pluginStoreListing.js";
  24. function makeSummary(
  25. overrides: Partial<ZCodeAvailablePluginSummary> & { id: string },
  26. ): ZCodeAvailablePluginSummary {
  27. const [name = "", marketplace = ""] = overrides.id.split("@");
  28. return {
  29. name,
  30. marketplace,
  31. installed: false,
  32. ...overrides,
  33. };
  34. }
  35. function makeInfo(overrides: Partial<ZCodePluginInfo> & { id: string }): ZCodePluginInfo {
  36. const [name = "", marketplace = ""] = overrides.id.split("@");
  37. return {
  38. name,
  39. marketplace,
  40. enabled: true,
  41. source: "cache",
  42. skillRootCount: 0,
  43. commandRootCount: 0,
  44. mcpServerNames: [],
  45. rootPath: `/cache/${name}`,
  46. ...overrides,
  47. };
  48. }
  49. function makeMarketplace(
  50. overrides: Partial<ZCodePluginMarketplaceSummary> & { id: string },
  51. ): ZCodePluginMarketplaceSummary {
  52. return {
  53. name: overrides.id,
  54. source: {},
  55. pluginCount: 0,
  56. ...overrides,
  57. };
  58. }
  59. describe("pluginStoreListing", () => {
  60. it("only falls back to a listing when the plugin name is unique", () => {
  61. const official = makeSummary({
  62. id: "computer-use@zcode-plugins-official",
  63. listing: { displayName: "Computer Use" },
  64. });
  65. const custom = makeSummary({
  66. id: "computer-use@custom-marketplace",
  67. listing: { displayName: "Custom CUA" },
  68. });
  69. expect(resolveUniquePluginListingByName([official], "computer-use")).toEqual(official.listing);
  70. expect(resolveUniquePluginListingByName([official, custom], "computer-use")).toBeUndefined();
  71. });
  72. it("prefers the official listing name over the internal plugin slug", () => {
  73. expect(
  74. resolvePluginDisplayName(
  75. {
  76. name: "computer-use",
  77. listing: {
  78. displayName: "Computer Use",
  79. displayNameI18n: { "zh-CN": "电脑控制" },
  80. },
  81. },
  82. "en-US",
  83. ),
  84. ).toBe("Computer Use");
  85. expect(
  86. resolvePluginDisplayName(
  87. {
  88. name: "computer-use",
  89. listing: {
  90. displayName: "Computer Use",
  91. displayNameI18n: { "zh-CN": "电脑控制" },
  92. },
  93. },
  94. "zh-CN",
  95. ),
  96. ).toBe("电脑控制");
  97. expect(resolvePluginDisplayName({ name: "third-party-tool" }, "en-US")).toBe(
  98. "Third Party Tool",
  99. );
  100. });
  101. it("formats marketplace slugs as display names", () => {
  102. expect(formatCanonicalMarketplaceName("zcode-plugins-official", "en-US")).toBe(
  103. "ZCode Plugins Official",
  104. );
  105. expect(formatCanonicalMarketplaceName("claude-plugins-official", "en-US")).toBe(
  106. "Claude Plugins Official",
  107. );
  108. });
  109. it("resolves localized text with exact locale then language-prefix fallback", () => {
  110. expect(resolveLocalizedText("zh-CN", "base", { "zh-CN": "精确" })).toBe("精确");
  111. expect(resolveLocalizedText("zh-CN", "base", { zh: "前缀" })).toBe("前缀");
  112. expect(resolveLocalizedText("en-US", "base", { en: "english" })).toBe("english");
  113. expect(resolveLocalizedText("en-US", "base", { "zh-CN": "中文" })).toBe("base");
  114. expect(resolveLocalizedList("zh-CN", ["base"], { zh: ["列表"] })).toEqual(["列表"]);
  115. expect(resolveLocalizedList("en-US", undefined, undefined)).toBeUndefined();
  116. });
  117. it("joins catalog, runtime, and installed records into store items", () => {
  118. const items = buildStoreItems({
  119. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  120. marketplaceAvailabilityKnown: true,
  121. availablePlugins: [
  122. makeSummary({ id: "a@zcode-plugins-official", installed: true }),
  123. makeSummary({ id: "b@zcode-plugins-official" }),
  124. ],
  125. installedPlugins: [
  126. {
  127. id: "a@zcode-plugins-official",
  128. name: "a",
  129. marketplace: "zcode-plugins-official",
  130. enabled: true,
  131. scope: "user",
  132. } as ZCodeInstalledPluginSummary,
  133. ],
  134. plugins: [
  135. makeInfo({ id: "a@zcode-plugins-official" }),
  136. // 运行时独有(inline)插件也要出现在条目集合里。
  137. makeInfo({ id: "c@inline", source: "inline" }),
  138. ],
  139. restorableBuiltins: [makeSummary({ id: "d@zcode-plugins-official" })],
  140. });
  141. const byId = new Map(items.map((item) => [item.id, item]));
  142. expect(byId.get("a@zcode-plugins-official")?.installed).toBe(true);
  143. expect(byId.get("a@zcode-plugins-official")?.info).toBeDefined();
  144. expect(byId.get("a@zcode-plugins-official")?.installedMeta).toBeDefined();
  145. expect(byId.get("b@zcode-plugins-official")?.installed).toBe(false);
  146. expect(byId.get("c@inline")?.installed).toBe(true);
  147. expect(byId.get("c@inline")?.orphaned).toBe(false);
  148. expect(byId.get("d@zcode-plugins-official")?.restorable).toBe(true);
  149. });
  150. it("merges a restorable built-in with its catalog entry instead of dropping detail metadata", () => {
  151. const [item] = buildStoreItems({
  152. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  153. marketplaceAvailabilityKnown: true,
  154. availablePlugins: [
  155. makeSummary({
  156. id: "document-skills@zcode-plugins-official",
  157. listing: {
  158. category: "productivity",
  159. displayName: "Document Skills",
  160. descriptionI18n: { "en-US": "Work with documents" },
  161. },
  162. }),
  163. ],
  164. installedPlugins: [],
  165. plugins: [],
  166. restorableBuiltins: [makeSummary({ id: "document-skills@zcode-plugins-official" })],
  167. });
  168. expect(item).toMatchObject({
  169. id: "document-skills@zcode-plugins-official",
  170. installed: false,
  171. restorable: true,
  172. listing: {
  173. category: "productivity",
  174. displayName: "Document Skills",
  175. },
  176. });
  177. });
  178. it("does not treat a missing-package configuration projection as installed inventory", () => {
  179. const [item] = buildStoreItems({
  180. marketplaces: [makeMarketplace({ id: "personal-market" })],
  181. marketplaceAvailabilityKnown: true,
  182. availablePlugins: [
  183. makeSummary({
  184. id: "missing@personal-market",
  185. installed: true,
  186. marketplace: "personal-market",
  187. }),
  188. ],
  189. installedPlugins: [],
  190. plugins: [
  191. makeInfo({
  192. id: "missing@personal-market",
  193. packageStatus: "missing",
  194. rootPath: "",
  195. source: "missing",
  196. }),
  197. ],
  198. restorableBuiltins: [],
  199. });
  200. expect(item).toMatchObject({
  201. id: "missing@personal-market",
  202. installed: false,
  203. info: {
  204. packageStatus: "missing",
  205. },
  206. });
  207. });
  208. it("keeps marketplace ownership when a stale restorable marker overlaps an installed record", () => {
  209. const [item] = buildStoreItems({
  210. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  211. marketplaceAvailabilityKnown: true,
  212. availablePlugins: [
  213. makeSummary({ id: "document-skills@zcode-plugins-official", installed: true }),
  214. ],
  215. installedPlugins: [
  216. {
  217. id: "document-skills@zcode-plugins-official",
  218. name: "document-skills",
  219. marketplace: "zcode-plugins-official",
  220. enabled: true,
  221. scope: "user",
  222. } as ZCodeInstalledPluginSummary,
  223. ],
  224. plugins: [makeInfo({ id: "document-skills@zcode-plugins-official", enabled: true })],
  225. restorableBuiltins: [makeSummary({ id: "document-skills@zcode-plugins-official" })],
  226. });
  227. expect(item).toMatchObject({
  228. id: "document-skills@zcode-plugins-official",
  229. installed: true,
  230. restorable: false,
  231. info: { enabled: true },
  232. installedMeta: { enabled: true },
  233. });
  234. });
  235. it("marks a cache install as orphaned when its known marketplace source is absent", () => {
  236. const [item] = buildStoreItems({
  237. marketplaces: [],
  238. marketplaceAvailabilityKnown: true,
  239. availablePlugins: [],
  240. installedPlugins: [
  241. {
  242. id: "orphan@personal-market",
  243. name: "orphan",
  244. marketplace: "personal-market",
  245. enabled: true,
  246. scope: "user",
  247. updateStatus: "update-available",
  248. } as ZCodeInstalledPluginSummary,
  249. ],
  250. plugins: [makeInfo({ id: "orphan@personal-market" })],
  251. restorableBuiltins: [],
  252. });
  253. expect(item).toMatchObject({
  254. id: "orphan@personal-market",
  255. installed: true,
  256. orphaned: true,
  257. });
  258. expect(canUpdatePluginItem(item)).toBe(false);
  259. });
  260. it("does not infer orphaned from a missing catalog listing when the source still exists", () => {
  261. const installedMeta: ZCodeInstalledPluginSummary = {
  262. id: "installed@personal-market",
  263. name: "installed",
  264. marketplace: "personal-market",
  265. enabled: true,
  266. scope: "user",
  267. updateStatus: "update-available",
  268. };
  269. const [item] = buildStoreItems({
  270. marketplaces: [makeMarketplace({ id: "personal-market" })],
  271. marketplaceAvailabilityKnown: true,
  272. availablePlugins: [],
  273. installedPlugins: [installedMeta],
  274. plugins: [makeInfo({ id: "installed@personal-market" })],
  275. restorableBuiltins: [],
  276. });
  277. expect(item?.orphaned).toBe(false);
  278. expect(canUpdatePluginItem(item)).toBe(true);
  279. });
  280. it("does not turn missing configuration into an installable item without a catalog source", () => {
  281. const missing = makeInfo({
  282. id: "document-skills@zcode-plugins-official",
  283. source: "missing",
  284. packageStatus: "missing",
  285. rootPath: "",
  286. });
  287. const input = {
  288. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  289. marketplaceAvailabilityKnown: true,
  290. availablePlugins: [],
  291. installedPlugins: [],
  292. plugins: [missing],
  293. restorableBuiltins: [],
  294. };
  295. expect(buildStoreItems(input)).toEqual([]);
  296. // 配置诊断必须仍留给设置页,不能通过删源数据来掩盖商店误投影。
  297. expect(input.plugins).toEqual([missing]);
  298. expect(
  299. buildStoreItems({ ...input, availablePlugins: [makeSummary({ id: missing.id })] }),
  300. ).toEqual([
  301. expect.objectContaining({ id: missing.id, installed: false, summary: expect.any(Object) }),
  302. ]);
  303. });
  304. it("never marks official plugins as orphaned when the catalog listing is absent", () => {
  305. const [item] = buildStoreItems({
  306. marketplaces: [],
  307. marketplaceAvailabilityKnown: true,
  308. availablePlugins: [],
  309. installedPlugins: [],
  310. plugins: [
  311. makeInfo({
  312. id: "builtin@zcode-plugins-official",
  313. source: "official",
  314. }),
  315. ],
  316. restorableBuiltins: [],
  317. });
  318. expect(item?.orphaned).toBe(false);
  319. });
  320. it("allows updates only when the installed item still has a marketplace source", () => {
  321. const installedMeta: ZCodeInstalledPluginSummary = {
  322. id: "plugin@personal-market",
  323. name: "plugin",
  324. marketplace: "personal-market",
  325. enabled: true,
  326. scope: "user",
  327. updateStatus: "update-available",
  328. };
  329. expect(canUpdatePluginItem({ installedMeta, orphaned: false })).toBe(true);
  330. expect(canUpdatePluginItem({ installedMeta, orphaned: true })).toBe(false);
  331. expect(
  332. canUpdatePluginItem({
  333. installedMeta: { ...installedMeta, updateStatus: "none" },
  334. orphaned: false,
  335. }),
  336. ).toBe(false);
  337. });
  338. it("selects featured items from public marketplaces in catalog order", () => {
  339. const items = buildStoreItems({
  340. marketplaces: [
  341. makeMarketplace({ id: "zcode-plugins-official" }),
  342. makeMarketplace({ id: "claude-plugins-official" }),
  343. ],
  344. marketplaceAvailabilityKnown: true,
  345. availablePlugins: [
  346. makeSummary({ id: "alpha@zcode-plugins-official" }),
  347. makeSummary({ id: "beta@zcode-plugins-official" }),
  348. makeSummary({ id: "gamma@claude-plugins-official" }),
  349. ],
  350. installedPlugins: [],
  351. plugins: [],
  352. restorableBuiltins: [],
  353. });
  354. const publicItems = items.filter((item) => item.marketplace === "zcode-plugins-official");
  355. const featured = selectFeaturedItems(publicItems, [
  356. makeMarketplace({ id: "zcode-plugins-official", featured: ["beta", "missing", "alpha"] }),
  357. // 非公开市场的 featured 名单不参与。
  358. makeMarketplace({ id: "claude-plugins-official", featured: ["gamma"] }),
  359. ]);
  360. expect(featured.map((item) => item.name)).toEqual(["beta", "alpha"]);
  361. });
  362. it("orders category groups identically across locales with a fixed product order", () => {
  363. const items = buildStoreItems({
  364. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  365. marketplaceAvailabilityKnown: true,
  366. availablePlugins: [
  367. makeSummary({ id: "a@zcode-plugins-official", listing: { category: "productivity" } }),
  368. makeSummary({ id: "b@zcode-plugins-official", listing: { category: "developer-tools" } }),
  369. makeSummary({ id: "c@zcode-plugins-official", listing: { category: "legal" } }),
  370. makeSummary({ id: "d@zcode-plugins-official", listing: { category: "template" } }),
  371. makeSummary({ id: "e@zcode-plugins-official", listing: { category: "utilities" } }),
  372. makeSummary({ id: "f@zcode-plugins-official", listing: { category: "zebra-unknown" } }),
  373. makeSummary({ id: "h@zcode-plugins-official", listing: { category: "finance" } }),
  374. makeSummary({ id: "g@zcode-plugins-official" }),
  375. ],
  376. installedPlugins: [],
  377. plugins: [],
  378. restorableBuiltins: [],
  379. });
  380. // 固定产品顺序:已知分类按 KNOWN_CATEGORY_ORDER,未知分类按 slug 排在其后,other 恒最后;
  381. // 与 UI locale 无关(旧实现按本地化标签排序,zh 拼音序与 en 字母序会得到不同分组顺序)。
  382. const expected = [
  383. "productivity",
  384. "developer-tools",
  385. "utilities",
  386. "finance",
  387. "legal",
  388. "template",
  389. "zebra-unknown",
  390. "other",
  391. ];
  392. for (const locale of ["zh-CN", "en-US"]) {
  393. expect(groupItemsByCategory(items, locale).map((group) => group.category)).toEqual(expected);
  394. }
  395. });
  396. it("prefers listing display name with locale resolution", () => {
  397. const [item] = buildStoreItems({
  398. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  399. marketplaceAvailabilityKnown: true,
  400. availablePlugins: [
  401. makeSummary({
  402. id: "a@zcode-plugins-official",
  403. listing: { displayName: "Alpha", displayNameI18n: { "zh-CN": "阿尔法" } },
  404. }),
  405. ],
  406. installedPlugins: [],
  407. plugins: [],
  408. restorableBuiltins: [],
  409. });
  410. expect(item).toBeDefined();
  411. expect(resolveItemDisplayName(item!, "zh-CN")).toBe("阿尔法");
  412. expect(resolveItemDisplayName(item!, "en-US")).toBe("Alpha");
  413. });
  414. it("formats a canonical plugin name when no display name is configured", () => {
  415. const [item] = buildStoreItems({
  416. marketplaces: [makeMarketplace({ id: "zcode-plugins-official" })],
  417. marketplaceAvailabilityKnown: true,
  418. availablePlugins: [
  419. makeSummary({
  420. id: "cloudbase-skills@zcode-plugins-official",
  421. name: "cloudbase-skills",
  422. }),
  423. ],
  424. installedPlugins: [],
  425. plugins: [],
  426. restorableBuiltins: [],
  427. });
  428. expect(item).toBeDefined();
  429. expect(resolveItemDisplayName(item!, "en-US")).toBe("Cloudbase Skills");
  430. expect(formatCanonicalPluginName("zcode-guide", "en-US")).toBe("ZCode Guide");
  431. expect(formatCanonicalPluginName("aws-mcp-server", "en-US")).toBe("AWS MCP Server");
  432. expect(formatCanonicalPluginName("AWS_mCp_tools", "en-US")).toBe("AWS MCP Tools");
  433. });
  434. it("sorts built-in and inline plugins first, then marketplace plugins by installedAt desc", () => {
  435. const items = buildStoreItems({
  436. marketplaces: [
  437. makeMarketplace({ id: "m" }),
  438. makeMarketplace({ id: "zcode-plugins-official" }),
  439. ],
  440. marketplaceAvailabilityKnown: true,
  441. availablePlugins: [],
  442. installedPlugins: [
  443. {
  444. id: "old@m",
  445. name: "old",
  446. marketplace: "m",
  447. enabled: true,
  448. scope: "user",
  449. installedAt: "2026-01-01T00:00:00Z",
  450. } as ZCodeInstalledPluginSummary,
  451. {
  452. id: "new@m",
  453. name: "new",
  454. marketplace: "m",
  455. enabled: true,
  456. scope: "user",
  457. installedAt: "2026-07-01T00:00:00Z",
  458. } as ZCodeInstalledPluginSummary,
  459. {
  460. id: "builtin@zcode-plugins-official",
  461. name: "builtin",
  462. marketplace: "zcode-plugins-official",
  463. enabled: true,
  464. scope: "user",
  465. installedAt: "2025-01-01T00:00:00Z",
  466. } as ZCodeInstalledPluginSummary,
  467. ],
  468. plugins: [
  469. makeInfo({ id: "old@m" }),
  470. makeInfo({ id: "new@m" }),
  471. makeInfo({ id: "inline@inline", source: "inline" }),
  472. makeInfo({ id: "builtin@zcode-plugins-official", source: "official" }),
  473. ],
  474. restorableBuiltins: [],
  475. });
  476. const sorted = sortInstalledStripItems(items, "en-US");
  477. expect(sorted.map((item) => item.name)).toEqual(["builtin", "inline", "new", "old"]);
  478. });
  479. it("orders personal marketplace groups by lastUpdated descending, sinking unknown to the end", () => {
  480. const groups = [
  481. { marketplace: "claude-plugins-official", title: "Claude Code Plugins", items: [] },
  482. { marketplace: "zcode-plugins-test", title: "zcode-plugins-test", items: [] },
  483. { marketplace: "never-refreshed", title: "never-refreshed", items: [] },
  484. { marketplace: "paid-demo-market", title: "paid-demo-market", items: [] },
  485. ];
  486. const sorted = sortPersonalMarketplaceGroups(
  487. groups,
  488. [
  489. makeMarketplace({ id: "claude-plugins-official", lastUpdated: "2026-01-01T00:00:00Z" }),
  490. makeMarketplace({ id: "zcode-plugins-test", lastUpdated: "2026-08-20T12:00:00Z" }),
  491. makeMarketplace({ id: "paid-demo-market", lastUpdated: "2026-08-20T12:00:00Z" }),
  492. // never-refreshed 无记录:没有 lastUpdated,按缺失沉底。
  493. ],
  494. "en-US",
  495. );
  496. expect(sorted.map((group) => group.marketplace)).toEqual([
  497. // 最近刷新的在前;同刻(zcode-plugins-test / paid-demo-market)按显示名字母序。
  498. "paid-demo-market",
  499. "zcode-plugins-test",
  500. "claude-plugins-official",
  501. "never-refreshed",
  502. ]);
  503. });
  504. it("pins official sources and sorts custom sources by lastUpdated", () => {
  505. const sorted = sortMarketplaceSources(
  506. [
  507. makeMarketplace({
  508. id: "never-refreshed",
  509. name: "Never Refreshed",
  510. }),
  511. makeMarketplace({
  512. id: "zcode-plugins-test",
  513. name: "zcode-plugins-test",
  514. lastUpdated: "2026-08-20T12:00:00Z",
  515. }),
  516. makeMarketplace({
  517. id: "claude-plugins-official",
  518. name: "claude-plugins-official",
  519. lastUpdated: "2026-01-01T00:00:00Z",
  520. }),
  521. makeMarketplace({
  522. id: "zcode-plugins-official",
  523. name: "zcode-plugins-official",
  524. lastUpdated: "2026-08-20T23:00:00Z",
  525. }),
  526. makeMarketplace({
  527. id: "zcode-labs",
  528. name: "zcode-labs",
  529. lastUpdated: "2026-08-20T12:00:00Z",
  530. }),
  531. ],
  532. "en-US",
  533. );
  534. expect(sorted.map((marketplace) => marketplace.id)).toEqual([
  535. "zcode-plugins-official",
  536. "claude-plugins-official",
  537. "zcode-labs",
  538. "zcode-plugins-test",
  539. "never-refreshed",
  540. ]);
  541. });
  542. });
  543. describe("document plugin default order", () => {
  544. const names = ["pdf", "presentations", "spreadsheets", "documents"];
  545. const ids = names.map((name) => `${name}@zcode-plugins-official`);
  546. const items = buildStoreItems({
  547. marketplaces: [],
  548. installedPlugins: [],
  549. restorableBuiltins: [],
  550. availablePlugins: ["aaa", ...names.toReversed()].map((name) =>
  551. makeSummary({
  552. id: `${name}@zcode-plugins-official`,
  553. installed: true,
  554. listing: { category: "productivity" },
  555. }),
  556. ),
  557. plugins: ["aaa", ...names].map((name) =>
  558. makeInfo({
  559. id: `${name}@zcode-plugins-official`,
  560. source: "official",
  561. enabled: false,
  562. }),
  563. ),
  564. });
  565. it.each(["en-US", "zh-CN"])(
  566. "pins documents across installed and category views in %s",
  567. (locale) => {
  568. expect(
  569. sortInstalledStripItems(items, locale)
  570. .slice(0, 4)
  571. .map((item) => item.id),
  572. ).toEqual(ids);
  573. expect(
  574. groupItemsByCategory(items, locale)[0]
  575. ?.items.slice(0, 4)
  576. .map((item) => item.id),
  577. ).toEqual(ids);
  578. expect(items[0]?.name).toBe("aaa");
  579. },
  580. );
  581. it("retains explicit server priority and skips absent document plugins", () => {
  582. const groups = groupItemsByCategory(
  583. items.filter((item) => item.name !== "pdf"),
  584. "en-US",
  585. {
  586. pluginOrder: { productivity: ["aaa@zcode-plugins-official"] },
  587. },
  588. );
  589. expect(groups[0]?.items.map((item) => item.name)).toEqual([
  590. "aaa",
  591. "presentations",
  592. "spreadsheets",
  593. "documents",
  594. ]);
  595. });
  596. it("does not pin personal plugins with the same name", () => {
  597. const personal = items.map((item) => ({
  598. ...item,
  599. id: `${item.name}@personal`,
  600. marketplace: "personal",
  601. }));
  602. expect(sortInstalledStripItems(personal, "en-US")[0]?.name).toBe("aaa");
  603. });
  604. });