1
+ describe ( 'Viewing Home page' , ( ) => {
2
+ // declare variables that can be used to change how the response is intercepted.
3
+ let loading
4
+ let error
5
+ let featuredServices
6
+
7
+ beforeEach ( ( ) => {
8
+ // Intercept the response from the endpoint to view all requests
9
+ cy . customApiIntercept ( {
10
+ action : 'GET' ,
11
+ alias : 'useAllWares' ,
12
+ requestURL : `/providers/${ Cypress . env ( 'NEXT_PUBLIC_PROVIDER_ID' ) } /wares.json` ,
13
+ data : featuredServices ,
14
+ defaultFixture : 'services/wares.json' ,
15
+ emptyFixture : 'services/no-wares.json' ,
16
+ loading,
17
+ error
18
+ } )
19
+ cy . visit ( '/' )
20
+ } )
21
+
22
+
23
+ context ( 'featured services list is loading' , ( ) => {
24
+ before ( ( ) => {
25
+ loading = true
26
+ } )
27
+ it ( 'should show 3 placeholder cards loading' , ( ) => {
28
+ cy . get ( 'p.placeholder-glow' ) . should ( 'be.visible' ) . then ( ( ) => {
29
+ cy . log ( 'Loading text displays correctly.' )
30
+ } )
31
+ } )
32
+ } )
33
+
34
+ context ( 'error while making a request to the api' , ( ) => {
35
+ before ( ( ) => {
36
+ loading = false
37
+ error = true
38
+ } )
39
+ it ( 'should show an error message.' , ( ) => {
40
+ cy . get ( "div[role='alert']" ) . should ( 'be.visible' ) . then ( ( ) => {
41
+ cy . log ( 'Successfully hits an error.' )
42
+ } )
43
+ } )
44
+ } )
45
+
46
+ context ( 'home page components are loading successfully, &' , ( ) => {
47
+ before ( ( ) => {
48
+ featuredServices = true
49
+ error = false
50
+ } )
51
+ it ( 'should show the search bar.' , ( ) => {
52
+ cy . get ( "form[data-cy='search-bar']" ) . should ( 'exist' ) . then ( ( ) => {
53
+ cy . log ( 'Search bar renders successfully.' )
54
+ } )
55
+ } )
56
+ it ( 'should show the about text.' , ( ) => {
57
+ cy . get ( "section[data-cy='about-us-section']" ) . should ( 'exist' ) . then ( ( ) => {
58
+ cy . log ( 'Abouttext renders successfully.' )
59
+ } )
60
+ } )
61
+ it ( 'should show the featured services cards.' , ( ) => {
62
+ cy . get ( "div[data-cy='item-group']" ) . should ( 'exist' ) . then ( ( ) => {
63
+ cy . log ( 'Status bar renders successfully.' )
64
+ } )
65
+ } )
66
+ } )
67
+ } )
0 commit comments