Skip to content

Commit

Permalink
fix: Delete modal button with lowercase text (#30060)
Browse files Browse the repository at this point in the history
(cherry picked from commit cd6b8b2)
  • Loading branch information
michael-s-molina authored and sadpandajoe committed Sep 6, 2024
1 parent cea8ede commit d43e992
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,32 @@ describe('ConfirmStatusChange', () => {
</>
)}
</ConfirmStatusChange>,
{
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
},
);

it('opens a confirm modal', () => {
act(() => {
wrapper.find('#btn1').first().props().onClick('foo');
});
fireEvent.click(getByTestId('btn1'));

Check failure on line 42 in superset-frontend/src/components/ConfirmStatusChange/ConfirmStatusChange.test.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

'fireEvent' is not defined

Check failure on line 42 in superset-frontend/src/components/ConfirmStatusChange/ConfirmStatusChange.test.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

'getByTestId' is not defined

wrapper.update();
expect(getByTestId(`${mockedProps.title}-modal`)).toBeInTheDocument();

Check failure on line 44 in superset-frontend/src/components/ConfirmStatusChange/ConfirmStatusChange.test.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Expect must be inside of a test block

Check failure on line 44 in superset-frontend/src/components/ConfirmStatusChange/ConfirmStatusChange.test.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

'getByTestId' is not defined
});

test('calls the function on confirm', async () => {
const { getByTestId, getByRole } = render(

Check failure on line 48 in superset-frontend/src/components/ConfirmStatusChange/ConfirmStatusChange.test.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

'render' is not defined
<ConfirmStatusChange {...mockedProps}>
{confirm => (
<>
<Button data-test="btn1" onClick={() => confirm('foo')} />
</>
)}
</ConfirmStatusChange>,
);

fireEvent.click(getByTestId('btn1'));

expect(wrapper.find(Modal)).toExist();
});
const confirmInput = getByTestId('delete-modal-input');
fireEvent.change(confirmInput, { target: { value: 'DELETE' } });

it('calls the function on confirm', () => {
act(() => {
wrapper.find(Button).last().props().onClick();
});
const confirmButton = getByRole('button', { name: 'Delete' });
fireEvent.click(confirmButton);

expect(mockedProps.onConfirm).toHaveBeenCalledWith('foo');
});
await waitFor(() => expect(mockedProps.onConfirm).toHaveBeenCalledTimes(1));
expect(mockedProps.onConfirm).toHaveBeenCalledWith('foo');
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ test('Calling "onConfirm" only after typing "delete" in the input', () => {
expect(props.onConfirm).toBeCalledTimes(0);

// do not execute "onConfirm" if you have not typed "delete"
userEvent.click(screen.getByText('delete'));
userEvent.click(screen.getByText('Delete'));
expect(props.onConfirm).toBeCalledTimes(0);

// execute "onConfirm" if you have typed "delete"
userEvent.type(screen.getByTestId('delete-modal-input'), 'delete');
userEvent.click(screen.getByText('delete'));
userEvent.click(screen.getByText('Delete'));
expect(props.onConfirm).toBeCalledTimes(1);

// confirm input has been cleared
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/DeleteModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function DeleteModal({
disablePrimaryButton={disableChange}
onHide={hide}
onHandledPrimaryAction={confirm}
primaryButtonName={t('delete')}
primaryButtonName={t('Delete')}
primaryButtonType="danger"
show={open}
title={title}
Expand Down

0 comments on commit d43e992

Please sign in to comment.