From 0c561e9b396c9760bf73c9796ba2af8390f6be4f Mon Sep 17 00:00:00 2001 From: Yiling-J Date: Thu, 3 Sep 2026 21:36:28 +0800 Subject: [PATCH] refactor(webui): use semantic system colors in notification settings (#379) --- .../settings/NotificationSettings.test.tsx | 124 ++++++++++++++++++ .../settings/NotificationSettings.tsx | 102 +++++--------- 2 files changed, 160 insertions(+), 66 deletions(-) create mode 100644 packages/webui/components/settings/NotificationSettings.test.tsx diff --git a/packages/webui/components/settings/NotificationSettings.test.tsx b/packages/webui/components/settings/NotificationSettings.test.tsx new file mode 100644 index 00000000..da9438df --- /dev/null +++ b/packages/webui/components/settings/NotificationSettings.test.tsx @@ -0,0 +1,124 @@ +// @vitest-environment happy-dom +import { cleanup, render, screen, fireEvent, waitFor } from '@testing-library/react' +import React from 'react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { NotificationSettings } from './NotificationSettings' +import type { NotificationSettings as Settings } from '@shumai/dtos' + +const mockGetSettings = vi.fn() +const mockPostSettings = vi.fn() + +vi.mock('@/ui/api/client', () => ({ + client: { + api: { + teams: { + ':teamId': { + notifications: { + settings: { + $get: () => mockGetSettings(), + $post: (args: unknown) => mockPostSettings(args), + }, + }, + }, + }, + }, + }, +})) + +vi.mock('sonner', () => ({ + toast: { + success: vi.fn(), + error: vi.fn(), + }, +})) + +describe('NotificationSettings', () => { + const initialSettings: Settings = { + comments: true, + replies: true, + mentions: true, + yourUploads: false, + otherUploads: true, + statusUpdates: true, + kanbanTasks: true, + kanbanComments: true, + } + + beforeEach(() => { + vi.clearAllMocks() + mockGetSettings.mockResolvedValue({ + ok: true, + json: async () => initialSettings, + }) + mockPostSettings.mockResolvedValue({ + ok: true, + json: async () => ({ ...initialSettings, yourUploads: true }), + }) + }) + + afterEach(() => { + cleanup() + }) + + function renderComponent() { + const queryClient = new QueryClient({ + defaultOptions: { + queries: { retry: false }, + }, + }) + + return render( + + + , + ) + } + + it('renders all notification sections and switches', async () => { + const { container } = renderComponent() + + await waitFor(() => { + expect(screen.getByText(/comments & replies/i)).toBeDefined() + }) + + expect(screen.getByText(/assets & statuses/i)).toBeDefined() + expect(screen.getByText(/kanban notifications/i)).toBeDefined() + + // Verify switches are rendered + const switches = screen.getAllByRole('switch') + expect(switches.length).toBe(8) + + // Verify no hardcoded blue/purple color classes exist in the markup + const html = container.innerHTML + expect(html).not.toMatch(/text-blue-500/) + expect(html).not.toMatch(/bg-blue-50/) + expect(html).not.toMatch(/text-purple-600/) + expect(html).not.toMatch(/bg-purple-50/) + expect(html).not.toMatch(/text-indigo-500/) + expect(html).not.toMatch(/border-slate-/) + }) + + it('handles toggling a notification setting', async () => { + renderComponent() + + await waitFor(() => { + expect(screen.getByText(/comments & replies/i)).toBeDefined() + }) + + const switches = screen.getAllByRole('switch') + // Click the first switch (comments) + fireEvent.click(switches[0]) + + await waitFor(() => { + expect(mockPostSettings).toHaveBeenCalledTimes(1) + expect(mockPostSettings).toHaveBeenCalledWith({ + param: { teamId: 'team-1' }, + json: { + ...initialSettings, + comments: false, + }, + }) + }) + }) +}) diff --git a/packages/webui/components/settings/NotificationSettings.tsx b/packages/webui/components/settings/NotificationSettings.tsx index a4974b45..867c95cd 100644 --- a/packages/webui/components/settings/NotificationSettings.tsx +++ b/packages/webui/components/settings/NotificationSettings.tsx @@ -71,28 +71,24 @@ export function NotificationSettings({ teamId }: { teamId: string }) {
{/* Comments Settings */} - - + +
- + {m.comments_and_replies()}
{m.comments_notification_description()}
- + {/* General Comments */}
-
+
-

- {m.general_comments()} -

-

- {m.when_someone_comments()} -

+

{m.general_comments()}

+

{m.when_someone_comments()}

-
+
-

- {m.comment_replies()} -

-

- {m.when_someone_replies()} -

+

{m.comment_replies()}

+

{m.when_someone_replies()}

-
+
-

- {m.at_mentions()} -

-

- {m.when_someone_mentions()} -

+

{m.at_mentions()}

+

{m.when_someone_mentions()}

{/* Assets Settings */} - - + +
- + {m.assets_and_statuses()}
{m.assets_notification_description()}
- + {/* Your Uploads */}
-
+
-

- {m.your_uploads()} -

-

- {m.when_you_upload_assets()} -

+

{m.your_uploads()}

+

{m.when_you_upload_assets()}

-
+
-

- {m.other_uploads()} -

-

+

{m.other_uploads()}

+

{m.when_other_users_upload_assets()}

@@ -205,16 +187,12 @@ export function NotificationSettings({ teamId }: { teamId: string }) { {/* Status Updates */}
-
+
-

- {m.status_updates()} -

-

- {m.when_someone_changes_status()} -

+

{m.status_updates()}

+

{m.when_someone_changes_status()}

{/* Kanban Settings */} - - + +
- + {m.kanban_notifications()}
{m.kanban_notification_description()}
- + {/* Kanban Tasks */}
-
+
-

- {m.kanban_tasks()} -

-

- {m.when_kanban_task_events()} -

+

{m.kanban_tasks()}

+

{m.when_kanban_task_events()}

-
+
-

- {m.kanban_comments()} -

-

- {m.when_kanban_task_commented()} -

+

{m.kanban_comments()}

+

{m.when_kanban_task_commented()}