Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update tab set value #750

Merged
merged 3 commits into from
May 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add setGroupEditorValue test case
  • Loading branch information
Zaoei committed May 25, 2022
commit 25717bd4815aec36e369b0e27eb7cf16c89725d5
34 changes: 34 additions & 0 deletions src/services/workbench/__tests__/editorService.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { container } from 'tsyringe';
import { EditorEvent, IEditorTab } from 'mo/model';
import { expectFnCalled } from '@test/utils';
import { modules } from 'mo/services/builtinService/const';
import { editor as MonacoEditor } from 'mo/monaco';
import { cloneDeep } from 'lodash';

describe('Test EditorService', () => {
Expand Down Expand Up @@ -155,6 +156,39 @@ describe('Test EditorService', () => {
).toBe('updated1');
});

test('Set the editor text for a specific group', () => {
const editor = new EditorService();
const tabData = {
...mockTab,
data: {
value: 'tabData',
},
};
editor.open(tabData);
const { groups } = editor.getState();
if (groups) {
const modifyText = 'newValue';
const editorData = {
value: '',
};
const editorInstance = {} as MonacoEditor.IStandaloneCodeEditor;
editorInstance.getModel = jest.fn(() => {
return {
getValue: () => editorData.value,
setValue: (newValue: string) => {
editorData.value = newValue;
},
} as MonacoEditor.ITextModel;
});

groups[0].editorInstance = editorInstance;
editor.setGroupEditorValue(groups[0], modifyText);
expect(groups[0].editorInstance?.getModel()?.getValue()).toBe(
modifyText
);
}
});

test('Close a tab', () => {
const editor: any = new EditorService();
editor.disposeModel = jest.fn();
Expand Down