Skip to content

Commit e412793

Browse files
committed
add home page test
1 parent d4c36b4 commit e412793

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

cypress/e2e/home.cy.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { scientistApiBaseURL } from '../support/e2e'
2+
3+
describe('Viewing Home page', () => {
4+
// declare variables that can be used to change how the response is intercepted.
5+
let loading
6+
let error
7+
let featuredServices
8+
9+
beforeEach(() => {
10+
// Intercept the response from the endpoint to view all requests
11+
cy.customApiIntercept({
12+
action: 'GET',
13+
alias: 'useAllWares',
14+
requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json`,
15+
data: featuredServices,
16+
defaultFixture: 'services/wares.json',
17+
emptyFixture: 'services/no-wares.json',
18+
loading,
19+
error
20+
})
21+
cy.visit('/')
22+
})
23+
24+
25+
context('featured services list is loading', () => {
26+
before(() => {
27+
loading = true
28+
})
29+
it('should show a loading spinner.', () => {
30+
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
31+
cy.log('Loading spinner displays correctly.')
32+
})
33+
})
34+
})
35+
36+
context('error while making a request to the api', () => {
37+
before(() => {
38+
featuredServices = undefined
39+
loading = false
40+
error = true
41+
})
42+
it('should show an error message.', () => {
43+
cy.get("div[role='alert']").should('be.visible').then(() => {
44+
cy.log('Successfully hits an error.')
45+
})
46+
})
47+
})
48+
})

0 commit comments

Comments
 (0)