Skip to content

Commit 335dadd

Browse files
authored
test(ShareSheet): verify navigator.share is called (JhaSourav07#760)
▶ Description Fixes JhaSourav07#739 This PR adds test coverage for the native OS sharing flow inside the `ShareSheet` component by mocking `navigator.share` and verifying it is triggered correctly when the **"Share via OS Sheet"** button is clicked. The native share sheet path is especially important for mobile devices, and this test ensures the integration remains stable and regression-safe. ▶ Changes Made ● Added a new unit test in: "txt components/dashboard/ShareSheet.test.tsx" ▶ Test coverage includes: - Mocking "navigator.share" using "vi.fn()" - Rendering the "ShareSheet" component - Simulating user interaction with the native share button - Verifying "navigator.share" is invoked - Verifying the payload contains: • title • text • url ▶ Pillar Testing / Quality Assurance ▶ Validation Successfully ran the complete Vitest test suite locally. ● Result: "txt Test Files 27 passed (27) Tests 353 passed (353)" No existing tests were broken. ▶ Why This Matters The OS share sheet flow is a mobile-critical feature. This test improves reliability by ensuring: * native sharing continues working correctly * payload structure remains consistent * future regressions are caught automatically ✅ Checklist [x] Added unit test for "navigator.share" [x] Verified correct payload structure [x] Followed existing test conventions [x] All tests passing [x] No unrelated files modified <img width="1920" height="1080" alt="Screenshot 2026-05-27 221308" src="https://github.com/user-attachments/assets/99d4e85c-644f-439d-8e4c-f6befa29a464" /> <img width="1920" height="1080" alt="Screenshot 2026-05-27 221344" src="https://github.com/user-attachments/assets/f49ba90c-596f-4ee7-9044-0ffe7d19b15b" />
2 parents f97751f + 934c92f commit 335dadd

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

components/dashboard/ShareSheet.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ describe('ShareSheet', () => {
163163
expect(defaultProps.onClose).toHaveBeenCalled();
164164
});
165165

166+
it('handles Share via OS Sheet action', async () => {
167+
const shareMock = vi.fn().mockResolvedValue(undefined);
168+
Object.assign(navigator, {
169+
share: shareMock,
170+
});
171+
render(<ShareSheet {...defaultProps} />);
172+
const shareButton = screen.getByText('Share via OS Sheet').closest('button');
173+
fireEvent.click(shareButton!);
174+
await waitFor(() => {
175+
expect(shareMock).toHaveBeenCalled();
176+
});
177+
178+
expect(shareMock).toHaveBeenCalledWith(
179+
expect.objectContaining({
180+
title: expect.any(String),
181+
text: expect.any(String),
182+
url: expect.any(String),
183+
})
184+
);
185+
});
186+
166187
it('handles Download PNG action', async () => {
167188
render(<ShareSheet {...defaultProps} />);
168189

0 commit comments

Comments
 (0)