Skip to content

Commit

Permalink
fix: set-frozen test case need ScrollManagerService -> SheetSkeletonM…
Browse files Browse the repository at this point in the history
…anagerService
  • Loading branch information
lumixraku committed May 30, 2024
1 parent becf0b8 commit 5b93b98
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/

import type { IWorkbookData } from '@univerjs/core';
import { ICommandService, LocaleType } from '@univerjs/core';
import { SetFrozenMutation, SetSelectionsOperation } from '@univerjs/sheets';
import { BooleanNumber, ICommandService, ILogService, IUniverInstanceService, LocaleService, LocaleType, LogLevel, Plugin, Tools, Univer, UniverInstanceType } from '@univerjs/core';
import { BorderStyleManagerService, SelectionManagerService, SetFrozenMutation, SetSelectionsOperation, SheetInterceptorService, SheetPermissionService } from '@univerjs/sheets';
// FIXME: should not import from the inside of the package
import type { ITestBed } from '@univerjs/sheets/commands/commands/__tests__/create-command-test-bed.js';
import { createCommandTestBed } from '@univerjs/sheets/commands/commands/__tests__/create-command-test-bed.js';

import enUS from '@univerjs/sheets/locale/en-US';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { ScrollManagerService } from '../../../services/scroll-manager.service';
import { ShortcutExperienceService } from '../../../services/shortcut-experience.service';
import {
Expand All @@ -29,6 +33,89 @@ import {
SetSelectionFrozenCommand,
} from '../set-frozen.command';
import { ExpandSelectionCommand, MoveSelectionCommand, SelectAllCommand } from '../set-selection.command';
import { SheetSkeletonManagerService } from '../../../services/sheet-skeleton-manager.service';

const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
id: 'test',
appVersion: '3.0.0-alpha',
sheets: {
sheet1: {
id: 'sheet1',
name: 'sheet1',
cellData: {
0: {
0: {
v: 'A1',
},
1: {
v: 'A2',
},
},
},
columnData: {
1: {
hd: BooleanNumber.FALSE,
},
},
rowData: {
1: {
hd: BooleanNumber.FALSE,
},
},
},
},
locale: LocaleType.ZH_CN,
name: '',
sheetOrder: [],
styles: {},
};

function createCommandTestBed2(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {
const univer = new Univer();
const injector = univer.__getInjector();

class TestPlugin extends Plugin {
static override pluginName = 'test-plugin';
static override type = UniverInstanceType.UNIVER_SHEET;

constructor(
_config: undefined,
@Inject(Injector) override readonly _injector: Injector
) {
super();

this._injector = _injector;
}

override onStarting(injector: Injector): void {
injector.add([SheetSkeletonManagerService]);
injector.add([SelectionManagerService]);
injector.add([BorderStyleManagerService]);
injector.add([SheetInterceptorService]);
injector.add([SheetPermissionService]);

dependencies?.forEach((d) => injector.add(d));
}
}

univer.registerPlugin(TestPlugin);
const sheet = univer.createUniverSheet(Tools.deepClone(workbookData || TEST_WORKBOOK_DATA_DEMO));

const univerInstanceService = injector.get(IUniverInstanceService);
univerInstanceService.focusUnit('test');
const logService = injector.get(ILogService);

logService.setLogLevel(LogLevel.SILENT); // change this to `LogLevel.VERBOSE` to debug tests via logs

const localeService = injector.get(LocaleService);
localeService.load({ enUS });

return {
univer,
get: injector.get.bind(injector),
sheet,
};
}

export function createSelectionCommandTestBed(workbookData?: IWorkbookData) {
const { univer, get, sheet } = createCommandTestBed(workbookData || SIMPLE_SELECTION_WORKBOOK_DATA, [
Expand All @@ -48,7 +135,7 @@ export function createSelectionCommandTestBed(workbookData?: IWorkbookData) {
}

export function createFrozenCommandTestBed(workbookData?: IWorkbookData) {
const { univer, get, sheet } = createCommandTestBed(workbookData || SIMPLE_SELECTION_WORKBOOK_DATA, [
const { univer, get, sheet } = createCommandTestBed2(workbookData || SIMPLE_SELECTION_WORKBOOK_DATA, [
[ShortcutExperienceService],
[ScrollManagerService],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ describe('Test commands used for change selections', () => {
sheetViewStartColumn: startColumn,
offsetX,
offsetY,
scrollLeft: 0,
scrollTop: 0,
...currentInfo,
});
};
Expand Down

0 comments on commit 5b93b98

Please sign in to comment.