featureSuggestedPromptRotation.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { afterEach, describe, expect, it } from "vitest";
  2. import {
  3. advanceRecommendedPromptPane,
  4. getRecommendedPromptsForPane,
  5. registerRecommendedPromptPane,
  6. unregisterRecommendedPromptPane,
  7. } from "@/v4/featureSuggestedPromptRotation.js";
  8. const paneIds = ["rotation-first", "rotation-second"];
  9. afterEach(() => {
  10. for (const id of paneIds) unregisterRecommendedPromptPane(id);
  11. });
  12. describe("active task recommendations", () => {
  13. it("replaces all three visible office recommendations when refreshing", () => {
  14. registerRecommendedPromptPane(paneIds[0]!, "office");
  15. for (let refresh = 0; refresh < 6; refresh += 1) {
  16. const previous = getRecommendedPromptsForPane(paneIds[0]!, "office");
  17. advanceRecommendedPromptPane(paneIds[0]!);
  18. const next = getRecommendedPromptsForPane(paneIds[0]!, "office");
  19. expect(next).toHaveLength(3);
  20. expect(
  21. next.every((item) => !previous.some((shown) => shown.id === item.id)),
  22. ).toBe(true);
  23. expect(new Set(next.map((item) => item.iconUrl)).size).toBe(3);
  24. }
  25. });
  26. it("keeps each coding pane visually varied while avoiding repeated tasks across panes", () => {
  27. registerRecommendedPromptPane(paneIds[0]!, "coding");
  28. registerRecommendedPromptPane(paneIds[1]!, "coding");
  29. const first = getRecommendedPromptsForPane(paneIds[0]!, "coding");
  30. const second = getRecommendedPromptsForPane(paneIds[1]!, "coding");
  31. expect(first).toHaveLength(3);
  32. expect(second).toHaveLength(3);
  33. expect(new Set(first.map((item) => item.iconUrl))).toHaveProperty(
  34. "size",
  35. 3,
  36. );
  37. expect(new Set(second.map((item) => item.iconUrl))).toHaveProperty(
  38. "size",
  39. 3,
  40. );
  41. expect(
  42. second.every((item) => !first.some((shown) => shown.id === item.id)),
  43. ).toBe(true);
  44. advanceRecommendedPromptPane(paneIds[0]!);
  45. const refreshed = getRecommendedPromptsForPane(paneIds[0]!, "coding");
  46. expect(new Set(refreshed.map((item) => item.iconUrl))).toHaveProperty(
  47. "size",
  48. 3,
  49. );
  50. expect(refreshed.map((item) => item.id)).not.toEqual(
  51. first.map((item) => item.id),
  52. );
  53. });
  54. });