From eb5369f2a6f2dc238838119eb70194bf2b42b085 Mon Sep 17 00:00:00 2001
From: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
Date: Wed, 3 Aug 2022 21:29:11 -0400
Subject: [PATCH] fix: No back button in save dataset modal (#20964)
* back button fix
* fixed test
---
.../SaveDatasetModal.test.tsx | 23 +++++++++++++++----
.../components/SaveDatasetModal/index.tsx | 4 +++-
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/superset-frontend/src/SqlLab/components/SaveDatasetModal/SaveDatasetModal.test.tsx b/superset-frontend/src/SqlLab/components/SaveDatasetModal/SaveDatasetModal.test.tsx
index 94017525f08d6..7e838a44e3e26 100644
--- a/superset-frontend/src/SqlLab/components/SaveDatasetModal/SaveDatasetModal.test.tsx
+++ b/superset-frontend/src/SqlLab/components/SaveDatasetModal/SaveDatasetModal.test.tsx
@@ -18,7 +18,13 @@
*/
import React from 'react';
import * as reactRedux from 'react-redux';
-import { render, screen, waitFor, within } from 'spec/helpers/testing-library';
+import {
+ render,
+ screen,
+ waitFor,
+ within,
+ cleanup,
+} from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';
import { SaveDatasetModal } from 'src/SqlLab/components/SaveDatasetModal';
@@ -39,7 +45,10 @@ fetchMock.get('glob:*/api/v1/dataset?*', {
// Mock the user
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
-beforeEach(() => useSelectorMock.mockClear());
+beforeEach(() => {
+ useSelectorMock.mockClear();
+ cleanup();
+});
describe('SaveDatasetModal', () => {
it('renders a "Save as new" field', async () => {
@@ -88,7 +97,7 @@ describe('SaveDatasetModal', () => {
expect(screen.getByRole('button', { name: /save/i })).toBeVisible();
});
- it('renders a back and overwrite button when "Overwrite existing" is selected', async () => {
+ it('renders an overwrite button when "Overwrite existing" is selected', async () => {
render(, { useRedux: true });
// Click the overwrite radio button to reveal the overwrite confirmation and back buttons
@@ -97,11 +106,10 @@ describe('SaveDatasetModal', () => {
});
userEvent.click(overwriteRadioBtn);
- expect(screen.getByRole('button', { name: /back/i })).toBeVisible();
expect(screen.getByRole('button', { name: /overwrite/i })).toBeVisible();
});
- it('renders the overwrite button as disabled until an existing dataset is selected', async () => {
+ it('renders the overwrite button as disabled until an existing dataset is selected, confirms overwrite', async () => {
useSelectorMock.mockReturnValue({ ...user });
render(, { useRedux: true });
@@ -131,5 +139,10 @@ describe('SaveDatasetModal', () => {
// Overwrite button should now be enabled
expect(overwriteConfirmationBtn).toBeEnabled();
+
+ // Check Overwrite confirmation functionality
+ userEvent.click(overwriteConfirmationBtn);
+ expect(screen.getByRole('button', { name: /back/i })).toBeVisible();
+ expect(screen.getByRole('button', { name: /overwrite/i })).toBeVisible();
});
});
diff --git a/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx b/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx
index 12922ef79d26a..6d6acf8af9787 100644
--- a/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx
+++ b/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx
@@ -357,7 +357,9 @@ export const SaveDatasetModal: FunctionComponent = ({
)}
{newOrOverwrite === DatasetRadioState.OVERWRITE_DATASET && (
<>
-
+ {shouldOverwriteDataset && (
+
+ )}