Skip to content

Commit 92f2dbb

Browse files
committed
Added tests for search filters
1 parent 1e71700 commit 92f2dbb

File tree

5 files changed

+116
-10
lines changed

5 files changed

+116
-10
lines changed

cypress.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
{
2-
"baseUrl": "http://localhost:3000"
2+
"baseUrl": "http://localhost:3000",
3+
"env": {
4+
"testUsername": "user1",
5+
"testUserEmail": "[email protected]",
6+
"testUserPassword": "password",
7+
"testStoryTitle": "This is a test story",
8+
"testStoryProduct": "EOS Icons",
9+
"testCategory": "Documentation"
10+
},
11+
"testFiles": [
12+
"user_story.spec.js",
13+
"test_filters.spec.js"
14+
]
315
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Test the filters and search for stories', () => {
4+
const testStory = {
5+
title: Cypress.env('testStoryTitle'),
6+
product: Cypress.env('testStoryProduct'),
7+
category: Cypress.env('testCategory')
8+
}
9+
10+
const setDropdown = (dropdown, value) => {
11+
cy
12+
.get('[data-cy=search-input-div]')
13+
.get(`[data-cy=${dropdown}-dropdown]`)
14+
.click()
15+
cy.contains(value).click({ force: true })
16+
}
17+
18+
const searchByTitle = (value) => {
19+
cy.get('[data-cy=search-input]').type(value)
20+
cy.get('[data-cy=btn-search]').click()
21+
}
22+
23+
const typeOnSearch = (value) => {
24+
cy.get('[data-cy=search-input]').type(value)
25+
}
26+
27+
const clearSearchInput = () => {
28+
cy.get('[data-cy=btn-clear]').click({ force: true })
29+
}
30+
31+
before(() => {
32+
cy.visit('/')
33+
})
34+
35+
it('Filters stories based on product', () => {
36+
setDropdown('product', 'EOS User Story')
37+
38+
cy.contains('No stories')
39+
40+
setDropdown('product', testStory.product)
41+
42+
cy.contains(testStory.title)
43+
})
44+
45+
it('Filters stories based on category', () => {
46+
setDropdown('category', 'Bug')
47+
48+
cy.contains('No stories')
49+
50+
setDropdown('category', testStory.category)
51+
52+
cy.contains(testStory.title)
53+
})
54+
55+
it('Searches stories based on title', () => {
56+
searchByTitle('random')
57+
58+
cy.contains('No stories')
59+
60+
clearSearchInput()
61+
62+
searchByTitle('test')
63+
64+
cy.contains(testStory.title)
65+
66+
clearSearchInput()
67+
})
68+
69+
it('Searches stories based on author', () => {
70+
setDropdown('toggle-title', 'Author')
71+
72+
typeOnSearch('un')
73+
cy.get('[data-cy=search-input-div]').contains('No users found')
74+
75+
clearSearchInput()
76+
77+
typeOnSearch('us')
78+
cy
79+
.get('[data-cy=search-input-div]')
80+
.contains('user1')
81+
.click({ force: true })
82+
83+
cy.contains(testStory.title)
84+
})
85+
})

cypress/integration/user_story.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
describe('Test new User Registration Workflow', () => {
44
const testUser = {
5-
username: 'user5',
6-
7-
password: 'password',
5+
username: Cypress.env('testUsername'),
6+
email: Cypress.env('testUserEmail'),
7+
password: Cypress.env('testUserPassword'),
88
}
99

1010
const testStory = {
11-
title: 'This is a test story',
12-
product: 'EOS Icons',
13-
category: 'Documentation',
11+
title: Cypress.env('testStoryTitle'),
12+
product: Cypress.env('testStoryProduct'),
13+
category: Cypress.env('testCategory'),
1414
priority: 'High',
1515
description: '{enter}Testing User Story',
1616
}

src/components/Dropdown.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useState, useEffect } from 'react'
33
import Button from './Button'
44

55
const Dropdown = (props) => {
6-
const { title, reference, curr, setCurr, itemList } = props
6+
const { title, reference, curr, setCurr, itemList, ...rest } = props
77

88
const [dropdownState, setDropdownState] = useState(false)
99

@@ -32,7 +32,7 @@ const Dropdown = (props) => {
3232
return (
3333
<>
3434
<div className='filter-title'>{title}</div>
35-
<div className='dropdown-container' ref={reference}>
35+
<div className='dropdown-container' ref={reference} {...rest}>
3636
<Button
3737
type='button'
3838
className='btn btn-transparent'

src/pages/Home.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ const Home = () => {
299299

300300
<div className='flex flex-row search-bar'>
301301
<div className='flex flex-row search-controls'>
302-
<div className='flex flex-row search-input'>
302+
<div
303+
className='flex flex-row search-input'
304+
data-cy='search-input-div'
305+
>
303306
<span>
304307
<i className='eos-icons'>search</i>
305308
</span>
@@ -317,6 +320,7 @@ const Home = () => {
317320
name='search'
318321
placeholder='Search'
319322
autoComplete='off'
323+
data-cy='search-input'
320324
value={fieldToSearch === 'Title' ? searchTerm : userTerm}
321325
onChange={(event) => {
322326
if (fieldToSearch === 'Title') {
@@ -340,6 +344,7 @@ const Home = () => {
340344
<div className='close-btn-div'>
341345
<span
342346
className='close-btn'
347+
data-cy='btn-clear'
343348
onClick={() => {
344349
if (fieldToSearch === 'Title' && searchTerm.length > 0) {
345350
setSearchTerm('')
@@ -360,11 +365,13 @@ const Home = () => {
360365
curr={fieldToSearch}
361366
setCurr={setFieldToSearch}
362367
itemList={['Title', 'Author']}
368+
data-cy='toggle-title-dropdown'
363369
/>
364370
</div>
365371
<Button
366372
type='submit'
367373
className='btn btn-default'
374+
data-cy='btn-search'
368375
onClick={handleSearchSubmit}
369376
>
370377
Search
@@ -377,13 +384,15 @@ const Home = () => {
377384
curr={product}
378385
setCurr={setProduct}
379386
itemList={products}
387+
data-cy='product-dropdown'
380388
/>
381389
<Dropdown
382390
title='Categories'
383391
reference={categoryDropdownContainer}
384392
curr={category}
385393
setCurr={setCategory}
386394
itemList={categories}
395+
data-cy='category-dropdown'
387396
/>
388397
<Dropdown
389398
title='Sort By'

0 commit comments

Comments
 (0)