1
1
describe ( 'Browsing' , ( ) => {
2
- // will need to use the intercepts/fixtures from home page test here
3
- // it('completes a search from the home page and navigates to "/browse" with a blank query', () => {
4
- // // Start from the home/index page
5
- // cy.visit('/')
6
-
7
- // // Find the search button and perform an empty search, which should lead to the browse page
8
- // cy.get('button.search-button').click()
9
-
10
- // // The new url should include "/browse"
11
- // cy.url().should('include', '/browse')
12
-
13
- // // The new url should not contain a query
14
- // cy.url().should('not.include', '?')
15
-
16
- // // The search bar on the browse page should remain blank
17
- // cy.get('input.search-bar').should('have.value', '')
18
- // })
19
-
20
- // it('completes a search from the home page and navigates to "/browse" with a query term', () => {
21
- // // Start from the home/index page
22
- // cy.visit('/')
23
-
24
- // // type an example search into the searchbar
25
- // cy.get('input.search-bar').type('next')
26
-
27
- // // Press the search button
28
- // cy.get('button.search-button').click()
29
-
30
- // // The new url should include "/browse"
31
- // cy.url().should('include', '/browse?q=next')
32
-
33
- // // The search bar on the browse page should have the text that was searched for
34
- // cy.get('input.search-bar').should('have.value', 'next')
35
- // })
36
-
37
2
let wares
38
3
let loading
39
4
let error
40
5
let intercepts = [
41
6
{
42
- alias : 'useAllWares ' ,
7
+ alias : 'useFilteredWares ' ,
43
8
} ,
44
9
{
45
10
alias : 'useFilteredWares - blank search' ,
@@ -54,25 +19,27 @@ describe('Browsing', () => {
54
19
emptyFixture : 'services/no-wares.json' ,
55
20
} ,
56
21
]
57
-
58
- describe ( 'from the /browse page' , ( ) => {
59
- beforeEach ( ( ) => {
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
- } )
22
+ beforeEach ( ( ) => {
23
+ // Intercept the responses from the endpoint to view all requests.
24
+ // Even though this is to the same endpoint, the call happens on each page twice,
25
+ // once when the page loads with all the wares, and again after any search is performed.
26
+ // this makes it necessary to create an intercept for each time the call is made.
27
+ intercepts . forEach ( ( intercept ) => {
28
+ cy . customApiIntercept ( {
29
+ action : 'GET' ,
30
+ alias : intercept . alias ,
31
+ requestURL : `/providers/${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_ID' ) } /wares.json?q=${ intercept . query || '' } ` ,
32
+ data : wares ,
33
+ defaultFixture : 'services/wares.json' ,
34
+ emptyFixture : intercept . emptyFixture || '' ,
35
+ loading,
36
+ error
75
37
} )
38
+ } )
39
+ } )
40
+
41
+ describe ( 'from the browse page' , ( ) => {
42
+ beforeEach ( ( ) => {
76
43
cy . visit ( '/browse' )
77
44
} )
78
45
@@ -120,9 +87,6 @@ describe('Browsing', () => {
120
87
cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
121
88
} )
122
89
123
- before ( ( ) => {
124
- wares = true
125
- } )
126
90
it ( 'completes a search with a query term' , ( ) => {
127
91
// Type an example search into the searchbar
128
92
cy . get ( 'input.search-bar' ) . type ( 'test' )
@@ -149,7 +113,51 @@ describe('Browsing', () => {
149
113
// The search bar on the browse page should have the text that was searched for
150
114
cy . get ( 'input.search-bar' ) . should ( 'have.value' , 'asdfghjk' )
151
115
// The message showing that there are no results should show
116
+ cy . get ( "p[data-cy='no-results']" ) . should ( 'contain' , 'Your search for asdfghjk returned no results' )
152
117
} )
153
118
} )
154
119
} )
120
+
121
+ describe ( 'from the home page' , ( ) => {
122
+ beforeEach ( ( ) => {
123
+ wares = true
124
+ // Intercept the api call being made on the homepage
125
+ cy . customApiIntercept ( {
126
+ action : 'GET' ,
127
+ alias : 'useAllWares' ,
128
+ requestURL : `/providers/${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_ID' ) } /wares.json` ,
129
+ data : wares ,
130
+ defaultFixture : 'services/wares.json' ,
131
+ loading,
132
+ error
133
+ } )
134
+ cy . visit ( '/' )
135
+ } )
136
+
137
+ it ( 'completes a search from the home page and navigates to "/browse" with a blank query' , ( ) => {
138
+ // Find the search button and perform an empty search, which should lead to the browse page
139
+ cy . get ( 'button.search-button' ) . click ( )
140
+ // The new url should include "/browse"
141
+ cy . url ( ) . should ( 'include' , '/browse' )
142
+ // The new url should not contain a query
143
+ cy . url ( ) . should ( 'not.include' , '?' )
144
+ // The search bar on the browse page should remain blank
145
+ cy . get ( 'input.search-bar' ) . should ( 'have.value' , '' )
146
+ // The service card component should be visible
147
+ cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
148
+ } )
149
+
150
+ it ( 'completes a search from the home page and navigates to "/browse" with a query term' , ( ) => {
151
+ // type an example search into the searchbar
152
+ cy . get ( 'input.search-bar' ) . type ( 'test' )
153
+ // Press the search button
154
+ cy . get ( 'button.search-button' ) . click ( )
155
+ // The new url should include "/browse"
156
+ cy . url ( ) . should ( 'include' , '/browse?q=test' )
157
+ // The search bar on the browse page should have the text that was searched for
158
+ cy . get ( 'input.search-bar' ) . should ( 'have.value' , 'test' )
159
+ // The service card component should be visible
160
+ cy . get ( ".card[data-cy='item-card']" ) . should ( 'be.visible' )
161
+ } )
162
+ } )
155
163
} )
0 commit comments