From 80db0c39b2cf1b93f512290f3048ddcd65c1d2f6 Mon Sep 17 00:00:00 2001 From: Shubham Oulkar Date: Fri, 25 Jul 2025 13:06:43 +0530 Subject: [PATCH 1/3] set min 70% test coverage target --- codecov.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index 35cde5cd5e854..b66d2baa7c2f6 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,4 +1,11 @@ coverage: status: - project: off - patch: off + patch: + default: + target: 70% + threshold: 1% + +comment: + behavior: default + require_changes: true + \ No newline at end of file From 147e613b85211e5ac4c68f08691a82cca4de7ff2 Mon Sep 17 00:00:00 2001 From: Shubham Oulkar Date: Fri, 25 Jul 2025 13:07:33 +0530 Subject: [PATCH 2/3] test(hook): useCopyToClipboard --- .../__tests__/useCopyToClipboard.test.jsx | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/apps/site/hooks/react-client/__tests__/useCopyToClipboard.test.jsx b/apps/site/hooks/react-client/__tests__/useCopyToClipboard.test.jsx index 5bb64c54c7592..89fae6fe49b2e 100644 --- a/apps/site/hooks/react-client/__tests__/useCopyToClipboard.test.jsx +++ b/apps/site/hooks/react-client/__tests__/useCopyToClipboard.test.jsx @@ -1,4 +1,4 @@ -import { describe, it } from 'node:test'; +import { describe, it, beforeEach } from 'node:test'; import assert from 'node:assert/strict'; import { setTimeout } from 'node:timers/promises'; @@ -9,10 +9,10 @@ import useCopyToClipboard from '#site/hooks/react-client/useCopyToClipboard'; navigator.clipboard = { writeText: () => {} }; await describe('useCopyToClipboard', async () => { - await it('should call clipboard API with `test` once', async t => { - t.mock.method(navigator.clipboard, 'writeText', () => Promise.resolve()); + let TestComponent; - const TestComponent = ({ textToCopy }) => { + beforeEach(() => { + TestComponent = ({ textToCopy }) => { const [copied, copyText] = useCopyToClipboard(); return ( @@ -21,6 +21,10 @@ await describe('useCopyToClipboard', async () => { ); }; + }); + + await it('should call clipboard API with `test` once', async t => { + t.mock.method(navigator.clipboard, 'writeText', () => Promise.resolve()); render(); @@ -40,4 +44,29 @@ await describe('useCopyToClipboard', async () => { 'test', ]); }); + + await it('should handle clipboard write text failure', async t => { + t.mock.method(navigator.clipboard, 'writeText', () => Promise.reject(new Error("fail"))); + + render(); + const button = screen.getByRole('button'); + + fireEvent.click(button); + assert.ok((await screen.findByText(/copy/i))); + + assert.equal(navigator.clipboard.writeText.mock.callCount(), 1); + assert.deepEqual(navigator.clipboard.writeText.mock.calls[0].arguments, [ + 'fail', + ]); + }); + + await it('should not call clipboard API when text is undefined', async t => { + t.mock.method(navigator.clipboard, 'writeText', () => Promise.resolve()); + + render(); + const button = screen.getByRole('button'); + fireEvent.click(button); + + assert.equal(navigator.clipboard.writeText.mock.callCount(), 0); + }); }); From d7f7f53b4898b3e3f9f650d016e5813a8f3b08f3 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Fri, 25 Jul 2025 16:37:47 +0530 Subject: [PATCH 3/3] Set 70% target on project Co-authored-by: Aviv Keller Signed-off-by: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> --- codecov.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/codecov.yml b/codecov.yml index b66d2baa7c2f6..401d836ecb2ef 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,11 +1,6 @@ coverage: status: - patch: + patch: off + project: default: target: 70% - threshold: 1% - -comment: - behavior: default - require_changes: true - \ No newline at end of file