Skip to content

Commit

Permalink
Update IntroText.test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Apr 13, 2024
1 parent 47a4233 commit 4d000b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions frontend/test/IntroText.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { afterEach, beforeAll, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'
import Search from '@pages/search'
import SearchProvider from '@contexts/SearchContext'

import CopyFixture from './fixtures/Copy.json'
import IntroFixture from './fixtures/Intro.json'

beforeAll(() => {
vi.mock('next/config', () => ({
Expand All @@ -22,22 +23,26 @@ it('removes the intro text on submitting a search query', async () => {
window.innerWidth = 390
window.innerHeight = 844

const screen = render(<Search swrFallback={{}} />)
const screen = render(
<SearchProvider initialQuery="">
<Search swrFallback={{}} />
</SearchProvider>,
)
const searchInput = screen.getAllByPlaceholderText(
'Search for projects',
)[0] as HTMLInputElement

const copy = screen.getByText(CopyFixture.CopyText)
const copy = screen.getByText(IntroFixture.Text)
// The copy should be visible
expect(copy).toBeTruthy()

//Submit a search query
fireEvent.change(searchInput, { target: { value: 'de' } })
fireEvent.change(searchInput, { target: { value: 'foo' } })
fireEvent.submit(searchInput)

// The copy should be removed
await waitFor(() => {
expect(screen.queryByText(CopyFixture.CopyText)).toBeFalsy()
expect(screen.queryByText(IntroFixture.Text)).toBeFalsy()
})
})

Expand Down
3 changes: 0 additions & 3 deletions frontend/test/fixtures/Copy.json

This file was deleted.

3 changes: 3 additions & 0 deletions frontend/test/fixtures/Intro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Text": "Kitspace is a place to share ready-to-order electronics designs. We automate parts purchasing so you can focus on building."
}

0 comments on commit 4d000b0

Please sign in to comment.