Skip to content

Commit

Permalink
test: improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung committed Sep 2, 2021
1 parent 06f2aac commit 573bdc5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 66 deletions.
95 changes: 32 additions & 63 deletions src/workbench/sidebar/__tests__/editorTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@ const PaneEditorTree = (props: Omit<IOpenEditProps, 'panel'>) => {
return <EditorTree panel={{ id: 'test', name: 'test' }} {...props} />;
};

const mockTab1 = {
id: 'tab1',
name: 'tab1',
data: {
path: 'tab',
},
};

const mockTab2 = {
id: 'tab2',
name: 'tab2',
data: {
path: 'tab',
},
};
const TAB1_PATH = `${mockTab1.data.path}/${mockTab1.name}`;
const TAB2_PATH = `${mockTab2.data.path}/${mockTab2.name}`;

const mockGroups = [
{
id: 1,
tab: {
id: 'tab1',
name: 'tab1',
},
data: [
{
id: 'tab1',
name: 'tab1',
data: {
path: 'tab',
},
},
{
id: 'tab2',
name: 'tab2',
data: {
path: 'tab',
},
},
],
data: [mockTab1, mockTab2],
},
];

Expand Down Expand Up @@ -144,10 +147,10 @@ describe('The EditorTree Component', () => {
/>
);

const tab1 = getByTitle('tab/tab1');
const tab1 = getByTitle(TAB1_PATH);
fireEvent.click(tab1.querySelector('span.codicon-close')!);

expect(testFn.mock.calls[0][0]).toBe('tab1');
expect(testFn.mock.calls[0][0]).toBe(mockTab1.name);
expect(testFn.mock.calls[0][1]).toBe(1);
});
});
Expand All @@ -167,7 +170,7 @@ describe('The EditorTree Component', () => {
/>
);

const tab1 = getByTitle('tab/tab1');
const tab1 = getByTitle(TAB1_PATH);
fireEvent.contextMenu(tab1);

const menu = getByRole('menu');
Expand All @@ -179,13 +182,7 @@ describe('The EditorTree Component', () => {
expect.objectContaining(contextMenu)
);
expect(contextMenuFn.mock.calls[0][1]).toEqual(1);
expect(contextMenuFn.mock.calls[0][2]).toEqual({
id: 'tab1',
name: 'tab1',
data: {
path: 'tab',
},
});
expect(contextMenuFn.mock.calls[0][2]).toEqual(mockTab1);
});
});

Expand All @@ -199,12 +196,12 @@ describe('The EditorTree Component', () => {
/>
);

const tab1 = getByTitle('tab/tab1');
const tab1 = getByTitle(TAB1_PATH);
fireEvent.click(tab1);
// same current tab won't triiger onSelect event
expect(selectFn).not.toBeCalled();

const tab2 = getByTitle('tab/tab2');
const tab2 = getByTitle(TAB2_PATH);
fireEvent.click(tab2);
});
});
Expand Down Expand Up @@ -241,45 +238,15 @@ const multipleGroups = [
id: 'tab1',
name: 'tab1',
},
data: [
{
id: 'tab1',
name: 'tab1',
data: {
path: 'tab',
},
},
{
id: 'tab2',
name: 'tab2',
data: {
path: 'tab',
},
},
],
data: [mockTab1, mockTab2],
},
{
id: 2,
tab: {
id: 'tab1',
name: 'tab1',
},
data: [
{
id: 'tab1',
name: 'tab1',
data: {
path: 'tab',
},
},
{
id: 'tab2',
name: 'tab2',
data: {
path: 'tab',
},
},
],
data: [mockTab1, mockTab2],
},
];

Expand Down Expand Up @@ -316,8 +283,8 @@ describe('The EditorTree Component With multiple groups', () => {
(group1.nextElementSibling! as HTMLDivElement).focus
).toBeTruthy();

expect(selectFn.mock.calls[0][0]).toBe('tab1');
expect(selectFn.mock.calls[0][1]).toBe(1);
expect(selectFn.mock.calls[0][0]).toBe(mockTab1.name);
expect(selectFn.mock.calls[0][1]).toBe(multipleGroups[0].id);
});
});

Expand Down Expand Up @@ -350,7 +317,9 @@ describe('The EditorTree Component With multiple groups', () => {
expect(contextMenuFn.mock.calls[0][0]).toEqual(
expect.objectContaining(contextMenu)
);
expect(contextMenuFn.mock.calls[0][1]).toEqual(1);
expect(contextMenuFn.mock.calls[0][1]).toEqual(
multipleGroups[0].id
);
expect(contextMenuFn.mock.calls[0][2]).toBeUndefined();
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/workbench/sidebar/explore/editorTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ const EditorTree = (props: IOpenEditProps) => {
return (
<div
title={
file.data?.path
? `${file.data?.path}/${file.name}`
: undefined
file.data?.path &&
`${file.data?.path}/${file.name}`
}
className={classNames(
editorTreeItemClassName,
Expand Down

0 comments on commit 573bdc5

Please sign in to comment.