Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No back button in save dataset modal #20964

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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