From d213561fbff219d72fa043433e28e68b54e1468b Mon Sep 17 00:00:00 2001 From: prabhuignoto Date: Tue, 13 Feb 2024 15:00:01 +0530 Subject: [PATCH] fix unit test cases --- .../__tests__/layout-switcher.test.tsx | 100 +++++++++++------- .../timeline/timeline-popover-elements.tsx | 7 +- src/models/TimelineModel.ts | 2 + src/utils/index.ts | 2 + src/utils/utils.test.ts | 2 + 5 files changed, 73 insertions(+), 40 deletions(-) diff --git a/src/components/timeline/__tests__/layout-switcher.test.tsx b/src/components/timeline/__tests__/layout-switcher.test.tsx index 542afa60..81e9865d 100644 --- a/src/components/timeline/__tests__/layout-switcher.test.tsx +++ b/src/components/timeline/__tests__/layout-switcher.test.tsx @@ -1,5 +1,6 @@ import { fireEvent, render, waitFor } from '@testing-library/react'; -import { getDefaultThemeOrDark } from '@utils/index'; +import { getDefaultButtonTexts, getDefaultThemeOrDark } from '@utils/index'; +import GlobalContextProvider from 'src/components/GlobalContext'; import { vi } from 'vitest'; import { LayoutSwitcher, QuickJump } from '../timeline-popover-elements'; @@ -11,13 +12,18 @@ describe('LayoutSwitcher Component', () => { test('Renders correctly with vertical layout options', () => { const { getByText } = render( - , + buttonTexts={getDefaultButtonTexts()} + > + + , ); // Add your assertions here @@ -31,13 +37,18 @@ describe('LayoutSwitcher Component', () => { test('Renders correctly with horizontal layout options', () => { const { getByText } = render( - , + buttonTexts={getDefaultButtonTexts()} + > + + , ); // Add your assertions here @@ -51,13 +62,18 @@ describe('LayoutSwitcher Component', () => { test('Handles mode selection correctly', async () => { const { getByText } = render( - , + buttonTexts={getDefaultButtonTexts()} + > + + , ); expect(getByText('Change layout')).toBeInTheDocument(); @@ -87,21 +103,26 @@ describe('QuickJump Component', () => { test('Renders correctly with provided items', () => { const { getByText } = render( - , + buttonTexts={getDefaultButtonTexts()} + > + + , ); // Add your assertions here - expect(getByText('Jump to a date')).toBeInTheDocument(); + expect(getByText('Jump to')).toBeInTheDocument(); - fireEvent.click(getByText('Jump to a date')); + fireEvent.click(getByText('Jump to')); expect(getByText('Item 1')).toBeInTheDocument(); expect(getByText('Item 2')).toBeInTheDocument(); @@ -109,19 +130,24 @@ describe('QuickJump Component', () => { test('Handles item activation correctly', () => { const { getByText } = render( - , + buttonTexts={getDefaultButtonTexts()} + > + + , ); - expect(getByText('Jump to a date')).toBeInTheDocument(); + expect(getByText('Jump to')).toBeInTheDocument(); - fireEvent.click(getByText('Jump to a date')); + fireEvent.click(getByText('Jump to')); // Simulate clicking on an item fireEvent.click(getByText('Item 1')); diff --git a/src/components/timeline/timeline-popover-elements.tsx b/src/components/timeline/timeline-popover-elements.tsx index c005abe3..db819a7f 100644 --- a/src/components/timeline/timeline-popover-elements.tsx +++ b/src/components/timeline/timeline-popover-elements.tsx @@ -31,7 +31,7 @@ const LayoutSwitcher: FunctionComponent = ({ isDarkMode, position, }: LayoutSwitcherProp) => { - const { showAllCardsHorizontal } = useContext(GlobalContext); + const { showAllCardsHorizontal, buttonTexts } = useContext(GlobalContext); const activeTimelineMode = useMemo( () => mode, @@ -81,7 +81,7 @@ const LayoutSwitcher: FunctionComponent = ({ return ( = ({ isDarkMode, position, }: QuickJumpProp) => { + const {buttonTexts} = useContext(GlobalContext); return ( ({ }); export const getDefaultButtonTexts = () => ({ + changeLayout: 'Change layout', dark: 'Switch to Dark Mode', first: 'Go to First', + jumpTo: 'Jump to', last: 'Go to Last', light: 'Switch to Light Mode', next: 'Next', diff --git a/src/utils/utils.test.ts b/src/utils/utils.test.ts index 1ddd896f..c53e17c7 100644 --- a/src/utils/utils.test.ts +++ b/src/utils/utils.test.ts @@ -44,8 +44,10 @@ describe('Utility Functions', () => { it('getDefaultButtonTexts should return default button texts', () => { expect(getDefaultButtonTexts()).toEqual({ + changeLayout: 'Change layout', dark: 'Switch to Dark Mode', first: 'Go to First', + jumpTo: 'Jump to', last: 'Go to Last', light: 'Switch to Light Mode', next: 'Next',