forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationCenter.test.tsx
More file actions
70 lines (59 loc) · 2.58 KB
/
Copy pathNotificationCenter.test.tsx
File metadata and controls
70 lines (59 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { ReactElement } from "react";
import { render, screen, fireEvent, act } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { describe, it, expect, beforeEach } from "vitest";
import { NotificationCenter } from "./NotificationCenter";
import { useNotificationsStore } from "../../store/notifications";
import { resetNotificationsForTesting } from "../../test-utils/notifications";
const wrap = (ui: ReactElement) =>
render(<MemoryRouter>{ui}</MemoryRouter>);
describe("NotificationCenter", () => {
beforeEach(() => {
resetNotificationsForTesting();
});
it("renders notification center page", () => {
wrap(<NotificationCenter />);
expect(screen.getByTestId("notification-center")).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /notifications/i })).toBeInTheDocument();
});
it("shows filter by type options", () => {
wrap(<NotificationCenter />);
expect(screen.getByText("Filter by type")).toBeInTheDocument();
expect(screen.getByTestId("filter-all")).toBeInTheDocument();
expect(screen.getByTestId("filter-split_invitation")).toBeInTheDocument();
});
it("filter updates displayed list", () => {
wrap(<NotificationCenter />);
fireEvent.click(screen.getByTestId("filter-payment_received"));
expect(screen.getByTestId("filter-payment_received")).toHaveClass("bg-accent");
});
it("mark all as read button is present when there are unread", () => {
wrap(<NotificationCenter />);
expect(screen.getByTestId("mark-all-read")).toBeInTheDocument();
});
it("mark all as read clears unread", () => {
wrap(<NotificationCenter />);
fireEvent.click(screen.getByTestId("mark-all-read"));
expect(screen.queryByTestId("mark-all-read")).not.toBeInTheDocument();
});
it("clear all removes all notifications", () => {
wrap(<NotificationCenter />);
fireEvent.click(screen.getByTestId("clear-all"));
expect(screen.getByTestId("empty-state")).toBeInTheDocument();
expect(screen.getByText("No notifications yet.")).toBeInTheDocument();
});
it("adding a notification via store updates the list", () => {
useNotificationsStore.getState().clearAll();
wrap(<NotificationCenter />);
expect(screen.getByTestId("empty-state")).toBeInTheDocument();
act(() => {
useNotificationsStore.getState().addNotification({
type: "system_announcement",
title: "Test",
message: "Test message",
});
});
expect(screen.queryByTestId("empty-state")).not.toBeInTheDocument();
expect(screen.getByText("Test")).toBeInTheDocument();
});
});