Skip to content

Commit bf4a66e

Browse files
sadpandajoeclaude
andcommitted
test(explore): add RTL test for ViewQueryModal error rendering
Add React Testing Library test to verify that ViewQueryModal correctly displays validation errors in an Alert component when the backend returns errors in the query result. This test ensures the fix for issue #35492 continues to work correctly by verifying the frontend properly renders error messages instead of showing a blank panel. Test coverage: - Mocks chart/data API to return validation error - Verifies Alert component is rendered - Verifies error message is displayed Related to #35492 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f04b81e commit bf4a66e

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { screen, render, waitFor } from 'spec/helpers/testing-library';
21+
import fetchMock from 'fetch-mock';
22+
import ViewQueryModal from './ViewQueryModal';
23+
24+
const mockFormData = {
25+
datasource: '1__table',
26+
viz_type: 'table',
27+
};
28+
29+
const chartDataEndpoint = 'glob:*/api/v1/chart/data*';
30+
31+
afterEach(() => {
32+
jest.resetAllMocks();
33+
fetchMock.restore();
34+
});
35+
36+
test('renders Alert component when query result contains validation error', async () => {
37+
/**
38+
* Regression test for issue #35492
39+
* Verifies that validation errors from the backend are displayed in an Alert
40+
* component instead of showing a blank panel
41+
*/
42+
// Mock API response with validation error
43+
fetchMock.post(chartDataEndpoint, {
44+
result: [
45+
{
46+
error: 'Missing temporal column',
47+
language: 'sql',
48+
},
49+
],
50+
});
51+
52+
render(<ViewQueryModal latestQueryFormData={mockFormData} />);
53+
54+
// Wait for API call to complete
55+
await waitFor(() =>
56+
expect(fetchMock.calls(chartDataEndpoint)).toHaveLength(1),
57+
);
58+
59+
// Assert Alert component is rendered with error message
60+
expect(screen.getByRole('alert')).toBeInTheDocument();
61+
expect(screen.getByText('Missing temporal column')).toBeInTheDocument();
62+
});

0 commit comments

Comments
 (0)