Skip to content

Commit

Permalink
fix: prevent call loadData when editing (#789)
Browse files Browse the repository at this point in the history
* fix: prevent call loadData when editing

* test: improve test coverage
  • Loading branch information
mortalYoung authored Aug 25, 2022
1 parent 4b26c14 commit 80d99bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/workbench/sidebar/__tests__/folderTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ describe('The FolderTree Component', () => {
).toContain(folderTreeEditClassName);
});

test('Should NOT call loadData in editing', () => {
const mockFn = jest.fn(() => Promise.resolve());
const { getByRole } = render(
<FolderTreeViewPanel
folderTree={{
data: [{ ...mockTreeData[0], children: [mockEditFile] }],
}}
onLoadData={mockFn}
/>
);

const input = getByRole('input') as HTMLInputElement;
expect(input).toBeInTheDocument();

fireEvent.click(input);
expect(mockFn).not.toBeCalled();
});

test('Should support to update file name via blur or keypress', () => {
const mockFn = jest.fn();
const { getByRole } = render(
Expand Down
1 change: 1 addition & 0 deletions src/workbench/sidebar/explore/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
autoComplete="off"
autoFocus
onBlur={(e) => handleInputBlur(e, node)}
onClick={(e) => e.stopPropagation()}
/>
) : (
name!
Expand Down
4 changes: 2 additions & 2 deletions src/workbench/sidebar/explore/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
font-family: inherit;
font-size: 13px;
height: 20px;
left: -2px;
left: 0;
margin: 0;
outline: none;
padding: 0;
position: relative;
width: 100%;
width: calc(100% - 2px);

&:focus,
&:active {
Expand Down

0 comments on commit 80d99bc

Please sign in to comment.