Skip to content

Commit f270ff2

Browse files
committed
feat(e2e): add data-testids to search components
1 parent 1df8fc5 commit f270ff2

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

src/modules/search/components/hit/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ type HitProps = {
2121

2222
const Hit = ({ hit }: HitProps) => {
2323
return (
24-
<LocalizedClientLink href={`/products/${hit.handle}`}>
24+
<LocalizedClientLink
25+
href={`/products/${hit.handle}`}
26+
data-testid="search-result"
27+
>
2528
<Container
2629
key={hit.id}
2730
className="flex sm:flex-col gap-2 w-full p-4 shadow-elevation-card-rest hover:shadow-elevation-card-hover items-center sm:justify-center"
@@ -33,7 +36,12 @@ const Hit = ({ hit }: HitProps) => {
3336
/>
3437
<div className="flex flex-col justify-between group">
3538
<div className="flex flex-col">
36-
<Text className="text-ui-fg-subtle">{hit.title}</Text>
39+
<Text
40+
className="text-ui-fg-subtle"
41+
data-testid="search-result-title"
42+
>
43+
{hit.title}
44+
</Text>
3745
</div>
3846
</div>
3947
</Container>

src/modules/search/components/hits/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ const Hits = ({
3333
}
3434
)}
3535
>
36-
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4 mb-4">
36+
<div
37+
className="grid grid-cols-1 sm:grid-cols-3 gap-4 mb-4"
38+
data-testid="search-results"
39+
>
3740
{hits.slice(0, 6).map((hit, index) => (
3841
<li
3942
key={index}

src/modules/search/components/search-box/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const ControlledSearchBox = ({
4545
<div className="flex items-center justify-between">
4646
<input
4747
ref={inputRef}
48+
data-testid="search-input"
4849
autoComplete="off"
4950
autoCorrect="off"
5051
autoCapitalize="off"

src/modules/search/components/show-all/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const ShowAll = () => {
1313

1414
if (hits.length === 0) {
1515
return (
16-
<Container className="flex gap-2 justify-center h-fit py-2">
16+
<Container
17+
className="flex gap-2 justify-center h-fit py-2"
18+
data-testid="no-search-results-container"
19+
>
1720
<Text>No results found.</Text>
1821
</Container>
1922
)

src/modules/search/templates/search-modal/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export default function SearchModal() {
6363
indexName={SEARCH_INDEX_NAME}
6464
searchClient={searchClient}
6565
>
66-
<div className="flex absolute flex-col h-fit w-full sm:w-fit">
66+
<div
67+
className="flex absolute flex-col h-fit w-full sm:w-fit"
68+
data-testid="search-modal-container"
69+
>
6770
<div className="w-full flex items-center gap-x-2 p-4 bg-[rgba(3,7,18,0.5)] text-ui-fg-on-color backdrop-blur-2xl rounded-rounded">
6871
<MagnifyingGlassMini />
6972
<SearchBox />

0 commit comments

Comments
 (0)