Skip to content

Commit

Permalink
fix: disable click event when action is disabled (#745)
Browse files Browse the repository at this point in the history
* fix: disable click event when action is disabled (#725)

* test: added EditorAction disable use cases
  • Loading branch information
Zaoei authored May 24, 2022
1 parent 7fd02ab commit ad0310d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/workbench/editor/__tests__/action.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { expectFnCalled } from '@test/utils';
import '@testing-library/jest-dom';

import EditorAction from '../action';
import { groupActionItemDisabledClassName } from '../base';

const current: IEditorActionsProps = {
id: '1',
Expand Down Expand Up @@ -71,4 +72,32 @@ describe('The Editor Component', () => {
expect(container.querySelector(`.codicon-warning`)).toBeInTheDocument();
expect(container.querySelectorAll(`.codicon-warning`)!.length).toBe(8);
});

test('The EditorAction item disabled', () => {
const mockAction: IEditorActionsProps[] = Array(8)
.fill(1)
.map((_, index) => ({
id: index.toString(),
place: 'outer',
icon: 'warning',
}));
mockAction[0].disabled = true;
const mockCallback = jest.fn();

const { container } = render(
<EditorAction
isActiveGroup={true}
actions={mockAction}
onClickActions={jest.fn()}
/>
);

const liDom = container.querySelector(
`.${groupActionItemDisabledClassName}`
);

expect(liDom).not.toBeNull();
liDom && fireEvent.click(liDom);
expect(mockCallback).not.toBeCalled();
});
});
4 changes: 3 additions & 1 deletion src/workbench/editor/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ function EditorAction(props: IEditorActionProps & IEditorController) {
outer.map((action) => (
<Tooltip key={action.id} overlay={action.title}>
<div
onClick={() => handleActionsClick(action)}
onClick={() =>
!action.disabled && handleActionsClick(action)
}
className={classNames(
groupActionsItemClassName,
action.disabled &&
Expand Down

0 comments on commit ad0310d

Please sign in to comment.