mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: database delete warning (#10800)
This commit is contained in:
@@ -24,6 +24,7 @@ import { styledMount as mount } from 'spec/helpers/theming';
|
||||
|
||||
import DatabaseList from 'src/views/CRUD/data/database/DatabaseList';
|
||||
import DatabaseModal from 'src/views/CRUD/data/database/DatabaseModal';
|
||||
import DeleteModal from 'src/components/DeleteModal';
|
||||
import SubMenu from 'src/components/Menu/SubMenu';
|
||||
import ListView from 'src/components/ListView';
|
||||
import Filters from 'src/components/ListView/Filters';
|
||||
@@ -37,6 +38,7 @@ const store = mockStore({});
|
||||
const databasesInfoEndpoint = 'glob:*/api/v1/database/_info*';
|
||||
const databasesEndpoint = 'glob:*/api/v1/database/?*';
|
||||
const databaseEndpoint = 'glob:*/api/v1/database/*';
|
||||
const databaseRelatedEndpoint = 'glob:*/api/v1/database/*/related_objects*';
|
||||
|
||||
const mockdatabases = [...new Array(3)].map((_, i) => ({
|
||||
changed_by: {
|
||||
@@ -63,6 +65,16 @@ fetchMock.get(databasesEndpoint, {
|
||||
});
|
||||
|
||||
fetchMock.delete(databaseEndpoint, {});
|
||||
fetchMock.get(databaseRelatedEndpoint, {
|
||||
charts: {
|
||||
count: 0,
|
||||
result: [],
|
||||
},
|
||||
dashboards: {
|
||||
count: 0,
|
||||
result: [],
|
||||
},
|
||||
});
|
||||
|
||||
describe('DatabaseList', () => {
|
||||
const wrapper = mount(<DatabaseList />, { context: { store } });
|
||||
@@ -101,6 +113,10 @@ describe('DatabaseList', () => {
|
||||
});
|
||||
await waitForComponentToPaint(wrapper);
|
||||
|
||||
expect(wrapper.find(DeleteModal).props().description).toMatchInlineSnapshot(
|
||||
`"The database db 0 is linked to 0 charts that appear on 0 dashboards. Are you sure you want to continue? Deleting the database will break those objects."`,
|
||||
);
|
||||
|
||||
act(() => {
|
||||
wrapper
|
||||
.find('#delete')
|
||||
@@ -115,6 +131,9 @@ describe('DatabaseList', () => {
|
||||
|
||||
await waitForComponentToPaint(wrapper);
|
||||
|
||||
expect(fetchMock.calls(/database\/0\/related_objects/, 'GET')).toHaveLength(
|
||||
1,
|
||||
);
|
||||
expect(fetchMock.calls(/database\/0/, 'DELETE')).toHaveLength(1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user