From f7dc26068fa90a2c51c06fc5db84bb1b176a8022 Mon Sep 17 00:00:00 2001 From: danmondra Date: Mon, 11 Sep 2023 09:16:20 -0600 Subject: [PATCH] Add tests to --- .../src/components/ActionListButton.jsx | 2 +- .../src/tests/ActionListButton.test.jsx | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pruebas/01-reading-list/danmondra/src/tests/ActionListButton.test.jsx diff --git a/pruebas/01-reading-list/danmondra/src/components/ActionListButton.jsx b/pruebas/01-reading-list/danmondra/src/components/ActionListButton.jsx index f43262bcb..76f1dd226 100644 --- a/pruebas/01-reading-list/danmondra/src/components/ActionListButton.jsx +++ b/pruebas/01-reading-list/danmondra/src/components/ActionListButton.jsx @@ -3,7 +3,7 @@ import { ACTIONS_MSGS } from './BookNotification' const { IS_ALREADY_IN_LIST, ADD_TO_SPECIFIC_LIST, DELETE_FROM_LIST } = ACTIONS_MSGS -const TITLE_VARIANTS = { +export const TITLE_VARIANTS = { delete: (nameList) => `${DELETE_FROM_LIST} ${nameList}`, isAlready: (nameList) => `${IS_ALREADY_IN_LIST} "${nameList}"`, default: (nameList) => `${ADD_TO_SPECIFIC_LIST} "${nameList}"` diff --git a/pruebas/01-reading-list/danmondra/src/tests/ActionListButton.test.jsx b/pruebas/01-reading-list/danmondra/src/tests/ActionListButton.test.jsx new file mode 100644 index 000000000..75429789e --- /dev/null +++ b/pruebas/01-reading-list/danmondra/src/tests/ActionListButton.test.jsx @@ -0,0 +1,46 @@ +import { cleanup, fireEvent, render, waitFor } from '@testing-library/react' +import { afterEach, expect, it, vi } from 'vitest' + +import { ActionListButton, TITLE_VARIANTS } from '../components/ActionListButton.jsx' + +afterEach(cleanup) + +it('should render the with the default title', () => { + const { getByRole } = render( {}} Icon={() => null} />) + + const name = TITLE_VARIANTS?.default('') + getByRole('button', { name }) +}) + +it('should render the with the delete variant and the title to delete from the list', () => { + const listNameTest = 'LIST_TO_DELETE_TEST' + + const { getByRole } = render( + {}} + Icon={() => null} + variant='delete' + nameList={listNameTest} + /> + ) + + const name = TITLE_VARIANTS?.delete(listNameTest) + getByRole('button', { name }) +}) + +it('should execute the callback provided when is clicked', async () => { + const spy = vi.fn() + + const { getByRole } = render( + null} + /> + ) + + fireEvent.click(getByRole('button')) + + await waitFor(() => { + expect(spy).toHaveBeenCalledOnce() + }) +})