Skip to content

Commit

Permalink
Add i18next for SearchInputBox test
Browse files Browse the repository at this point in the history
  • Loading branch information
nhohb committed Sep 30, 2024
1 parent a08c3ef commit 334a046
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/@molecules/SearchInput/SearchInputBox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { fireEvent, render, screen } from '@testing-library/react'
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import { ThemeProvider } from 'styled-components'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { lightTheme } from '@ensdomains/thorin'

import { SearchInputBox } from './SearchInputBox'

// Initialize i18next for the tests
i18n.use(initReactI18next).init({
lng: 'en',
fallbackLng: 'en',
ns: ['translations'],
defaultNS: 'translations',
resources: { en: { translations: {} } },
})

describe('SearchInputBox', () => {
const mockSetInput = vi.fn()

Expand Down Expand Up @@ -38,19 +49,23 @@ describe('SearchInputBox', () => {

it('debounces input and calls setInput once after 500ms', async () => {
const { getByTestId } = renderComponent()
// Ensure the initial call is made
expect(mockSetInput).toHaveBeenCalledTimes(1)

const searchInput = getByTestId('search-input-box')

fireEvent.change(searchInput, { target: { value: 't' } })
await vi.advanceTimersByTime(100)
// Ensure setInput not called
expect(mockSetInput).toHaveBeenCalledTimes(1)

fireEvent.change(searchInput, { target: { value: 'test' } })
await vi.advanceTimersByTime(499)
// Ensure setInput not called
expect(mockSetInput).toHaveBeenCalledTimes(1)

await vi.advanceTimersByTime(1)
// Ensure setInput called
expect(mockSetInput).toHaveBeenCalledTimes(2)
expect(mockSetInput).toHaveBeenCalledWith('test')

Expand Down

0 comments on commit 334a046

Please sign in to comment.