Skip to content

Commit

Permalink
test: add test for search
Browse files Browse the repository at this point in the history
  • Loading branch information
tjuandev committed May 26, 2024
1 parent 9c0ae6a commit d677282
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-comment": "off",
"no-console": "error",
"react/no-unescaped-entities": "off",
"react/jsx-filename-extension": [1, { "extensions": [".ts", ".tsx"] }],
"react/function-component-definition": [
"error",
Expand Down
19 changes: 17 additions & 2 deletions cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
describe('template spec', () => {
it('passes', () => {
class CategorySearch {
elements = {
peopleCategory: () => cy.get('[data-cy="category-people"]'),
searchInput: () => cy.get('[data-cy="search-input"]')
}
}

describe('Category Search', () => {
it('Should search for people category', () => {
cy.visit('/')
const categorySearch = new CategorySearch()
const { peopleCategory, searchInput } = categorySearch.elements

peopleCategory().click()
searchInput().type('Luke Skywalker').type('{enter}')

const expectedResult = cy.contains('Luke Skywalker')
expectedResult.should('be.visible')
})
})
1 change: 1 addition & 0 deletions src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Categories = () => {
title={title}
alt={`${title}'s image`}
href={`/categories/${title}`}
dataCy={`category-${title.toLowerCase()}`}
/>
))}
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/components/molecules/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const Card = ({
title,
imgHeight,
imgWidth,
href
href,
dataCy
}: CardProps) => (
<Link href={href} className={S.container}>
<Link href={href} className={S.container} data-cy={dataCy}>
<div className={S.card}>
<Image
src={src}
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/Card/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type CardProps = {
href: string
imgWidth?: number
imgHeight?: number
dataCy?: string
}
8 changes: 7 additions & 1 deletion src/components/molecules/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export const SearchBar = ({
className={S.input}
type="search"
placeholder={placeholder}
data-cy="search-input"
/>
<Button type="submit" attachPos="left" icon={<LightsaberIcon />}>
<Button
type="submit"
attachPos="left"
icon={<LightsaberIcon />}
data-cy="search-button"
>
Search
</Button>
</div>
Expand Down

0 comments on commit d677282

Please sign in to comment.