Skip to content

Commit

Permalink
fix: No back button in save dataset modal (#20964)
Browse files Browse the repository at this point in the history
* back button fix

* fixed test
  • Loading branch information
AAfghahi authored Aug 4, 2022
1 parent 7e501cd commit eb5369f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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(<SaveDatasetModal {...mockedProps} />, { useRedux: true });

// Click the overwrite radio button to reveal the overwrite confirmation and back buttons
Expand All @@ -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(<SaveDatasetModal {...mockedProps} />, { useRedux: true });

Expand Down Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ export const SaveDatasetModal: FunctionComponent<SaveDatasetModalProps> = ({
)}
{newOrOverwrite === DatasetRadioState.OVERWRITE_DATASET && (
<>
<Button onClick={handleOverwriteCancel}>Back</Button>
{shouldOverwriteDataset && (
<Button onClick={handleOverwriteCancel}>Back</Button>
)}
<Button
className="md"
buttonStyle="primary"
Expand Down

0 comments on commit eb5369f

Please sign in to comment.