Skip to content

Commit a296f28

Browse files
committed
browse tests from browse page all passing
1 parent ea7e25f commit a296f28

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

cypress/e2e/browse.cy.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,41 @@ describe('Browsing', () => {
3737
let wares
3838
let loading
3939
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+
]
4157

4258
describe('from the /browse page', () => {
4359
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+
})
5475
})
5576
cy.visit('/browse')
5677
})
@@ -80,7 +101,7 @@ describe('Browsing', () => {
80101

81102
// filtering by query is handled in the api and not the webstore
82103
// 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.
84105
context('a search is completed successfully from the browse page', () => {
85106
before(() => {
86107
wares = true
@@ -89,53 +110,45 @@ describe('Browsing', () => {
89110
it('completes a search with a blank query', () => {
90111
// Find the search button and perform an empty search, which should lead to the browse page
91112
cy.get('button.search-button').click()
92-
93113
// The new url should include "/browse"
94114
cy.url().should('include', '/browse')
95-
96115
// The new url should not contain a query
97116
cy.url().should('not.include', '?')
98-
99117
// The search bar on the browse page should remain blank
100118
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')
101121
})
102122

103123
before(() => {
104124
wares = true
105-
query = 'test'
106125
})
107126
it('completes a search with a query term', () => {
108-
// type an example search into the searchbar
127+
// Type an example search into the searchbar
109128
cy.get('input.search-bar').type('test')
110-
111129
// Press the search button
112130
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
115132
cy.url().should('include', '/browse?q=test')
116-
117133
// The search bar on the browse page should have the text that was searched for
118134
cy.get('input.search-bar').should('have.value', 'test')
119-
135+
// The service card component should be visible
120136
cy.get(".card[data-cy='item-card']").should('be.visible')
121137
})
122138

123139
before(() => {
124-
wares = true
125-
query = 'asdfghjk'
140+
wares = false
126141
})
127142
it('completes a search with a query term, but has no results', () => {
128143
// type an example search into the searchbar
129144
cy.get('input.search-bar').type('asdfghjk')
130-
131145
// Press the search button
132146
cy.get('button.search-button').click()
133-
134147
// The new url should include "/browse"
135148
cy.url().should('include', '/browse?q=asdfghjk')
136-
137149
// The search bar on the browse page should have the text that was searched for
138150
cy.get('input.search-bar').should('have.value', 'asdfghjk')
151+
// The message showing that there are no results should show
139152
})
140153
})
141154
})

0 commit comments

Comments
 (0)