Skip to content

Commit 940b731

Browse files
committed
refactor the home page specs
changed up the specs to fit the flow of the home page. also moving two specs from the browse page to the home page since that's where the requests originate from.
1 parent f9d4eae commit 940b731

File tree

3 files changed

+69
-68
lines changed

3 files changed

+69
-68
lines changed

cypress.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = defineConfig({
2626
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
2727
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
2828
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
29+
CYPRESS_SEARCH_QUERY: 'test',
2930
// importing the `API_PER_PAGE` variable from the constants file throws
3031
// errors since this file doesn't follow ES6 syntax. if the value is
3132
// changed in constants, it needs to be updated here too

cypress/e2e/browse.cy.js

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ describe('Browsing', () => {
1919
emptyFixture: 'services/no-wares.json',
2020
},
2121
]
22-
22+
2323
beforeEach(() => {
2424
// Intercept the responses from the endpoint to view all requests.
25-
// Even though this is to the same endpoint, the call happens on each page twice,
25+
// Even though this is to the same endpoint, the call happens on each page twice,
2626
// once when the page loads with all the wares, and again after any search is performed.
2727
// this makes it necessary to create an intercept for each time the call is made.
2828
intercepts.forEach((intercept) => {
@@ -103,39 +103,4 @@ describe('Browsing', () => {
103103
})
104104
})
105105
})
106-
107-
describe('from the home page', () => {
108-
beforeEach(() => {
109-
wares = true
110-
// Intercept the api call being made on the homepage
111-
cy.customApiIntercept({
112-
action: 'GET',
113-
alias: 'useAllWares',
114-
requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json`,
115-
data: wares,
116-
defaultFixture: 'services/wares.json',
117-
loading,
118-
error
119-
})
120-
cy.visit('/')
121-
})
122-
123-
context('a search is completed successfully and', () => {
124-
it('navigates to "/browse" with a blank query', () => {
125-
cy.get('button.search-button').click()
126-
cy.url().should('include', '/browse')
127-
cy.url().should('not.include', '?')
128-
cy.get('input.search-bar').should('have.value', '')
129-
cy.get(".card[data-cy='item-card']").should('be.visible')
130-
})
131-
132-
it('navigates to "/browse" with a query term', () => {
133-
cy.get('input.search-bar').type('test')
134-
cy.get('button.search-button').click()
135-
cy.url().should('include', '/browse?q=test')
136-
cy.get('input.search-bar').should('have.value', 'test')
137-
cy.get(".card[data-cy='item-card']").should('be.visible')
138-
})
139-
})
140-
})
141-
})
106+
})

cypress/e2e/home.cy.js

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('Viewing Home page', () => {
1+
describe('Navigating to the home page', () => {
22
// declare variables that can be used to change how the response is intercepted.
33
let loading
44
let error
@@ -18,47 +18,82 @@ describe('Viewing Home page', () => {
1818
cy.visit('/')
1919
})
2020

21-
context('featured services list is loading', () => {
22-
before(() => loading = true)
23-
24-
it('should show 3 placeholder cards loading', () => {
25-
cy.get('p.placeholder-glow').should('have.length', 3).then(() => {
26-
cy.log('Loading text displays correctly.')
21+
describe('renders a search bar', () => {
22+
it('with no query', () => {
23+
cy.get("form[data-cy='search-bar']").should('exist').then(() => {
24+
cy.log('Search bar renders successfully.')
2725
})
2826
})
29-
})
3027

31-
context('error while making a request to the api', () => {
32-
before(() => {
33-
loading = false
34-
error = true
28+
it('able to navigate to "/browse" with a blank query', () => {
29+
cy.get('button.search-button').click()
30+
cy.url().should('include', '/browse')
31+
cy.url().should('not.include', '?')
32+
cy.get('input.search-bar').should('have.value', '')
33+
cy.get(".card[data-cy='item-card']").should('be.visible')
3534
})
36-
it('should show an error message.', () => {
37-
cy.get("div[role='alert']").should('be.visible').then(() => {
38-
cy.log('Successfully hits an error.')
39-
})
35+
36+
it('able to navigate to "/browse" with a valid query term', () => {
37+
cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
38+
cy.get('button.search-button').click()
39+
cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`)
40+
cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY'))
41+
cy.get(".card[data-cy='item-card']").should('be.visible')
42+
})
43+
44+
it('able to navigate to "/browse" with an invalid query term', () => {
45+
cy.get('input.search-bar').type('test')
46+
cy.get('button.search-button').click()
47+
cy.url().should('include', '/browse?q=test')
48+
cy.get('input.search-bar').should('have.value', 'test')
49+
cy.get(".card[data-cy='item-card']").should('be.visible')
4050
})
4151
})
4252

43-
context('home page components are loading successfully, &', () => {
44-
before(() => {
45-
featuredServices = true
46-
error = false
53+
describe('renders a text box', () => {
54+
it('showing the about text.', () => {
55+
cy.get("section[data-cy='about-us-section']").should('exist').then(() => {
56+
cy.log('Abouttext renders successfully.')
57+
})
4758
})
48-
it('should show the search bar.', () => {
49-
cy.get("form[data-cy='search-bar']").should('exist').then(() => {
50-
cy.log('Search bar renders successfully.')
59+
})
60+
61+
describe('makes a call to the api', () => {
62+
context('which when returns an error', () => {
63+
before(() => {
64+
loading = false
65+
error = true
66+
})
67+
68+
it('shows an error message', () => {
69+
// why would we get an error?
70+
cy.get("div[role='alert']").should('be.visible').then(() => {
71+
cy.log('Successfully hits an error.')
72+
})
5173
})
5274
})
53-
it('should show the about text.', () => {
54-
cy.get("section[data-cy='about-us-section']").should('exist').then(() => {
55-
cy.log('Abouttext renders successfully.')
75+
76+
context('which when returns no error or data', () => {
77+
before(() => loading = true)
78+
79+
it('shows 3 placeholder cards loading', () => {
80+
cy.get('p.placeholder-glow').should('have.length', 3).then(() => {
81+
cy.log('Loading text displays correctly.')
82+
})
5683
})
5784
})
58-
it('should show the featured services cards.', () => {
59-
cy.get("div[data-cy='item-group']").should('exist').then(() => {
60-
cy.log('Status bar renders successfully.')
85+
86+
context('which when returns data', () => {
87+
before(() => {
88+
featuredServices = true
89+
error = false
90+
})
91+
92+
it('shows the featured services cards', () => {
93+
cy.get("div[data-cy='item-group']").should('exist').then(() => {
94+
cy.log('Status bar renders successfully.')
95+
})
6196
})
6297
})
6398
})
64-
})
99+
})

0 commit comments

Comments
 (0)