1
- describe ( 'Viewing Home page' , ( ) => {
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
3
+ let data = 'services/wares.json'
4
4
let error
5
- let featuredServices
6
5
7
6
beforeEach ( ( ) => {
8
- // Intercept the response from the endpoint to view all requests
9
7
cy . customApiIntercept ( {
10
- action : 'GET' ,
11
8
alias : 'useAllWares' ,
12
- requestURL : `/providers/${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_ID' ) } /wares.json` ,
13
- data : featuredServices ,
14
- defaultFixture : 'services/wares.json' ,
15
- emptyFixture : 'services/no-wares.json' ,
16
- loading,
17
- error
9
+ data,
10
+ error,
11
+ requestURL : '/wares.json?per_page=2000' ,
18
12
} )
13
+
19
14
cy . visit ( '/' )
20
15
} )
21
16
22
-
23
- context ( 'featured services list is loading' , ( ) => {
24
- before ( ( ) => {
25
- loading = true
17
+ describe ( 'renders a search bar' , ( ) => {
18
+ it ( 'with no query' , ( ) => {
19
+ cy . get ( "form[data-cy='search-bar']" ) . should ( 'exist' ) . then ( ( ) => {
20
+ cy . log ( 'Search bar renders successfully.' )
21
+ } )
26
22
} )
27
- it ( 'should show 3 placeholder cards loading' , ( ) => {
28
- cy . get ( 'p.placeholder-glow' ) . should ( 'be.visible' ) . then ( ( ) => {
29
- cy . log ( 'Loading text displays correctly.' )
23
+
24
+ context ( 'able to navigate to "/browse"' , ( ) => {
25
+ const testSetup = ( { data, defaultFixture, requestURL } ) => {
26
+ cy . customApiIntercept ( {
27
+ alias : 'useFilteredWares' ,
28
+ data,
29
+ error,
30
+ requestURL,
31
+ } )
32
+ }
33
+
34
+ it ( 'with a blank query' , ( ) => {
35
+ testSetup ( {
36
+ data : 'services/wares.json' ,
37
+ requestURL : '/wares.json?per_page=2000&q=' ,
38
+ } )
39
+
40
+ cy . get ( 'button.search-button' ) . click ( )
41
+ cy . url ( ) . should ( 'include' , '/browse' )
42
+ cy . url ( ) . should ( 'not.include' , '?' )
43
+ cy . get ( 'input.search-bar' ) . should ( 'have.value' , '' )
44
+ cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
45
+ } )
46
+
47
+ it ( 'with a valid query term' , ( ) => {
48
+ testSetup ( {
49
+ data : 'services/filtered-wares.json' ,
50
+ requestURL : `/wares.json?per_page=2000&q=${ Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) } ` ,
51
+ } )
52
+
53
+ cy . get ( 'input.search-bar' ) . type ( Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) )
54
+ cy . get ( 'button.search-button' ) . click ( )
55
+ cy . url ( ) . should ( 'include' , `/browse?q=${ Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) } ` )
56
+ cy . get ( 'input.search-bar' ) . should ( 'have.value' , Cypress . env ( 'CYPRESS_SEARCH_QUERY' ) )
57
+ cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
58
+ } )
59
+
60
+ it ( 'with an invalid query term' , ( ) => {
61
+ const invalidQuery = 'asdfghjk'
62
+ testSetup ( {
63
+ data : 'services/no-wares.json' ,
64
+ requestURL : `/wares.json?per_page=2000&q=${ invalidQuery } ` ,
65
+ } )
66
+
67
+ cy . get ( 'input.search-bar' ) . type ( invalidQuery )
68
+ cy . get ( 'button.search-button' ) . click ( )
69
+ cy . url ( ) . should ( 'include' , `/browse?q=${ invalidQuery } ` )
70
+ cy . get ( 'input.search-bar' ) . should ( 'have.value' , invalidQuery )
71
+ cy . get ( "p[data-cy='no-results']" ) . should ( 'contain' , `Your search for ${ invalidQuery } returned no results` )
30
72
} )
31
73
} )
32
74
} )
33
75
34
- context ( 'error while making a request to the api' , ( ) => {
35
- before ( ( ) => {
36
- loading = false
37
- error = true
38
- } )
39
- it ( 'should show an error message.' , ( ) => {
40
- cy . get ( "div[role='alert']" ) . should ( 'be.visible' ) . then ( ( ) => {
41
- cy . log ( 'Successfully hits an error.' )
76
+ describe ( 'renders a text box' , ( ) => {
77
+ it ( 'showing the about text.' , ( ) => {
78
+ cy . get ( "section[data-cy='about-us-section']" ) . should ( 'exist' ) . then ( ( ) => {
79
+ cy . log ( 'Abouttext renders successfully.' )
42
80
} )
43
81
} )
44
82
} )
45
83
46
- context ( 'home page components are loading successfully, &' , ( ) => {
47
- before ( ( ) => {
48
- featuredServices = true
49
- error = false
50
- } )
51
- it ( 'should show the search bar.' , ( ) => {
52
- cy . get ( "form[data-cy='search-bar']" ) . should ( 'exist' ) . then ( ( ) => {
53
- cy . log ( 'Search bar renders successfully.' )
84
+ describe ( 'makes a call to the api' , ( ) => {
85
+ context ( 'which when given an invalid access token' , ( ) => {
86
+ before ( ( ) => {
87
+ data = undefined
88
+ error = {
89
+ body : {
90
+ message : 'No access token provided.' ,
91
+ } ,
92
+ statusCode : 403 ,
93
+ }
94
+ } )
95
+
96
+ it ( 'shows an error message' , ( ) => {
97
+ cy . get ( "div[role='alert']" ) . should ( 'be.visible' ) . then ( ( ) => {
98
+ cy . log ( 'Successfully hits an error.' )
99
+ } )
100
+ cy . get ( "div[role='alert']" ) . contains ( 'No access token provided.' )
54
101
} )
55
102
} )
56
- it ( 'should show the about text.' , ( ) => {
57
- cy . get ( "section[data-cy='about-us-section']" ) . should ( 'exist' ) . then ( ( ) => {
58
- cy . log ( 'Abouttext renders successfully.' )
103
+
104
+ context ( 'which when returns no error or data' , ( ) => {
105
+ it ( 'shows 3 placeholder cards loading' , ( ) => {
106
+ cy . get ( 'p.placeholder-glow' ) . should ( 'have.length' , 3 ) . then ( ( ) => {
107
+ cy . log ( 'Loading text displays correctly.' )
108
+ } )
59
109
} )
60
110
} )
61
- it ( 'should show the featured services cards.' , ( ) => {
62
- cy . get ( "div[data-cy='item-group']" ) . should ( 'exist' ) . then ( ( ) => {
63
- cy . log ( 'Status bar renders successfully.' )
111
+
112
+ context ( 'which when returns data' , ( ) => {
113
+ it ( 'shows the featured services cards' , ( ) => {
114
+ cy . get ( "div[data-cy='item-group']" ) . should ( 'exist' ) . then ( ( ) => {
115
+ cy . log ( 'Status bar renders successfully.' )
116
+ } )
64
117
} )
65
118
} )
66
119
} )
67
- } )
120
+ } )
0 commit comments