Skip to content

Commit

Permalink
test: improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung committed Jul 12, 2022
1 parent f9a92b0 commit f75e2db
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion src/workbench/editor/__tests__/group.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'reflect-metadata';
import React from 'react';
import React, { useRef } from 'react';
import { render, cleanup, fireEvent, waitFor } from '@testing-library/react';
import { tabItemActiveClassName } from 'mo/components/tabs/tab';

Expand Down Expand Up @@ -152,4 +152,83 @@ describe('The Editor Component', () => {

expect(renderDiv?.innerHTML).toEqual(TEST_ID);
});

test('Should update editor props', () => {
const fn = jest.fn();
const { rerender } = render(
<EditorGroup
id="test"
editorOptions={{
minimap: {
enabled: false,
},
}}
isActiveGroup={true}
onClickActions={jest.fn()}
onChangeEditorProps={fn}
menu={menuData}
data={tabData}
/>
);

rerender(
<EditorGroup
id="test"
editorOptions={{
minimap: {
enabled: true,
},
}}
isActiveGroup={true}
onClickActions={jest.fn()}
onChangeEditorProps={fn}
menu={menuData}
data={tabData}
/>
);

expect(fn).toBeCalled();
});

test('Should scroll to view', () => {
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
configurable: true,
value: 500,
});

Object.defineProperty(HTMLElement.prototype, 'offsetLeft', {
configurable: true,
value: 1000,
});

const mockScrollToFn = jest.fn();
(useRef as jest.Mock).mockReturnValueOnce({
current: { scrollTo: mockScrollToFn },
});

render(
<EditorGroup
id="test"
currentGroup={{
id: 'test',
}}
tab={{
id: '1',
}}
editorOptions={{
minimap: {
enabled: false,
},
}}
isActiveGroup={true}
onClickActions={jest.fn()}
menu={menuData}
data={tabData}
/>
);

expect(mockScrollToFn).toBeCalled();
expect(mockScrollToFn.mock.calls[0][0]).toBe(1000);
expect(mockScrollToFn.mock.calls[0][1]).toBe(0);
});
});

0 comments on commit f75e2db

Please sign in to comment.