@@ -37,20 +37,41 @@ describe('Browsing', () => {
37
37
let wares
38
38
let loading
39
39
let error
40
- let query = ''
40
+ let intercepts = [
41
+ {
42
+ alias : 'useAllWares' ,
43
+ } ,
44
+ {
45
+ alias : 'useFilteredWares - blank search' ,
46
+ } ,
47
+ {
48
+ alias : 'useFilteredWares - with results' ,
49
+ query : 'test' ,
50
+ } ,
51
+ {
52
+ alias : 'useFilteredWares - no results' ,
53
+ query : 'asdfghjk' ,
54
+ emptyFixture : 'services/no-wares.json' ,
55
+ } ,
56
+ ]
41
57
42
58
describe ( 'from the /browse page' , ( ) => {
43
59
beforeEach ( ( ) => {
44
- // Intercept the response from the endpoint to view all requests
45
- cy . customApiIntercept ( {
46
- action : 'GET' ,
47
- alias : 'useFilteredWares' ,
48
- requestURL : `/providers/${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_ID' ) } /wares.json?q=${ query } ` ,
49
- data : wares ,
50
- defaultFixture : 'services/wares.json' ,
51
- emptyFixture : 'services/no-wares.json' ,
52
- loading,
53
- error
60
+ // Intercept the responses from the endpoint to view all requests.
61
+ // Even though this is to the same endpoint, the call happens on the page twice,
62
+ // once when the page loads with all the wares, and again after any search is performed.
63
+ // this makes it necessary to create an intercept for each time the call is made.
64
+ intercepts . forEach ( ( intercept ) => {
65
+ cy . customApiIntercept ( {
66
+ action : 'GET' ,
67
+ alias : intercept . alias ,
68
+ requestURL : `/providers/${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_ID' ) } /wares.json?q=${ intercept . query || '' } ` ,
69
+ data : wares ,
70
+ defaultFixture : 'services/wares.json' ,
71
+ emptyFixture : intercept . emptyFixture || '' ,
72
+ loading,
73
+ error
74
+ } )
54
75
} )
55
76
cy . visit ( '/browse' )
56
77
} )
@@ -80,7 +101,7 @@ describe('Browsing', () => {
80
101
81
102
// filtering by query is handled in the api and not the webstore
82
103
// since we are stubbing that response, our tests will not return actual filtered wares based on on test query.
83
- // the purpose of these tests is just that the correct components appear in the UI in each case.
104
+ // the purpose of these tests is just to show that the correct components appear in the UI in each case.
84
105
context ( 'a search is completed successfully from the browse page' , ( ) => {
85
106
before ( ( ) => {
86
107
wares = true
@@ -89,53 +110,45 @@ describe('Browsing', () => {
89
110
it ( 'completes a search with a blank query' , ( ) => {
90
111
// Find the search button and perform an empty search, which should lead to the browse page
91
112
cy . get ( 'button.search-button' ) . click ( )
92
-
93
113
// The new url should include "/browse"
94
114
cy . url ( ) . should ( 'include' , '/browse' )
95
-
96
115
// The new url should not contain a query
97
116
cy . url ( ) . should ( 'not.include' , '?' )
98
-
99
117
// The search bar on the browse page should remain blank
100
118
cy . get ( 'input.search-bar' ) . should ( 'have.value' , '' )
119
+ // The service card component should be visible
120
+ cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
101
121
} )
102
122
103
123
before ( ( ) => {
104
124
wares = true
105
- query = 'test'
106
125
} )
107
126
it ( 'completes a search with a query term' , ( ) => {
108
- // type an example search into the searchbar
127
+ // Type an example search into the searchbar
109
128
cy . get ( 'input.search-bar' ) . type ( 'test' )
110
-
111
129
// Press the search button
112
130
cy . get ( 'button.search-button' ) . click ( )
113
-
114
- // The new url should include "/browse"
131
+ // The new url should include "/browse" as well as the query
115
132
cy . url ( ) . should ( 'include' , '/browse?q=test' )
116
-
117
133
// The search bar on the browse page should have the text that was searched for
118
134
cy . get ( 'input.search-bar' ) . should ( 'have.value' , 'test' )
119
-
135
+ // The service card component should be visible
120
136
cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
121
137
} )
122
138
123
139
before ( ( ) => {
124
- wares = true
125
- query = 'asdfghjk'
140
+ wares = false
126
141
} )
127
142
it ( 'completes a search with a query term, but has no results' , ( ) => {
128
143
// type an example search into the searchbar
129
144
cy . get ( 'input.search-bar' ) . type ( 'asdfghjk' )
130
-
131
145
// Press the search button
132
146
cy . get ( 'button.search-button' ) . click ( )
133
-
134
147
// The new url should include "/browse"
135
148
cy . url ( ) . should ( 'include' , '/browse?q=asdfghjk' )
136
-
137
149
// The search bar on the browse page should have the text that was searched for
138
150
cy . get ( 'input.search-bar' ) . should ( 'have.value' , 'asdfghjk' )
151
+ // The message showing that there are no results should show
139
152
} )
140
153
} )
141
154
} )
0 commit comments