Skip to content
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 @@ -522,12 +522,15 @@ test('should disable both buttons when no actions available', () => {
expect(onRedo).not.toHaveBeenCalled();
});

test('should render the "Discard" button as disabled', () => {
test('should render an enabled "Exit edit mode" button when there are no unsaved changes', () => {
setup(editableState);
expect(screen.getByRole('button', { name: /discard/i })).toBeDisabled();
expect(screen.getByRole('button', { name: /exit edit mode/i })).toBeEnabled();
expect(
screen.queryByRole('button', { name: /discard/i }),
).not.toBeInTheDocument();
});

test('should enable the "Discard" button when there are unsaved changes', () => {
test('should render an enabled "Discard" button when there are unsaved changes', () => {
const unsavedState = {
...editableState,
dashboardState: {
Expand All @@ -537,6 +540,9 @@ test('should enable the "Discard" button when there are unsaved changes', () =>
};
setup(unsavedState);
expect(screen.getByRole('button', { name: /discard/i })).toBeEnabled();
expect(
screen.queryByRole('button', { name: /exit edit mode/i }),
).not.toBeInTheDocument();
});

test('should render the "Save" button as disabled', () => {
Expand Down
7 changes: 4 additions & 3 deletions superset-frontend/src/dashboard/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,14 @@ const Header = (): JSX.Element => {
<Button
css={discardBtnStyle}
buttonSize="small"
disabled={!hasUnsavedChanges}
onClick={discardChanges}
buttonStyle="secondary"
data-test="discard-changes-button"
aria-label={t('Discard')}
aria-label={
hasUnsavedChanges ? t('Discard') : t('Exit edit mode')
}
>
{t('Discard')}
{hasUnsavedChanges ? t('Discard') : t('Exit edit mode')}
</Button>
<Button
css={saveBtnStyle}
Expand Down
Loading