From b414659934019bbd0eeebd9569fb288cc7788cf2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 21:36:00 +0000 Subject: [PATCH 1/4] Initial plan From 193e06e45abda7ede7da0dfa8f7b0417905c8d32 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 21:39:08 +0000 Subject: [PATCH 2/4] test(clipboard): cover confirmPaste use case Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com> Agent-Logs-Url: https://github.com/marcuscastelo/macroflows/sessions/f300a3f2-84e4-41f8-8474-fe0ef356c507 --- .../usecases/tests/clipboardUseCases.test.ts | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts diff --git a/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts b/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts new file mode 100644 index 000000000..3824ee156 --- /dev/null +++ b/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts @@ -0,0 +1,128 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +vi.mock('~/modules/clipboard/ui/PasteConfirmModal', () => ({ + openPasteConfirmModal: vi.fn(), +})) + +import { createClipboardStore } from '~/modules/clipboard/application/store/clipboardStore' +import { createClipboardUseCases } from '~/modules/clipboard/application/usecases/clipboardUseCases' +import { openPasteConfirmModal } from '~/modules/clipboard/ui/PasteConfirmModal' +import { createMacroNutrients } from '~/modules/diet/macro-nutrients/domain/macroNutrients' +import { createItem, itemSchema } from '~/modules/diet/item/schema/itemSchema' + +describe('clipboardUseCases.confirmPaste', () => { + const showError = vi.fn() + + beforeEach(() => { + vi.clearAllMocks() + }) + + function createValidItemPayload() { + return createItem({ + id: 1, + name: 'Banana', + quantity: 100, + reference: { + type: 'food', + id: 1, + macros: createMacroNutrients({ + proteinInGrams: 1.2, + carbsInGrams: 22.8, + fatInGrams: 0.3, + }), + }, + }) + } + + it('opens the paste confirmation modal with the parsed payload', () => { + const clipboardStore = createClipboardStore() + const payload = createValidItemPayload() + const onPasteConfirmed = vi.fn() + const useCases = createClipboardUseCases({ + clipboardStore, + showError, + }) + + clipboardStore.copy(payload) + + useCases.confirmPaste(itemSchema, onPasteConfirmed) + + expect(openPasteConfirmModal).toHaveBeenCalledTimes(1) + expect(openPasteConfirmModal).toHaveBeenCalledWith(payload, onPasteConfirmed) + expect(showError).not.toHaveBeenCalled() + }) + + it('passes the confirmed payload to the paste handler on valid clipboard data', () => { + const clipboardStore = createClipboardStore() + const payload = createValidItemPayload() + const onPasteConfirmed = vi.fn() + const useCases = createClipboardUseCases({ + clipboardStore, + showError, + }) + + clipboardStore.copy(payload) + + useCases.confirmPaste(itemSchema, onPasteConfirmed) + + const modalHandler = vi.mocked(openPasteConfirmModal).mock.calls[0]?.[1] + + expect(modalHandler).toBeDefined() + + modalHandler?.(payload) + + expect(onPasteConfirmed).toHaveBeenCalledTimes(1) + expect(onPasteConfirmed).toHaveBeenCalledWith(payload) + }) + + it('shows an error and does not open the modal when the clipboard is empty', () => { + const clipboardStore = createClipboardStore() + const onPasteConfirmed = vi.fn() + const useCases = createClipboardUseCases({ + clipboardStore, + showError, + }) + + useCases.confirmPaste(itemSchema, onPasteConfirmed) + + expect(openPasteConfirmModal).not.toHaveBeenCalled() + expect(onPasteConfirmed).not.toHaveBeenCalled() + expect(showError).toHaveBeenCalledTimes(1) + expect(showError).toHaveBeenCalledWith( + 'A área de transferência está vazia ou o conteúdo é inválido.', + ) + }) + + it('shows validation errors and does not open the modal when clipboard data is incompatible', () => { + const clipboardStore = createClipboardStore() + const onPasteConfirmed = vi.fn() + const useCases = createClipboardUseCases({ + clipboardStore, + showError, + }) + + clipboardStore.copy({ + id: 999, + name: 'Broken clipboard payload', + quantity: 1, + reference: { + type: 'food', + id: 1, + }, + } as unknown as Parameters[0]) + + useCases.confirmPaste(itemSchema, onPasteConfirmed) + + expect(openPasteConfirmModal).not.toHaveBeenCalled() + expect(onPasteConfirmed).not.toHaveBeenCalled() + expect(showError).toHaveBeenCalledTimes(2) + expect(showError).toHaveBeenNthCalledWith( + 1, + 'O conteúdo da área de transferência não é compatível.', + ) + expect(showError).toHaveBeenNthCalledWith( + 2, + 'A área de transferência está vazia ou o conteúdo é inválido.', + ) + }) +}) From b997d2174fde0bae7f3ce32e839f45abe9d8054f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 21:42:23 +0000 Subject: [PATCH 3/4] test(clipboard): finalize confirmPaste coverage Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com> Agent-Logs-Url: https://github.com/marcuscastelo/macroflows/sessions/f300a3f2-84e4-41f8-8474-fe0ef356c507 --- .../usecases/tests/clipboardUseCases.test.ts | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts b/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts index 3824ee156..5bc7b946f 100644 --- a/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts +++ b/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts @@ -7,8 +7,9 @@ vi.mock('~/modules/clipboard/ui/PasteConfirmModal', () => ({ import { createClipboardStore } from '~/modules/clipboard/application/store/clipboardStore' import { createClipboardUseCases } from '~/modules/clipboard/application/usecases/clipboardUseCases' import { openPasteConfirmModal } from '~/modules/clipboard/ui/PasteConfirmModal' -import { createMacroNutrients } from '~/modules/diet/macro-nutrients/domain/macroNutrients' import { createItem, itemSchema } from '~/modules/diet/item/schema/itemSchema' +import { createMacroNutrients } from '~/modules/diet/macro-nutrients/domain/macroNutrients' +import { createNewMeal, promoteMeal } from '~/modules/diet/meal/domain/meal' describe('clipboardUseCases.confirmPaste', () => { const showError = vi.fn() @@ -48,7 +49,10 @@ describe('clipboardUseCases.confirmPaste', () => { useCases.confirmPaste(itemSchema, onPasteConfirmed) expect(openPasteConfirmModal).toHaveBeenCalledTimes(1) - expect(openPasteConfirmModal).toHaveBeenCalledWith(payload, onPasteConfirmed) + expect(openPasteConfirmModal).toHaveBeenCalledWith( + payload, + onPasteConfirmed, + ) expect(showError).not.toHaveBeenCalled() }) @@ -101,15 +105,14 @@ describe('clipboardUseCases.confirmPaste', () => { showError, }) - clipboardStore.copy({ - id: 999, - name: 'Broken clipboard payload', - quantity: 1, - reference: { - type: 'food', - id: 1, - }, - } as unknown as Parameters[0]) + clipboardStore.copy( + promoteMeal( + createNewMeal({ name: 'Meal clipboard payload', items: [] }), + { + id: 999, + }, + ), + ) useCases.confirmPaste(itemSchema, onPasteConfirmed) From dbb3db3c76cde6b433e29c86ec94aadd071e6e93 Mon Sep 17 00:00:00 2001 From: marcuscastelo Date: Tue, 24 Mar 2026 21:42:33 -0300 Subject: [PATCH 4/4] chore(pr): apply PR #1473 suggestions --- .../usecases/tests/clipboardUseCases.test.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts b/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts index 5bc7b946f..051ceb618 100644 --- a/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts +++ b/src/modules/clipboard/application/usecases/tests/clipboardUseCases.test.ts @@ -10,6 +10,7 @@ import { openPasteConfirmModal } from '~/modules/clipboard/ui/PasteConfirmModal' import { createItem, itemSchema } from '~/modules/diet/item/schema/itemSchema' import { createMacroNutrients } from '~/modules/diet/macro-nutrients/domain/macroNutrients' import { createNewMeal, promoteMeal } from '~/modules/diet/meal/domain/meal' +import { parseWithStack } from '~/shared/utils/parseWithStack' describe('clipboardUseCases.confirmPaste', () => { const showError = vi.fn() @@ -38,6 +39,7 @@ describe('clipboardUseCases.confirmPaste', () => { it('opens the paste confirmation modal with the parsed payload', () => { const clipboardStore = createClipboardStore() const payload = createValidItemPayload() + const parsedPayload = parseWithStack(itemSchema, payload) const onPasteConfirmed = vi.fn() const useCases = createClipboardUseCases({ clipboardStore, @@ -50,7 +52,7 @@ describe('clipboardUseCases.confirmPaste', () => { expect(openPasteConfirmModal).toHaveBeenCalledTimes(1) expect(openPasteConfirmModal).toHaveBeenCalledWith( - payload, + parsedPayload, onPasteConfirmed, ) expect(showError).not.toHaveBeenCalled() @@ -69,14 +71,19 @@ describe('clipboardUseCases.confirmPaste', () => { useCases.confirmPaste(itemSchema, onPasteConfirmed) - const modalHandler = vi.mocked(openPasteConfirmModal).mock.calls[0]?.[1] + const modalCall = vi.mocked(openPasteConfirmModal).mock.calls[0] - expect(modalHandler).toBeDefined() + expect(modalCall).toBeDefined() + if (!modalCall) { + throw new Error('Expected openPasteConfirmModal to be called') + } - modalHandler?.(payload) + const [modalPayload, modalHandler] = modalCall + + modalHandler(modalPayload) expect(onPasteConfirmed).toHaveBeenCalledTimes(1) - expect(onPasteConfirmed).toHaveBeenCalledWith(payload) + expect(onPasteConfirmed).toHaveBeenCalledWith(modalPayload) }) it('shows an error and does not open the modal when the clipboard is empty', () => {