Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9e2ed1c

Browse files
committedMar 20, 2025·
Fixing unit tests
1 parent 8e120f0 commit 9e2ed1c

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed
 

‎desktop/core/src/desktop/js/apps/admin/Overview/OverviewTab.test.tsx

+39-34
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,6 @@ describe('OverviewTab', () => {
7979
expect(trademarkText).toBeNull();
8080
});
8181

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-
// });
10482
describe('Analytics Component', () => {
10583
test('renders Analytics tab and can interact with the checkbox', async () => {
10684
(post as jest.Mock).mockResolvedValue({ status: 0, message: 'Success' });
@@ -120,18 +98,45 @@ describe('OverviewTab', () => {
12098
});
12199

122100
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+
});
133136
});
134-
});
135-
});
137+
138+
(post as jest.Mock).mockClear();
139+
}
140+
);
136141
});
137142
});

0 commit comments

Comments
 (0)
Please sign in to comment.