Skip to content

Commit 91a92c0

Browse files
committed
add data cy and home page e2e tests
1 parent a296f28 commit 91a92c0

File tree

2 files changed

+66
-58
lines changed

2 files changed

+66
-58
lines changed

cypress/e2e/browse.cy.js

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,10 @@
11
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-
372
let wares
383
let loading
394
let error
405
let intercepts = [
416
{
42-
alias: 'useAllWares',
7+
alias: 'useFilteredWares',
438
},
449
{
4510
alias: 'useFilteredWares - blank search',
@@ -54,25 +19,27 @@ describe('Browsing', () => {
5419
emptyFixture: 'services/no-wares.json',
5520
},
5621
]
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
7537
})
38+
})
39+
})
40+
41+
describe('from the browse page', () => {
42+
beforeEach(() => {
7643
cy.visit('/browse')
7744
})
7845

@@ -120,9 +87,6 @@ describe('Browsing', () => {
12087
cy.get(".card[data-cy='item-card']").should('be.visible')
12188
})
12289

123-
before(() => {
124-
wares = true
125-
})
12690
it('completes a search with a query term', () => {
12791
// Type an example search into the searchbar
12892
cy.get('input.search-bar').type('test')
@@ -149,7 +113,51 @@ describe('Browsing', () => {
149113
// The search bar on the browse page should have the text that was searched for
150114
cy.get('input.search-bar').should('have.value', 'asdfghjk')
151115
// 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')
152117
})
153118
})
154119
})
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+
})
155163
})

pages/browse/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Browse = () => {
7676
))}
7777
</>
7878
) : (
79-
<p>
79+
<p data-cy='no-results'>
8080
Your search for <b>{query}</b> returned no results. Please try another search term.
8181
</p>
8282
)}

0 commit comments

Comments
 (0)