Skip to content

Commit

Permalink
Added search component
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed May 6, 2024
1 parent 4c2f8ab commit 2f92d73
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
35 changes: 21 additions & 14 deletions app/places/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from 'next/link'
import { getCountryCodes } from '../../src/api/country'
import { getPlacesData } from '../../src/api/place'
import { Search } from '../../src/views/search'
import styles from './places.module.css'

export const dynamic = 'force-dynamic'
Expand All @@ -11,18 +12,24 @@ export default async function PlacesPage() {
getPlacesData()
])

return places.map((place) => (
<div key={`place-${place.id}`} className={styles.uaplaces}>
<Link href={`places/${place.id}`}>
<span>{place.name}</span>
&nbsp;
<span>~</span>
&nbsp;
<span>
{place.city ? `${place.city} - ` : ``}
{countryCodes[place.iso]}
</span>
</Link>
</div>
))
return (
<>
<Search />

{places.map((place) => (
<div key={`place-${place.id}`} className={styles.uaplaces}>
<Link href={`places/${place.id}`}>
<span>{place.name}</span>
&nbsp;
<span>~</span>
&nbsp;
<span>
{place.city ? `${place.city} - ` : ``}
{countryCodes[place.iso]}
</span>
</Link>
</div>
))}
</>
)
}
1 change: 1 addition & 0 deletions src/views/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './search'
3 changes: 3 additions & 0 deletions src/views/search/search.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.uasearch {
margin-bottom: 20px;
}
11 changes: 11 additions & 0 deletions src/views/search/search.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render, screen } from '@testing-library/react'
import { describe, expect, test } from 'vitest'
import { Search } from './search'

describe('Views > Search', () => {
test('display input', () => {
render(<Search />)

expect(screen.getByRole('input')).toBeDefined()

Check failure on line 9 in src/views/search/search.test.tsx

View workflow job for this annotation

GitHub Actions / build (20.10.x)

src/views/search/search.test.tsx > Views > Search > display input

TestingLibraryElementError: Unable to find an accessible element with the role "input" Here are the accessible roles: textbox: Name "": <input /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <div class="_uasearch_780c74" > <form> <input /> </form> </div> </div> </body> ❯ Object.getElementError node_modules/@testing-library/dom/dist/config.js:37:19 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:76:38 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:52:17 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:95:19 ❯ src/views/search/search.test.tsx:9:19
})
})
15 changes: 15 additions & 0 deletions src/views/search/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { memo } from 'react'
import type { FC } from 'react'
import styles from './search.module.css'

export const Search: FC = memo(() => {
return (
<div className={styles.uasearch}>
<form>
<input />
</form>
</div>
)
})

Search.displayName = 'Search'

0 comments on commit 2f92d73

Please sign in to comment.