feat: Add confirmation modal for unsaved changes (#33809)

This commit is contained in:
Gabriel Torres Ruiz
2025-07-01 13:38:51 -03:00
committed by GitHub
parent 050ccdcb3d
commit 057218d87f
28 changed files with 1799 additions and 489 deletions

View File

@@ -16,13 +16,83 @@
* specific language governing permissions and limitations
* under the License.
*/
import { sanitizeFormData } from './formData';
import { SupersetClient } from '@superset-ui/core';
import { postFormData, putFormData } from './formData';
test('sanitizeFormData removes temporary control values', () => {
expect(
sanitizeFormData({
url_params: { foo: 'bar' },
metrics: ['foo', 'bar'],
}),
).toEqual({ metrics: ['foo', 'bar'] });
jest.mock('@superset-ui/core', () => ({
SupersetClient: {
post: jest.fn(),
put: jest.fn(),
},
}));
test('postFormData should call SupersetClient.post with correct payload and return key', async () => {
const mockKey = '123abc';
const mockResponse = { json: { key: mockKey } };
(SupersetClient.post as jest.Mock).mockResolvedValue(mockResponse);
const result = await postFormData(
1,
'table',
{ some: 'form', data: true },
42,
'tab-7',
);
expect(SupersetClient.post).toHaveBeenCalledWith({
endpoint: 'api/v1/explore/form_data?tab_id=tab-7',
jsonPayload: {
datasource_id: 1,
datasource_type: 'table',
form_data: JSON.stringify({ some: 'form', data: true }), // assuming sanitizeFormData is a passthrough
chart_id: 42,
},
});
expect(result).toBe(mockKey);
});
test('putFormData should call SupersetClient.put with correct payload and return message', async () => {
const mockMessage = 'Form data updated';
const mockResponse = { json: { message: mockMessage } };
(SupersetClient.put as jest.Mock).mockResolvedValue(mockResponse);
const result = await putFormData(
10,
'druid',
'abc123',
{ another: 'value' },
undefined,
'tab-5',
);
expect(SupersetClient.put).toHaveBeenCalledWith({
endpoint: 'api/v1/explore/form_data/abc123?tab_id=tab-5',
jsonPayload: {
datasource_id: 10,
datasource_type: 'druid',
form_data: JSON.stringify({ another: 'value' }), // again, assuming sanitizeFormData is passthrough
},
});
expect(result).toBe(mockMessage);
});
test('postFormData without optional params should work', async () => {
(SupersetClient.post as jest.Mock).mockResolvedValue({
json: { key: 'abc' },
});
await postFormData(2, 'table', { foo: 'bar' });
expect(SupersetClient.post).toHaveBeenCalledWith({
endpoint: 'api/v1/explore/form_data',
jsonPayload: {
datasource_id: 2,
datasource_type: 'table',
form_data: JSON.stringify({ foo: 'bar' }),
},
});
});