Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Oct 10, 2024
1 parent c6f7276 commit af430e7
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/* eslint-disable ts/no-explicit-any */

import type { Ctor, Dependency, DependencyIdentifier, DocumentDataModel, IDocumentData, Nullable } from '@univerjs/core';
import type { DocumentSkeleton, IRender, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import {
BooleanNumber,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
Expand All @@ -31,11 +33,9 @@ import {
UniverInstanceType,
} from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService } from '@univerjs/docs';

import { DocumentViewModel, IRenderManagerService } from '@univerjs/engine-render';
import { BehaviorSubject, takeUntil } from 'rxjs';

import type { Ctor, Dependency, DependencyIdentifier, DocumentDataModel, IDocumentData, Nullable } from '@univerjs/core';
import type { DocumentSkeleton, IRender, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { DocIMEInputManagerService } from '../../../services/doc-ime-input-manager.service';
import { DocStateChangeManagerService } from '../../../services/doc-state-change-manager.service';
import { DocSelectionRenderService } from '../../../services/selection/doc-selection-render.service';
Expand Down Expand Up @@ -124,6 +124,10 @@ export function createCommandTestBed(docData?: IDocumentData, dependencies?: Dep

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

override onReady(): void {
this._injector.get(DocStateChangeManagerService);
}
}

univer.registerPlugin(TestPlugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import type { DocumentDataModel, ICommand, Injector, IStyleBase, Univer } from '@univerjs/core';
import { BooleanNumber, ICommandService, IUniverInstanceService, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService, RichTextEditingMutation, SetTextSelectionsOperation } from '@univerjs/docs';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';

import type { DocumentDataModel, ICommand, Injector, IStyleBase, Univer } from '@univerjs/core';
import {
SetInlineFormatBoldCommand,
SetInlineFormatCommand,
Expand Down
9 changes: 9 additions & 0 deletions packages/facade/src/apis/__tests__/create-test-bed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:
});

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

this._injector.get(SheetInterceptorService);
this._injector.get(WorkbookPermissionService);
this._injector.get(WorksheetPermissionService);
this._injector.get(ConditionalFormattingService);
}

override onReady(): void {
this._injector.get(SheetsRenderService);
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/facade/src/apis/docs/__tests__/create-test-bed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export function createTestBed(documentConfig?: IDocumentData, dependencies?: Dep
renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_DOC, [DocSkeletonManagerService] as Dependency);
renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_DOC, [DocIMEInputManagerService] as Dependency);
}

override onReady(): void {
this._injector.get(DocStateChangeManagerService);
this._injector.get(DocsRenderService);
}
}

injector.get(LocaleService).load({ zhCN, enUS });
Expand Down
4 changes: 2 additions & 2 deletions packages/facade/src/apis/sheets/__tests__/f-range.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

/* eslint-disable ts/no-non-null-asserted-optional-chain */

import type { ICellData, Injector, IRange, IStyleData, Nullable } from '@univerjs/core';
import { DataValidationType, HorizontalAlign, ICommandService, IUniverInstanceService, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { FormulaDataModel } from '@univerjs/engine-formula';
import { AddWorksheetMergeCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';
import { AddSheetDataValidationCommand } from '@univerjs/sheets-data-validation';

import { AddSheetDataValidationCommand } from '@univerjs/sheets-data-validation';
import { ClearSheetsFilterCriteriaCommand, RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from '@univerjs/sheets-filter-ui';
import { beforeEach, describe, expect, it } from 'vitest';
import type { ICellData, Injector, IRange, IStyleData, Nullable } from '@univerjs/core';
import { createFacadeTestBed } from '../../__tests__/create-test-bed';
import { FUniver } from '../../facade';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
*/

import type { ICellData, Nullable, ObjectMatrix } from '@univerjs/core';
import { BooleanNumber, CellValueType, Disposable, ICommandService, Inject, Injector, RefAlias, toDisposable, Tools } from '@univerjs/core';
import type { IRemoveOtherFormulaMutationParams, ISetFormulaCalculationResultMutation, ISetOtherFormulaMutationParams } from '@univerjs/engine-formula';
import type { IConditionalFormattingFormulaMarkDirtyParams } from '../commands/mutations/formula-mark-dirty.mutation';
import { BooleanNumber, CellValueType, Disposable, ICommandService, Inject, Injector, RefAlias, toDisposable, Tools } from '@univerjs/core';

import {
IActiveDirtyManagerService,
RemoveOtherFormulaMutation,
SetFormulaCalculationResultMutation,
SetOtherFormulaMutation,
} from '@univerjs/engine-formula';

import { Subject } from 'rxjs';
import { bufferTime, filter, map } from 'rxjs/operators';
import type { IConditionalFormattingFormulaMarkDirtyParams } from '../commands/mutations/formula-mark-dirty.mutation';
import { ConditionalFormattingFormulaMarkDirty } from '../commands/mutations/formula-mark-dirty.mutation';
import { ConditionalFormattingViewModel } from '../models/conditional-formatting-view-model';
import { ConditionalFormattingRuleModel } from '../models/conditional-formatting-rule-model';
import { ConditionalFormattingViewModel } from '../models/conditional-formatting-view-model';
import { ConditionalFormattingService } from './conditional-formatting.service';

// eslint-disable-next-line ts/consistent-type-definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
injector.add([WorksheetProtectionRuleModel]);

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

this._injector.get(SheetInterceptorService);
this._injector.get(WorkbookPermissionService);
this._injector.get(WorksheetPermissionService);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
injector.add([IRefSelectionsService, { useClass: SheetsSelectionsService }]);

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

this._injector.get(SheetInterceptorService);
this._injector.get(WorkbookPermissionService);
this._injector.get(WorksheetPermissionService);
}

override onReady(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,23 @@ describe('Test auto fill with formula', () => {
[RangeProtectionRenderModel],
[SheetsRenderService, { useClass: mockSheetsRenderService }],
]);

univer = testBed.univer;
get = testBed.get;

commandService = get(ICommandService);
themeService = get(ThemeService);
themeService.setTheme(theme);
autoFillController = get(AutoFillController);

commandService.registerCommand(SetRangeValuesMutation);
commandService.registerCommand(SetSelectionsOperation);
commandService.registerCommand(AddWorksheetMergeMutation);
commandService.registerCommand(RemoveWorksheetMergeMutation);
commandService.registerCommand(AutoFillCommand);

get(FormulaAutoFillController);

getValues = (
startRow: number,
startColumn: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { ICellData, Injector, IObjectMatrixPrimitiveType, IWorkbookData, Nullable, Univer } from '@univerjs/core';
import type { ICellData, Injector, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core';
import type { IDeleteRangeMoveLeftCommandParams, IDeleteRangeMoveUpCommandParams, IInsertColCommandParams, IInsertRowCommandParams, IMoveColsCommandParams, IMoveRangeCommandParams, IMoveRowsCommandParams, InsertRangeMoveDownCommandParams, InsertRangeMoveRightCommandParams, IRemoveRowColCommandParams, IRemoveSheetCommandParams, ISetRangeValuesCommandParams, ISetWorksheetNameCommandParams } from '@univerjs/sheets';
import { CellValueType, Direction, ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core';
import { SetArrayFormulaDataMutation, SetFormulaDataMutation } from '@univerjs/engine-formula';
Expand Down Expand Up @@ -280,12 +280,12 @@ describe('Test insert function operation', () => {
endRow: number,
endColumn: number
) => Array<Array<Nullable<ICellData>>> | undefined;
let getCellData: () => IObjectMatrixPrimitiveType<Nullable<ICellData>> | undefined;

beforeEach(() => {
const testBed = createCommandTestBed(TEST_WORKBOOK_DATA_DEMO(), [
[UpdateFormulaController],
]);

univer = testBed.univer;
get = testBed.get;

Expand Down Expand Up @@ -334,14 +334,12 @@ describe('Test insert function operation', () => {
endColumn: number
): Array<Array<Nullable<ICellData>>> | undefined =>
get(IUniverInstanceService)
.getUniverSheetInstance('test')
.getUnit<Workbook>('test')
?.getSheetBySheetId('sheet1')
?.getRange(startRow, startColumn, endRow, endColumn)
.getValues();

getCellData = () => {
return get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1')?.getCellMatrix().clone();
};
get(UpdateFormulaController);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export function createMenuTestBed() {
injector.add([RangeProtectionCache]);
injector.add([RangeProtectionRuleModel]);
injector.add([RangeProtectionService]);

this._injector.get(SheetInterceptorService);
this._injector.get(WorkbookPermissionService);
this._injector.get(WorksheetPermissionService);
}
}

Expand Down

0 comments on commit af430e7

Please sign in to comment.