@@ -79,28 +79,6 @@ describe('OverviewTab', () => {
79
79
expect ( trademarkText ) . toBeNull ( ) ;
80
80
} ) ;
81
81
82
- // describe('Analytics Component', () => {
83
- // beforeEach(() => {
84
- // jest.clearAllMocks();
85
- // });
86
-
87
- // test('renders Analytics tab and can interact with the checkbox', async () => {
88
- // render(<Analytics />);
89
- // const checkbox = screen.getByRole('checkbox', {
90
- // name: /help improve hue with anonymous usage analytics\./i
91
- // });
92
-
93
- // expect(checkbox).not.toBeChecked();
94
- // await userEvent.click(checkbox);
95
- // await waitFor(() => expect(checkbox).toBeChecked());
96
-
97
- // expect(post).toHaveBeenCalledWith('/about/update_preferences', { collect_usage: 'on' });
98
-
99
- // await userEvent.click(checkbox);
100
- // await waitFor(() => expect(checkbox).not.toBeChecked());
101
- // expect(post).toHaveBeenCalledWith('/about/update_preferences', { collect_usage: null });
102
- // });
103
- // });
104
82
describe ( 'Analytics Component' , ( ) => {
105
83
test ( 'renders Analytics tab and can interact with the checkbox' , async ( ) => {
106
84
( post as jest . Mock ) . mockResolvedValue ( { status : 0 , message : 'Success' } ) ;
@@ -120,18 +98,45 @@ describe('OverviewTab', () => {
120
98
} ) ;
121
99
122
100
describe ( 'Examples component' , ( ) => {
123
- afterEach ( cleanup ) ;
124
- test ( 'click on Hive app and the API for Hive is called' , async ( ) => {
125
- ( post as jest . Mock ) . mockResolvedValue ( { status : 0 , message : 'Success' } ) ;
126
- render ( < Examples /> ) ;
127
- const hiveButton = screen . getByText ( 'Hive' ) ;
128
- userEvent . click ( hiveButton ) ;
129
- await waitFor ( ( ) => {
130
- expect ( post ) . toHaveBeenCalledWith ( '/beeswax/install_examples' , null , {
131
- method : 'POST' ,
132
- silenceErrors : true
101
+
102
+ const exampleApps = [
103
+ { id : 'hive' , name : 'Hive' , old_name : 'beeswax' } ,
104
+ { id : 'impala' , name : 'Impala' } ,
105
+ {
106
+ id : 'search' ,
107
+ name : 'Solr Search' ,
108
+ data : [ 'log_analytics_demo' , 'twitter_demo' , 'yelp_demo' ]
109
+ } ,
110
+ { id : 'spark' , name : 'Spark' , old_name : 'notebook' } ,
111
+ { id : 'oozie' , name : 'Oozie Editor/Dashboard' } ,
112
+ { id : 'hbase' , name : 'Hbase Browser' } ,
113
+ { id : 'pig' , name : 'Pig Editor' }
114
+ ] ;
115
+ // We no longer need the hardcoded test_urls
116
+
117
+ test . each ( exampleApps ) (
118
+ "when the '%s' button is clicked, the API call for installing examples is executed" ,
119
+ async appData => {
120
+ const resolvedValue = { status : 0 , message : 'Success' } ;
121
+ ( post as jest . Mock ) . mockResolvedValue ( resolvedValue ) ;
122
+ render ( < Examples /> ) ;
123
+
124
+ const appIdOrOldName = appData . old_name || appData . id ;
125
+ const url = `/${ appIdOrOldName } /install_examples` ;
126
+ const expectedData = appData . data ? { data : appData . data } : null ;
127
+
128
+ let button = screen . getByText ( appData . name ) ;
129
+ fireEvent . click ( button ) ;
130
+
131
+ await waitFor ( ( ) => {
132
+ expect ( post ) . toHaveBeenCalledWith ( url , expectedData , {
133
+ method : 'POST' ,
134
+ silenceErrors : true
135
+ } ) ;
133
136
} ) ;
134
- } ) ;
135
- } ) ;
137
+
138
+ ( post as jest . Mock ) . mockClear ( ) ;
139
+ }
140
+ ) ;
136
141
} ) ;
137
142
} ) ;
0 commit comments