From fd676f25efbd254995f8305ad217f8bd5912851f Mon Sep 17 00:00:00 2001 From: Julia Kartasheva Date: Mon, 13 Oct 2025 14:15:39 -0700 Subject: [PATCH 1/2] adding unit tests for content card components --- packages/messaging/jest.config.js | 10 +- .../src/ui/components/Button/Button.spec.tsx | 23 +- .../ContentCardContainer.spec.tsx | 162 ++++++++++--- .../ContentCardContainer.tsx | 2 + .../ContentCardView/ContentCardView.spec.tsx | 224 ++++++++++++++++++ .../components/Pagination/Pagination.spec.tsx | 159 +++++++++++++ .../components/UnreadIcon/UnreadIcon.spec.tsx | 129 +++++++++- 7 files changed, 672 insertions(+), 37 deletions(-) create mode 100644 packages/messaging/src/ui/components/ContentCardView/ContentCardView.spec.tsx create mode 100644 packages/messaging/src/ui/components/Pagination/Pagination.spec.tsx diff --git a/packages/messaging/jest.config.js b/packages/messaging/jest.config.js index 6d8993ba..08b225d8 100644 --- a/packages/messaging/jest.config.js +++ b/packages/messaging/jest.config.js @@ -1,4 +1,12 @@ module.exports = { preset: "react-native", testMatch: ["/src/ui/**/*.spec.tsx"], -}; + collectCoverage: true, + collectCoverageFrom: [ + "/src/ui/components/**/*.{ts,tsx}", // only components + "!**/*.spec.tsx", + "!**/__tests__/**", + ], + coverageReporters: ["text", "text-summary", "html", "lcov"], + coverageDirectory: "/coverage", +}; \ No newline at end of file diff --git a/packages/messaging/src/ui/components/Button/Button.spec.tsx b/packages/messaging/src/ui/components/Button/Button.spec.tsx index 8639e323..82382ba2 100644 --- a/packages/messaging/src/ui/components/Button/Button.spec.tsx +++ b/packages/messaging/src/ui/components/Button/Button.spec.tsx @@ -9,11 +9,11 @@ ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +import { fireEvent, render, screen } from '@testing-library/react-native'; import React from 'react'; -import { render, screen, fireEvent } from '@testing-library/react-native'; import { Linking } from 'react-native'; -import Button from './Button'; import { ThemeProvider } from '../../theme/ThemeProvider'; +import Button from './Button'; // Mock Linking.openURL jest.spyOn(Linking, 'openURL'); @@ -157,6 +157,25 @@ describe('Button', () => { expect(Linking.openURL).toHaveBeenCalledWith(testUrl); }); + it('should warn if openURL throws', () => { + const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); + const testUrl = 'https://example.com'; + (Linking.openURL as unknown as jest.Mock).mockImplementationOnce(() => { + throw new Error('open failed'); + }); + + render(