From 18fecebc268e6a4e9d8f3a0d3ee24a1b5fc895a9 Mon Sep 17 00:00:00 2001 From: Ammar Yasser <143096817+AMYasserF@users.noreply.github.com> Date: Mon, 15 Dec 2025 21:39:27 +0200 Subject: [PATCH] test: increase messages and layout test coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Messages feature: 49% → 60.1% coverage (+66 tests) - Added comprehensive tests for MessageMenu, MessageItem, useMessageItem - Added ConversationItemWithUnseen tests (100% coverage) - Enhanced messageStore tests (96.23% coverage) - Added useConversationsList tests (80.64% coverage) - Removed all console logs from messages feature - Fixed mark-as-seen error handling - Layout feature: 0% → 19.25% coverage (+66 tests) - Created tests for Logo, ProfileSection, Footer, EmptySpace - Created tests for WhoToFollow, WhatIsHappening - Enhanced LayoutWrapper, MenuItems, PostButton tests - Enhanced LeftSidebar, RightSidebar, MobileBottomBar tests - All 72 layout tests passing Total: Added 132 new tests across both features --- .github/workflows/private-trigger.yml | 7 +- src/components/ui/forms/types.ts | 8 +- src/components/ui/input/types.ts | 7 +- src/features/layout/tests/EmptySpace.test.tsx | 25 + src/features/layout/tests/Footer.test.tsx | 37 ++ .../layout/tests/LayoutWrapper.test.tsx | 147 +++++- .../layout/tests/LeftSidebar.test.tsx | 62 ++- src/features/layout/tests/Logo.test.tsx | 44 ++ src/features/layout/tests/MenuItems.test.tsx | 100 +++- .../layout/tests/MobileBottomBar.test.tsx | 79 ++- src/features/layout/tests/PostButton.test.tsx | 85 +++- .../layout/tests/ProfileSection.test.tsx | 30 ++ .../layout/tests/RightSidebar.test.tsx | 83 +++- .../layout/tests/WhatIsHappening.test.tsx | 49 ++ .../layout/tests/WhoToFollow.test.tsx | 36 ++ src/features/messages/api/messages.ts | 14 +- .../messages/components/MessagesLayout.tsx | 6 +- .../components/chatwindow/useChatWindow.ts | 14 +- .../conversationlist/useConversationsList.ts | 41 +- src/features/messages/hooks/useBlockStatus.ts | 5 - .../hooks/useConversationUnseenSync.ts | 5 +- .../hooks/useMarkDMNotificationsAsRead.ts | 21 - src/features/messages/hooks/useMessages.ts | 39 +- .../messages/hooks/useSyncDMNotifications.ts | 20 +- src/features/messages/services/socket.ts | 5 - .../tests/ConversationItemWithUnseen.test.tsx | 191 ++++++++ .../messages/tests/MessageItem.test.tsx | 179 +++++++ .../messages/tests/MessageMenu.test.tsx | 46 ++ src/features/messages/tests/api.test.ts | 68 ++- .../messages/tests/messageStore.test.ts | 359 ++++++++++++-- .../tests/useConversationsList.test.ts | 450 ++++++++++++++++++ .../messages/tests/useMessageItem.test.ts | 98 ++++ .../onboarding/hooks/useOnboarding.test.ts | 10 +- .../hooks/__tests__/profileQueries.test.ts | 5 +- src/types/ui.ts | 13 +- 35 files changed, 2154 insertions(+), 234 deletions(-) create mode 100644 src/features/layout/tests/EmptySpace.test.tsx create mode 100644 src/features/layout/tests/Footer.test.tsx create mode 100644 src/features/layout/tests/Logo.test.tsx create mode 100644 src/features/layout/tests/ProfileSection.test.tsx create mode 100644 src/features/layout/tests/WhatIsHappening.test.tsx create mode 100644 src/features/layout/tests/WhoToFollow.test.tsx create mode 100644 src/features/messages/tests/ConversationItemWithUnseen.test.tsx create mode 100644 src/features/messages/tests/MessageItem.test.tsx create mode 100644 src/features/messages/tests/MessageMenu.test.tsx create mode 100644 src/features/messages/tests/useConversationsList.test.ts create mode 100644 src/features/messages/tests/useMessageItem.test.ts diff --git a/.github/workflows/private-trigger.yml b/.github/workflows/private-trigger.yml index e9c7d147..c9081a14 100644 --- a/.github/workflows/private-trigger.yml +++ b/.github/workflows/private-trigger.yml @@ -55,8 +55,9 @@ jobs: continue-on-error: true - name: Build project - run: npm run build - # SonarQube scan - ONLY on push (not PR) + run: + npm run build + # SonarQube scan - ONLY on push (not PR) - name: SonarQube Scan if: github.event_name == 'push' uses: SonarSource/sonarqube-scan-action@v5.0.0 @@ -75,7 +76,7 @@ jobs: needs: test-and-build if: github.event_name != 'pull_request' runs-on: ubuntu-latest - steps: + steps: - name: Trigger public repo workflow run: | curl -X POST \ diff --git a/src/components/ui/forms/types.ts b/src/components/ui/forms/types.ts index ad428390..702ab89d 100644 --- a/src/components/ui/forms/types.ts +++ b/src/components/ui/forms/types.ts @@ -97,9 +97,7 @@ export interface FormHandlers { } export interface FormContainerProps - extends GenericAuthFormProps, - FormState, - FormHandlers { + extends GenericAuthFormProps, FormState, FormHandlers { displayMode: 'modal' | 'fullpage'; onClose?: () => void; className?: string; @@ -152,9 +150,7 @@ export interface SocialLoginSectionProps { } export interface FormContentProps - extends GenericAuthFormProps, - FormState, - FormHandlers { + extends GenericAuthFormProps, FormState, FormHandlers { onSwitchModal?: (newType: AuthModalType) => void; loading: boolean; isFormValid: boolean; diff --git a/src/components/ui/input/types.ts b/src/components/ui/input/types.ts index d9ad114a..a569f426 100644 --- a/src/components/ui/input/types.ts +++ b/src/components/ui/input/types.ts @@ -19,10 +19,9 @@ export interface CharCounterProps { maxLength: number; } -export interface InputBaseProps - extends React.HTMLAttributes< - HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement - > { +export interface InputBaseProps extends React.HTMLAttributes< + HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement +> { // loosened ref type to support both input and textarea refs inputRef?: React.Ref< HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement diff --git a/src/features/layout/tests/EmptySpace.test.tsx b/src/features/layout/tests/EmptySpace.test.tsx new file mode 100644 index 00000000..6b21b186 --- /dev/null +++ b/src/features/layout/tests/EmptySpace.test.tsx @@ -0,0 +1,25 @@ +import { describe, it, expect } from 'vitest'; +import { render } from '@/test/test-utils'; +import EmptySpace from '../components/EmptySpace'; + +describe('EmptySpace', () => { + it('should render without crashing', () => { + const { container } = render(); + + expect(container).toBeInTheDocument(); + }); + + it('should render a div element', () => { + const { container } = render(); + const emptySpace = container.firstChild; + + expect(emptySpace).toBeInTheDocument(); + }); + + it('should have appropriate spacing classes', () => { + const { container } = render(); + const emptySpace = container.firstChild as HTMLElement; + + expect(emptySpace.className).toBeTruthy(); + }); +}); diff --git a/src/features/layout/tests/Footer.test.tsx b/src/features/layout/tests/Footer.test.tsx new file mode 100644 index 00000000..8918ad23 --- /dev/null +++ b/src/features/layout/tests/Footer.test.tsx @@ -0,0 +1,37 @@ +import { describe, it, expect } from 'vitest'; +import { render, screen } from '@/test/test-utils'; +import Footer from '../components/Footer'; + +describe('Footer', () => { + it('should render footer content', () => { + const { container } = render(