@@ -21,10 +21,15 @@ import Overview from './OverviewTab';
21
21
import * as hueConfigModule from '../../../config/hueConfig' ;
22
22
import Examples from './Examples' ;
23
23
import Analytics from './Analytics' ;
24
- import { post } from '../../../api/utils' ;
24
+ import {
25
+ INSTALL_APP_EXAMPLES_API_URL ,
26
+ INSTALL_AVAILABLE_EXAMPLES_API_URL
27
+ } from '../Components/utils' ;
28
+ import { get , post } from '../../../api/utils' ;
25
29
26
30
jest . mock ( '../../../api/utils' , ( ) => ( {
27
- post : jest . fn ( )
31
+ post : jest . fn ( ) ,
32
+ get : jest . fn ( )
28
33
} ) ) ;
29
34
30
35
jest . mock ( './ConfigStatus' , ( ) => ( ) => < div > MockedConfigStatusComponent</ div > ) ;
@@ -57,23 +62,6 @@ describe('OverviewTab', () => {
57
62
expect ( screen . queryByText ( 'MockedAnalyticsComponent' ) ) . not . toBeInTheDocument ( ) ;
58
63
} ) ;
59
64
60
- test ( 'shows the trademark text' , ( ) => {
61
- render ( < Overview /> ) ;
62
- expect (
63
- screen . getByText ( 'Hue and the Hue logo are trademarks of Cloudera, Inc.' )
64
- ) . toBeInTheDocument ( ) ;
65
- } ) ;
66
-
67
- test ( 'it should not render Overview for non-admin users' , ( ) => {
68
- ( hueConfigModule . getLastKnownConfig as jest . Mock ) . mockReturnValue ( {
69
- hue_config : { is_admin : false }
70
- } ) ;
71
-
72
- const { queryByText } = render ( < Overview /> ) ;
73
- const trademarkText = queryByText ( 'Hue and the Hue logo are trademarks of Cloudera, Inc.' ) ;
74
- expect ( trademarkText ) . toBeNull ( ) ;
75
- } ) ;
76
-
77
65
describe ( 'Analytics Component' , ( ) => {
78
66
test ( 'renders Analytics tab and can interact with the checkbox' , async ( ) => {
79
67
( post as jest . Mock ) . mockResolvedValue ( { status : 0 , message : 'Success' } ) ;
@@ -94,52 +82,69 @@ describe('OverviewTab', () => {
94
82
} ) ;
95
83
96
84
describe ( 'Examples component' , ( ) => {
97
- const exampleApps = [
98
- { id : 'hive' , name : 'Hive' , old_name : 'beeswax' } ,
99
- { id : 'impala' , name : 'Impala' } ,
100
- {
101
- id : 'search' ,
102
- name : 'Solr Search' ,
103
- data : [ 'log_analytics_demo' , 'twitter_demo' , 'yelp_demo' ]
104
- } ,
105
- { id : 'spark' , name : 'Spark' , old_name : 'notebook' } ,
106
- { id : 'oozie' , name : 'Oozie Editor/Dashboard' } ,
107
- { id : 'hbase' , name : 'Hbase Browser' } ,
108
- { id : 'pig' , name : 'Pig Editor' }
109
- ] ;
110
-
111
- const resolvedValue = { status : 0 , message : 'Success' } ;
112
-
113
- exampleApps . forEach ( appData => {
114
- test ( `clicking the install button for '${ appData . name } ' makes an API call to '/api/v1/install_app_examples'` , async ( ) => {
115
- ( post as jest . Mock ) . mockResolvedValue ( resolvedValue ) ;
116
- render ( < Examples /> ) ;
117
85
118
- const button = screen . getByText ( appData . name ) ;
119
- fireEvent . click ( button ) ;
86
+ const availableAppsResponse = {
87
+ apps : {
88
+ hive : 'Hive' ,
89
+ impala : 'Impala'
90
+ }
91
+ } ;
92
+ beforeEach ( ( ) => {
93
+ ( get as jest . Mock ) . mockImplementation ( url => {
94
+ if ( url === INSTALL_AVAILABLE_EXAMPLES_API_URL ) {
95
+ return Promise . resolve ( availableAppsResponse ) ;
96
+ }
97
+ return Promise . reject ( ) ;
98
+ } ) ;
99
+
100
+ ( post as jest . Mock ) . mockImplementation ( ( ) => Promise . resolve ( { status : 0 , message : 'Success' } ) ) ;
101
+ } ) ;
102
+
103
+ afterEach ( ( ) => {
104
+ jest . clearAllMocks ( ) ;
105
+ } ) ;
106
+
107
+ test ( 'fetch and display available apps' , async ( ) => {
108
+ render ( < Examples /> ) ;
109
+
110
+ await waitFor ( ( ) => {
111
+ expect ( get ) . toHaveBeenCalledWith ( INSTALL_AVAILABLE_EXAMPLES_API_URL , { } ) ;
112
+ Object . entries ( availableAppsResponse . apps ) . forEach ( ( [ appId , appName ] ) => {
113
+ expect ( screen . getByText ( appName ) ) . toBeInTheDocument ( ) ;
114
+ } ) ;
115
+ } ) ;
116
+ } ) ;
117
+
118
+ test ( 'post to install app example when the install button is clicked' , async ( ) => {
119
+ render ( < Examples /> ) ;
120
+
121
+ await waitFor ( ( ) => {
122
+ expect ( get ) . toHaveBeenCalledWith ( INSTALL_AVAILABLE_EXAMPLES_API_URL , { } ) ;
123
+ Object . entries ( availableAppsResponse . apps ) . forEach ( ( [ appId , appName ] ) => {
124
+ expect ( screen . getByText ( appName ) ) . toBeInTheDocument ( ) ;
125
+ } ) ;
126
+ } ) ;
127
+
128
+ const installButton = screen . getByText ( 'Hive' ) ;
129
+ fireEvent . click ( installButton ) ;
130
+
131
+ await waitFor ( ( ) => {
132
+ expect ( post ) . toHaveBeenCalledWith (
133
+ INSTALL_APP_EXAMPLES_API_URL ,
134
+ { app_name : 'hive' }
135
+ ) ;
136
+ } ) ;
137
+ expect ( installButton . textContent ) . toContain ( 'Hive' ) ;
138
+ }
139
+ ) ;
140
+
141
+ test ( 'display a confirmation message after a successful install' , async ( ) => {
142
+ render ( < Examples /> ) ;
120
143
144
+ const appName = 'Hive' ;
121
145
await waitFor ( ( ) => {
122
- if ( appData . data ) {
123
- expect ( post ) . toHaveBeenCalledWith (
124
- '/api/v1/install_app_examples' ,
125
- {
126
- app_name : appData . id ,
127
- data : appData . data
128
- } ,
129
- expect . anything ( )
130
- ) ;
131
- } else {
132
- expect ( post ) . toHaveBeenCalledWith (
133
- '/api/v1/install_app_examples' ,
134
- {
135
- app_name : appData . id
136
- } ,
137
- expect . anything ( )
138
- ) ;
139
- }
146
+ expect ( screen . getByText ( appName ) ) . toBeInTheDocument ( ) ;
140
147
} ) ;
141
- ( post as jest . Mock ) . mockClear ( ) ;
142
148
} ) ;
143
149
} ) ;
144
150
} ) ;
145
- } ) ;
0 commit comments