1
1
describe ( 'Navigating to the home page' , ( ) => {
2
2
// declare variables that can be used to change how the response is intercepted.
3
- let loading
4
3
let error
5
4
let featuredServices
6
- let requestURL
7
- let data
5
+ let loading
8
6
9
7
beforeEach ( ( ) => {
10
8
cy . customApiIntercept ( {
11
9
action : 'GET' ,
12
10
alias : 'useAllWares' ,
13
- requestURL : `/wares.json?per_page=${ Cypress . env ( 'API_PER_PAGE' ) } ` ,
14
11
data : featuredServices ,
15
12
defaultFixture : 'services/wares.json' ,
16
13
emptyFixture : 'services/no-wares.json' ,
14
+ error,
17
15
loading,
18
- error
16
+ requestURL : `/wares.json?per_page= ${ Cypress . env ( 'API_PER_PAGE' ) } ` ,
19
17
} )
18
+
20
19
cy . visit ( '/' )
21
20
} )
22
21
@@ -28,20 +27,22 @@ describe('Navigating to the home page', () => {
28
27
} )
29
28
30
29
context ( 'able to navigate to "/browse"' , ( ) => {
31
- const testSetup = ( { data, requestURL } ) => {
30
+ const testSetup = ( { data, defaultFixture , requestURL } ) => {
32
31
cy . customApiIntercept ( {
33
32
action : 'GET' ,
34
33
alias : 'useFilteredWares' ,
35
- requestURL,
36
34
data,
37
- defaultFixture : 'services/wares.json' ,
35
+ defaultFixture,
36
+ emptyFixture : 'services/no-wares.json' ,
37
+ requestURL,
38
38
} )
39
39
}
40
40
41
41
it ( 'with a blank query' , ( ) => {
42
42
testSetup ( {
43
43
requestURL : `/wares.json?per_page=${ Cypress . env ( 'API_PER_PAGE' ) } &q=` ,
44
- data : true
44
+ data : true ,
45
+ defaultFixture : 'services/wares.json' ,
45
46
} )
46
47
47
48
cy . get ( 'button.search-button' ) . click ( )
@@ -51,20 +52,32 @@ describe('Navigating to the home page', () => {
51
52
cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
52
53
} )
53
54
54
- it ( 'able to navigate to "/browse" with a valid query term' , ( ) => {
55
+ it ( 'with a valid query term' , ( ) => {
56
+ testSetup ( {
57
+ requestURL : `/wares.json?per_page=${ Cypress . env ( 'API_PER_PAGE' ) } &q=${ Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) } ` ,
58
+ data : true ,
59
+ defaultFixture : 'services/filtered-wares.json' ,
60
+ } )
61
+
55
62
cy . get ( 'input.search-bar' ) . type ( Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) )
56
63
cy . get ( 'button.search-button' ) . click ( )
57
64
cy . url ( ) . should ( 'include' , `/browse?q=${ Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) } ` )
58
65
cy . get ( 'input.search-bar' ) . should ( 'have.value' , Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) )
59
66
cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
60
67
} )
61
68
62
- it ( 'able to navigate to "/browse" with an invalid query term' , ( ) => {
63
- cy . get ( 'input.search-bar' ) . type ( 'test' )
69
+ it ( 'with an invalid query term' , ( ) => {
70
+ const invalidQuery = 'asdfghjk'
71
+ testSetup ( {
72
+ requestURL : `/wares.json?per_page=${ Cypress . env ( 'API_PER_PAGE' ) } &q=${ invalidQuery } ` ,
73
+ } )
74
+
75
+ cy . get ( 'input.search-bar' ) . type ( invalidQuery )
64
76
cy . get ( 'button.search-button' ) . click ( )
65
- cy . url ( ) . should ( 'include' , '/browse?q=test' )
66
- cy . get ( 'input.search-bar' ) . should ( 'have.value' , 'test' )
67
- cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
77
+ cy . url ( ) . should ( 'include' , `/browse?q=${ invalidQuery } ` )
78
+ cy . get ( 'input.search-bar' ) . should ( 'have.value' , invalidQuery )
79
+ cy . get ( "p[data-cy='no-results']" ) . should ( 'contain' , `Your search for ${ invalidQuery } returned no results` )
80
+ } )
68
81
} )
69
82
} )
70
83
0 commit comments