From d3243f6c0562779088d2ad18f15a81957d8a1fe9 Mon Sep 17 00:00:00 2001 From: bitbard3 Date: Mon, 2 Dec 2024 09:15:33 +0530 Subject: [PATCH 1/2] Refactored src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx from Jest to Vitest #2493 --- ...st.tsx => ChangeLanguageDropdown.spec.tsx} | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) rename src/components/ChangeLanguageDropdown/{ChangeLanguageDropdown.test.tsx => ChangeLanguageDropdown.spec.tsx} (91%) diff --git a/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx b/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx similarity index 91% rename from src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx rename to src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx index dc14f6ce17..b0b26de160 100644 --- a/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx +++ b/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx @@ -1,4 +1,5 @@ -import React, { act } from 'react'; +import React from 'react'; +import { describe, test, expect } from 'vitest'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { I18nextProvider } from 'react-i18next'; @@ -16,10 +17,8 @@ import useLocalStorage from 'utils/useLocalstorage'; const { setItem } = useLocalStorage(); async function wait(ms = 100): Promise { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); + await new Promise((resolve) => { + setTimeout(resolve, ms); }); } @@ -51,6 +50,7 @@ const MOCKS = [ ]; const link = new StaticMockLink(MOCKS, true); + describe('Testing Change Language Dropdown', () => { test('Component Should be rendered properly', async () => { const { getByTestId } = render( @@ -71,7 +71,7 @@ describe('Testing Change Language Dropdown', () => { getByTestId('language-dropdown-btn').className.includes(''); getByTestId('dropdown-btn-0').className.includes(''); - userEvent.click(getByTestId('dropdown-btn-0')); + await userEvent.click(getByTestId('dropdown-btn-0')); await wait(); languages.map((language) => { @@ -136,23 +136,23 @@ describe('Testing Change Language Dropdown', () => { , ); - userEvent.click(getByTestId('language-dropdown-btn')); + await userEvent.click(getByTestId('language-dropdown-btn')); await wait(); const changeLanguageBtn = getByTestId(`change-language-btn-fr`); await wait(); expect(changeLanguageBtn).toBeInTheDocument(); await wait(); - userEvent.click(changeLanguageBtn); + await userEvent.click(changeLanguageBtn); await wait(); expect(cookies.get('i18next')).toBe('fr'); await wait(); - userEvent.click(getByTestId('language-dropdown-btn')); + await userEvent.click(getByTestId('language-dropdown-btn')); await wait(); const changeLanguageBtnHi = getByTestId(`change-language-btn-hi`); await wait(); expect(changeLanguageBtnHi).toBeInTheDocument(); await wait(); - userEvent.click(changeLanguageBtnHi); + await userEvent.click(changeLanguageBtnHi); await wait(); }); }); From 1b6d7a63fd8ad92005c6a16543d978a74c01a8de Mon Sep 17 00:00:00 2001 From: bitbard3 Date: Mon, 2 Dec 2024 09:43:43 +0530 Subject: [PATCH 2/2] Add ts-doc comment --- .../ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx b/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx index b0b26de160..c43970de1d 100644 --- a/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx +++ b/src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx @@ -1,3 +1,9 @@ +/** + * Unit tests for the ChangeLanguageDropdown component. + * + * This file contains tests for the ChangeLanguageDropdown component to ensure it behaves as expected + * under various scenarios. + */ import React from 'react'; import { describe, test, expect } from 'vitest'; import { render } from '@testing-library/react';