fix: permalink save/overwrites in explore (#25112)

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
Hugh A. Miles II
2023-10-16 14:00:09 -04:00
committed by GitHub
parent 18a1c8d7d8
commit e58a3aba54
2 changed files with 48 additions and 10 deletions

View File

@@ -27,7 +27,10 @@ import Button from 'src/components/Button';
import fetchMock from 'fetch-mock';
import * as saveModalActions from 'src/explore/actions/saveModalActions';
import SaveModal, { StyledModal } from 'src/explore/components/SaveModal';
import SaveModal, {
PureSaveModal,
StyledModal,
} from 'src/explore/components/SaveModal';
import { BrowserRouter } from 'react-router-dom';
const middlewares = [thunk];
@@ -100,8 +103,12 @@ const queryDefaultProps = {
};
const fetchDashboardsEndpoint = `glob:*/dashboardasync/api/read?_flt_0_owners=${1}`;
const fetchChartEndpoint = `glob:*/api/v1/chart/${1}*`;
beforeAll(() => fetchMock.get(fetchDashboardsEndpoint, mockDashboardData));
beforeAll(() => {
fetchMock.get(fetchDashboardsEndpoint, mockDashboardData);
fetchMock.get(fetchChartEndpoint, { id: 1, dashboards: [1] });
});
afterAll(() => fetchMock.restore());
@@ -226,3 +233,27 @@ test('set dataset name when chart source is query', () => {
expect(wrapper.find('[data-test="new-dataset-name"]')).toExist();
expect(wrapper.state().datasetName).toBe('test');
});
test('make sure slice_id in the URLSearchParams before the redirect', () => {
const myProps = {
...defaultProps,
slice: { slice_id: 1, slice_name: 'title', owners: [1] },
actions: {
setFormData: jest.fn(),
updateSlice: jest.fn(() => Promise.resolve({ id: 1 })),
getSliceDashboards: jest.fn(),
},
user: { userId: 1 },
history: {
replace: jest.fn(),
},
dispatch: jest.fn(),
};
const saveModal = new PureSaveModal(myProps);
const result = saveModal.handleRedirect(
'https://example.com/?name=John&age=30',
{ id: 1 },
);
expect(result.get('slice_id')).toEqual('1');
});