Skip to content

Commit 733458a

Browse files
committed
all search bar tests from the home e2e spec pass
1 parent 4111930 commit 733458a

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

cypress/e2e/home.cy.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
describe('Navigating to the home page', () => {
22
// declare variables that can be used to change how the response is intercepted.
3-
let loading
43
let error
54
let featuredServices
6-
let requestURL
7-
let data
5+
let loading
86

97
beforeEach(() => {
108
cy.customApiIntercept({
119
action: 'GET',
1210
alias: 'useAllWares',
13-
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
1411
data: featuredServices,
1512
defaultFixture: 'services/wares.json',
1613
emptyFixture: 'services/no-wares.json',
14+
error,
1715
loading,
18-
error
16+
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
1917
})
18+
2019
cy.visit('/')
2120
})
2221

@@ -28,20 +27,22 @@ describe('Navigating to the home page', () => {
2827
})
2928

3029
context('able to navigate to "/browse"', () => {
31-
const testSetup = ({ data, requestURL }) => {
30+
const testSetup = ({ data, defaultFixture, requestURL }) => {
3231
cy.customApiIntercept({
3332
action: 'GET',
3433
alias: 'useFilteredWares',
35-
requestURL,
3634
data,
37-
defaultFixture: 'services/wares.json',
35+
defaultFixture,
36+
emptyFixture: 'services/no-wares.json',
37+
requestURL,
3838
})
3939
}
4040

4141
it('with a blank query', () => {
4242
testSetup({
4343
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=`,
44-
data: true
44+
data: true,
45+
defaultFixture: 'services/wares.json',
4546
})
4647

4748
cy.get('button.search-button').click()
@@ -51,20 +52,32 @@ describe('Navigating to the home page', () => {
5152
cy.get(".card[data-cy='item-card']").should('be.visible')
5253
})
5354

54-
it('able to navigate to "/browse" with a valid query term', () => {
55+
it('with a valid query term', () => {
56+
testSetup({
57+
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`,
58+
data: true,
59+
defaultFixture: 'services/filtered-wares.json',
60+
})
61+
5562
cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
5663
cy.get('button.search-button').click()
5764
cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`)
5865
cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY'))
5966
cy.get(".card[data-cy='item-card']").should('be.visible')
6067
})
6168

62-
it('able to navigate to "/browse" with an invalid query term', () => {
63-
cy.get('input.search-bar').type('test')
69+
it('with an invalid query term', () => {
70+
const invalidQuery = 'asdfghjk'
71+
testSetup({
72+
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=${invalidQuery}`,
73+
})
74+
75+
cy.get('input.search-bar').type(invalidQuery)
6476
cy.get('button.search-button').click()
65-
cy.url().should('include', '/browse?q=test')
66-
cy.get('input.search-bar').should('have.value', 'test')
67-
cy.get(".card[data-cy='item-card']").should('be.visible')
77+
cy.url().should('include', `/browse?q=${invalidQuery}`)
78+
cy.get('input.search-bar').should('have.value', invalidQuery)
79+
cy.get("p[data-cy='no-results']").should('contain', `Your search for ${invalidQuery} returned no results`)
80+
})
6881
})
6982
})
7083

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"ware_refs": [
3+
{
4+
"id": 3456,
5+
"slug": "test-ware",
6+
"name": "Test Ware",
7+
"snippet": "Here is a test ware snippet.",
8+
"urls": {
9+
"promo_image": "https://y.yarn.co/193fa4ae-a245-4f7a-ac9d-64bbebb18c8d_screenshot.jpg"
10+
}
11+
},
12+
{
13+
"id": 4567,
14+
"slug": "another-test-ware",
15+
"name": "Another Test Ware",
16+
"snippet": "Another test snippet.",
17+
"urls": {
18+
"promo_image": "https://cdn.drawception.com/images/panels/2017/7-2/jtqKRKSpyj-6.png"
19+
}
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)