Skip to content

Commit

Permalink
test: add unit tests for the EditorService (#376)
Browse files Browse the repository at this point in the history
* docs: add API comments

* refactor: rename the closeOthers to closeOther

* refactor: return the updated tab

* test: add unit tests for the EditorService

* fix: add the activeTab argument in the EditorGroupModel constructor

* test: add case for the activeTab

* refactor: declare the testFn typing as jest.Mock

* refactor: replace the default jest.fn() with the expectFnCalled
  • Loading branch information
wewoor authored Sep 1, 2021
1 parent 5895c8e commit 3ba17bd
Show file tree
Hide file tree
Showing 6 changed files with 561 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/controller/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface IEditorController {
onCloseTab?: (tabId: string, group: number) => void;
onCloseToLeft?: (tab: IEditorTab, group: number) => void;
onCloseToRight?: (tab: IEditorTab, group: number) => void;
onCloseOthers?: (tab: IEditorTab, group: number) => void;
onCloseOther?: (tab: IEditorTab, group: number) => void;
onCloseSaved?: (group: number) => void;
onChangeEditorProps?: (
preProps: IMonacoEditorProps,
Expand Down Expand Up @@ -88,7 +88,7 @@ export class EditorController extends Controller implements IEditorController {
break;
}
case EDITOR_MENU_CLOSE_OTHERS: {
this.onCloseOthers(tabItem!, groupId);
this.onCloseOther(tabItem!, groupId);
break;
}
case EDITOR_MENU_CLOSE_ALL: {
Expand Down Expand Up @@ -132,9 +132,9 @@ export class EditorController extends Controller implements IEditorController {
this.emit(EditorEvent.OnCloseToLeft, tabItem, groupId);
};

public onCloseOthers = (tabItem: IEditorTab, groupId: number) => {
this.editorService.closeOthers(tabItem, groupId);
this.emit(EditorEvent.OnCloseOthers, tabItem, groupId);
public onCloseOther = (tabItem: IEditorTab, groupId: number) => {
this.editorService.closeOther(tabItem, groupId);
this.emit(EditorEvent.OnCloseOther, tabItem, groupId);
};

public onMoveTab = (updateTabs: IEditorTab<any>[], groupId: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/editorTree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ExtendsEditorTree: IExtension = {
});

molecule.editorTree.onCloseOthers((tabItem, groupId) => {
molecule.editor.closeOthers(tabItem, groupId);
molecule.editor.closeOther(tabItem, groupId);
molecule.explorer.forceUpdate();
});

Expand Down
11 changes: 7 additions & 4 deletions src/model/workbench/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { editor as MonacoEditor } from 'monaco-editor';
export enum EditorEvent {
OnCloseTab = 'editor.closeTab',
OnCloseAll = 'editor.closeAll',
OnCloseOthers = 'editor.closeOthers',
OnCloseOther = 'editor.closeOther',
OnCloseToLeft = 'editor.closeToLeft',
OnCloseToRight = 'editor.closeToRight',
OnMoveTab = 'editor.moveTab',
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface IEditor {
/**
* Current editor group
*/
current?: IEditorGroup | null;
current?: IEditorGroup;
/**
* Editor Groups
*/
Expand Down Expand Up @@ -143,10 +143,12 @@ export class EditorGroupModel<E = any, T = any> implements IEditorGroup<E, T> {
actions: IEditorActionsProps[];
menu: IMenuItemProps[];
editorInstance: E | undefined;
activeTab: string | undefined;

constructor(
id: number,
tab: IEditorTab<T>,
activeTab: string | undefined,
data: IEditorTab<T>[],
actions: IEditorActionsProps[] = getEditorInitialActions(),
menu: IMenuItemProps[] = getEditorInitialMenu(),
Expand All @@ -157,18 +159,19 @@ export class EditorGroupModel<E = any, T = any> implements IEditorGroup<E, T> {
this.menu = menu;
this.actions = actions;
this.tab = tab;
this.activeTab = activeTab;
this.editorInstance = editorInstance;
}
}

export class EditorModel implements IEditor {
public current: IEditorGroup | null;
public current: IEditorGroup | undefined;
public groups: IEditorGroup[];
public entry: React.ReactNode;
public editorOptions: IEditorOptions;

constructor(
current: IEditorGroup | null = null,
current: IEditorGroup | undefined = undefined,
groups: IEditorGroup[] = [],
entry: React.ReactNode,
editorOptions: IEditorOptions = BuiltInEditorOptions
Expand Down
Loading

0 comments on commit 3ba17bd

Please sign in to comment.