test(dashboard): extract .data from SWR cache envelope in cache tests
MissionManager.cache and MailboxModal.cache tests parsed the raw
localStorage entry as the payload, but writeCache wraps values in
{ savedAt, data }. Pull .data out before asserting on length or
nested fields. Fixes 3 failing tests.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,8 +64,8 @@ describe("MailboxModal cache hydration", () => {
|
||||
await waitFor(() => {
|
||||
const cachedRaw = localStorage.getItem(`${SWR_CACHE_KEYS.MAILBOX_INBOX_PREFIX}p1`);
|
||||
expect(cachedRaw).not.toBeNull();
|
||||
const cached = JSON.parse(cachedRaw ?? "{}");
|
||||
expect(cached.messages[0].id).toBe("msg-1");
|
||||
const cached = JSON.parse(cachedRaw ?? "{}").data;
|
||||
expect(cached?.messages?.[0]?.id).toBe("msg-1");
|
||||
expect(cached).not.toHaveProperty("conversationMessages");
|
||||
});
|
||||
});
|
||||
@@ -88,8 +88,8 @@ describe("MailboxModal cache hydration", () => {
|
||||
const { rerender } = render(<MailboxModal isOpen onClose={() => {}} projectId="p1" agents={[]} />);
|
||||
|
||||
await waitFor(() => {
|
||||
const cached = JSON.parse(localStorage.getItem(`${SWR_CACHE_KEYS.MAILBOX_INBOX_PREFIX}p1`) ?? "{}");
|
||||
expect(cached.messages).toHaveLength(100);
|
||||
const cached = JSON.parse(localStorage.getItem(`${SWR_CACHE_KEYS.MAILBOX_INBOX_PREFIX}p1`) ?? "{}").data;
|
||||
expect(cached?.messages).toHaveLength(100);
|
||||
});
|
||||
|
||||
localStorage.setItem(`${SWR_CACHE_KEYS.MAILBOX_INBOX_PREFIX}p2`, JSON.stringify({ messages: [{ id: "msg-p2", fromId: "agent-2", fromType: "agent", toId: "dashboard", toType: "user", content: "p2", type: "agent-to-user", read: false, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }], total: 1, unreadCount: 1 }));
|
||||
|
||||
@@ -72,7 +72,7 @@ describe("MissionManager cache hydration", () => {
|
||||
);
|
||||
|
||||
await screen.findByText("Mission 0");
|
||||
const cachedP1 = JSON.parse(localStorage.getItem(`${SWR_CACHE_KEYS.MISSIONS_PREFIX}p1`) ?? "[]");
|
||||
const cachedP1 = JSON.parse(localStorage.getItem(`${SWR_CACHE_KEYS.MISSIONS_PREFIX}p1`) ?? "{}").data;
|
||||
expect(cachedP1).toHaveLength(200);
|
||||
|
||||
localStorage.setItem(`${SWR_CACHE_KEYS.MISSIONS_PREFIX}p2`, JSON.stringify([{ id: "M-P2", title: "Project Two Mission", description: "", status: "planning", milestones: [] }]));
|
||||
|
||||
Reference in New Issue
Block a user