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+ } )
0 commit comments