Skip to content

Commit 80d99bc

Browse files
authored
fix: prevent call loadData when editing (#789)
* fix: prevent call loadData when editing * test: improve test coverage
1 parent 4b26c14 commit 80d99bc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/workbench/sidebar/__tests__/folderTree.test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ describe('The FolderTree Component', () => {
148148
).toContain(folderTreeEditClassName);
149149
});
150150

151+
test('Should NOT call loadData in editing', () => {
152+
const mockFn = jest.fn(() => Promise.resolve());
153+
const { getByRole } = render(
154+
<FolderTreeViewPanel
155+
folderTree={{
156+
data: [{ ...mockTreeData[0], children: [mockEditFile] }],
157+
}}
158+
onLoadData={mockFn}
159+
/>
160+
);
161+
162+
const input = getByRole('input') as HTMLInputElement;
163+
expect(input).toBeInTheDocument();
164+
165+
fireEvent.click(input);
166+
expect(mockFn).not.toBeCalled();
167+
});
168+
151169
test('Should support to update file name via blur or keypress', () => {
152170
const mockFn = jest.fn();
153171
const { getByRole } = render(

src/workbench/sidebar/explore/folderTree.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
205205
autoComplete="off"
206206
autoFocus
207207
onBlur={(e) => handleInputBlur(e, node)}
208+
onClick={(e) => e.stopPropagation()}
208209
/>
209210
) : (
210211
name!

src/workbench/sidebar/explore/style.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
font-family: inherit;
3535
font-size: 13px;
3636
height: 20px;
37-
left: -2px;
37+
left: 0;
3838
margin: 0;
3939
outline: none;
4040
padding: 0;
4141
position: relative;
42-
width: 100%;
42+
width: calc(100% - 2px);
4343

4444
&:focus,
4545
&:active {

0 commit comments

Comments
 (0)