1
- describe ( 'Viewing Home page' , ( ) => {
1
+ describe ( 'Navigating to the home page' , ( ) => {
2
2
// declare variables that can be used to change how the response is intercepted.
3
3
let loading
4
4
let error
@@ -18,47 +18,82 @@ describe('Viewing Home page', () => {
18
18
cy . visit ( '/' )
19
19
} )
20
20
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.' )
27
25
} )
28
26
} )
29
- } )
30
27
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' )
35
34
} )
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' )
40
50
} )
41
51
} )
42
52
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
+ } )
47
58
} )
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
+ } )
51
73
} )
52
74
} )
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
+ } )
56
83
} )
57
84
} )
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
+ } )
61
96
} )
62
97
} )
63
98
} )
64
- } )
99
+ } )
0 commit comments