From c6f7276ad7c2d8af7ca10d0176035bd231b181f8 Mon Sep 17 00:00:00 2001 From: Wenzhao Hu <12122021+wzhudev@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:50:00 +0800 Subject: [PATCH] fix: fix filter test --- .../src/services/command/command.service.ts | 4 +++- .../__tests__/sheets-filter.command.spec.ts | 17 +++++++++----- .../__tests__/sheets-filter.operation.spec.ts | 12 +++++----- .../__tests__/sheets-filter.menu.spec.ts | 8 +++++-- .../sheets-filter-panel.service.spec.ts | 22 ++++++++----------- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/packages/core/src/services/command/command.service.ts b/packages/core/src/services/command/command.service.ts index c7c20462214..120c2c86f93 100644 --- a/packages/core/src/services/command/command.service.ts +++ b/packages/core/src/services/command/command.service.ts @@ -370,13 +370,15 @@ export class CommandService extends Disposable implements ICommandService { return result; } + throw new Error(`[CommandService]: command "${id}" is not registered.`); } catch (error) { + this._logService.error(error); + if (error instanceof CustomCommandExecutionError) { // If need custom logic, can add it here return false as R; } else { - this._logService.error(error); throw error; } } diff --git a/packages/sheets-filter-ui/src/commands/commands/__tests__/sheets-filter.command.spec.ts b/packages/sheets-filter-ui/src/commands/commands/__tests__/sheets-filter.command.spec.ts index e7bbdc07ce0..9e93c0d5ad8 100644 --- a/packages/sheets-filter-ui/src/commands/commands/__tests__/sheets-filter.command.spec.ts +++ b/packages/sheets-filter-ui/src/commands/commands/__tests__/sheets-filter.command.spec.ts @@ -14,17 +14,17 @@ * limitations under the License. */ -import type { Dependency, IRange, IWorkbookData } from '@univerjs/core'; -import { AuthzIoLocalService, IAuthzIoService, ICommandService, Inject, Injector, IUniverInstanceService, LocaleType, Plugin, RANGE_TYPE, RedoCommand, UndoCommand, Univer, UniverInstanceType } from '@univerjs/core'; +import type { Dependency, IRange, IWorkbookData, Workbook } from '@univerjs/core'; import type { ISetRangeValuesCommandParams } from '@univerjs/sheets'; -import { RangeProtectionRuleModel, RefRangeService, SetRangeValuesCommand, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets'; import type { FilterModel, ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter'; +import type { ISetSheetsFilterCriteriaCommandParams } from '../sheets-filter.command'; +import { AuthzIoLocalService, IAuthzIoService, ICommandService, Inject, Injector, IUniverInstanceService, LocaleType, Plugin, RANGE_TYPE, RedoCommand, UndoCommand, Univer, UniverInstanceType } from '@univerjs/core'; +import { RangeProtectionRuleModel, RefRangeService, SetRangeValuesCommand, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets'; import { SetSheetsFilterRangeMutation, SheetsFilterService, UniverSheetsFilterPlugin } from '@univerjs/sheets-filter'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { IMessageService } from '@univerjs/ui'; import { MockMessageService } from '@univerjs/ui/services/message/__testing__/mock-message.service.js'; -import type { ISetSheetsFilterCriteriaCommandParams } from '../sheets-filter.command'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { ClearSheetsFilterCriteriaCommand, ReCalcSheetsFilterCommand, RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand, SmartToggleSheetsFilterCommand } from '../sheets-filter.command'; function testWorkbookDataFactory(): IWorkbookData { @@ -83,6 +83,7 @@ function createFilterCommandTestBed() { class SheetsFilterCommandTestPlugin extends Plugin { static override pluginName = 'sheets-filter-command-test'; static override type = UniverInstanceType.UNIVER_SHEET; + constructor(_config: unknown, @Inject(Injector) protected readonly _injector: Injector) { super(); } @@ -100,13 +101,17 @@ function createFilterCommandTestBed() { [RangeProtectionRuleModel], [IMessageService, { useClass: MockMessageService }], ] as Dependency[]).forEach((d) => this._injector.add(d)); + + this._injector.get(SheetInterceptorService); + this._injector.get(WorkbookPermissionService); + this._injector.get(WorksheetPermissionService); } } univer.registerPlugin(UniverSheetsFilterPlugin); univer.registerPlugin(SheetsFilterCommandTestPlugin); - univer.createUniverSheet(testWorkbookDataFactory()); + univer.createUnit(UniverInstanceType.UNIVER_SHEET, testWorkbookDataFactory()); const commandService = get(ICommandService); [ diff --git a/packages/sheets-filter-ui/src/commands/operations/__tests__/sheets-filter.operation.spec.ts b/packages/sheets-filter-ui/src/commands/operations/__tests__/sheets-filter.operation.spec.ts index 163c8c8a803..5774226ef02 100644 --- a/packages/sheets-filter-ui/src/commands/operations/__tests__/sheets-filter.operation.spec.ts +++ b/packages/sheets-filter-ui/src/commands/operations/__tests__/sheets-filter.operation.spec.ts @@ -14,15 +14,15 @@ * limitations under the License. */ -import type { Dependency, IOperation, IWorkbookData } from '@univerjs/core'; -import { CommandType, ICommandService, IContextService, Inject, Injector, LocaleService, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; +import type { Dependency, IOperation, IWorkbookData, Workbook } from '@univerjs/core'; import type { ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter'; +import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui'; +import { CommandType, ICommandService, IContextService, Inject, Injector, LocaleService, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; +import { RefRangeService, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets'; import { SetSheetsFilterRangeMutation, UniverSheetsFilterPlugin } from '@univerjs/sheets-filter'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { RefRangeService, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets'; -import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui'; -import { CloseFilterPanelOperation, FILTER_PANEL_OPENED_KEY, OpenFilterPanelOperation } from '../sheets-filter.operation'; import { SheetsFilterPanelService } from '../../../services/sheets-filter-panel.service'; +import { CloseFilterPanelOperation, FILTER_PANEL_OPENED_KEY, OpenFilterPanelOperation } from '../sheets-filter.operation'; const SetCellEditVisibleOperation: IOperation = { id: 'sheet.operation.set-cell-edit-visible', @@ -85,7 +85,7 @@ function createFilterOperationTestBed() { univer.registerPlugin(UniverSheetsFilterPlugin); univer.registerPlugin(SheetsFilterOperationTestPlugin); - univer.createUniverSheet(testWorkbookDataFactory()); + univer.createUnit(UniverInstanceType.UNIVER_SHEET, testWorkbookDataFactory()); get(LocaleService).load({}); diff --git a/packages/sheets-filter-ui/src/controllers/__tests__/sheets-filter.menu.spec.ts b/packages/sheets-filter-ui/src/controllers/__tests__/sheets-filter.menu.spec.ts index a814387b3ff..075be0b5787 100644 --- a/packages/sheets-filter-ui/src/controllers/__tests__/sheets-filter.menu.spec.ts +++ b/packages/sheets-filter-ui/src/controllers/__tests__/sheets-filter.menu.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { IWorkbookData } from '@univerjs/core'; +import type { IWorkbookData, Workbook } from '@univerjs/core'; import type { ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter'; import { AuthzIoLocalService, DisposableCollection, IAuthzIoService, ICommandService, Inject, Injector, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; import { ExclusiveRangeService, IExclusiveRangeService, RangeProtectionRuleModel, RefRangeService, SetWorksheetActiveOperation, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets'; @@ -86,13 +86,17 @@ function createSheetsFilterMenuTestBed() { OpenFilterPanelOperation, CloseFilterPanelOperation, ].forEach((command) => commandService.registerCommand(command)); + + this._injector.get(SheetInterceptorService); + this._injector.get(WorkbookPermissionService); + this._injector.get(WorksheetPermissionService); } } univer.registerPlugin(TestPlugin); univer.registerPlugin(UniverSheetsFilterPlugin); - const sheet = univer.createUniverSheet(TEST_WORKBOOK_DATA_DEMO); + const sheet = univer.createUnit(UniverInstanceType.UNIVER_SHEET, TEST_WORKBOOK_DATA_DEMO); return { univer, get, sheet }; } diff --git a/packages/sheets-filter-ui/src/services/__tests__/sheets-filter-panel.service.spec.ts b/packages/sheets-filter-ui/src/services/__tests__/sheets-filter-panel.service.spec.ts index f53791d631d..252d8567eef 100644 --- a/packages/sheets-filter-ui/src/services/__tests__/sheets-filter-panel.service.spec.ts +++ b/packages/sheets-filter-ui/src/services/__tests__/sheets-filter-panel.service.spec.ts @@ -14,20 +14,20 @@ * limitations under the License. */ -import type { Dependency, IOperation, IWorkbookData } from '@univerjs/core'; +import type { Dependency, IOperation, IWorkbookData, Workbook } from '@univerjs/core'; +import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui'; +import type { IOpenFilterPanelOperationParams } from '../../commands/operations/sheets-filter.operation'; +import type { IFilterConditionFormParams } from '../../models/conditions'; import { CommandType, ICommandService, Inject, Injector, LocaleService, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; import { RefRangeService, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets'; -import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest'; import { CustomFilterOperator, SheetsFilterService, UniverSheetsFilterPlugin } from '@univerjs/sheets-filter'; -import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui'; -import { ByConditionsModel, ByValuesModel, FilterBy, SheetsFilterPanelService } from '../sheets-filter-panel.service'; -import type { IOpenFilterPanelOperationParams } from '../../commands/operations/sheets-filter.operation'; -import { CloseFilterPanelOperation, OpenFilterPanelOperation } from '../../commands/operations/sheets-filter.operation'; +import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest'; import { E_ITEMS, ITEMS, WithCustomFilterModelFactory, WithMergedCellFilterFactory, WithMultiEmptyCellsModelFactory, WithTwoFilterColumnsFactory, WithValuesAndEmptyFilterModelFactory, WithValuesFilterModelFactory } from '../../__testing__/data'; -import type { IFilterConditionFormParams } from '../../models/conditions'; +import { SetSheetsFilterCriteriaCommand } from '../../commands/commands/sheets-filter.command'; +import { CloseFilterPanelOperation, OpenFilterPanelOperation } from '../../commands/operations/sheets-filter.operation'; import { FilterConditionItems } from '../../models/conditions'; import { ExtendCustomFilterOperator } from '../../models/extended-operators'; -import { SetSheetsFilterCriteriaCommand } from '../../commands/commands/sheets-filter.command'; +import { ByConditionsModel, ByValuesModel, FilterBy, SheetsFilterPanelService } from '../sheets-filter-panel.service'; const SetCellEditVisibleOperation: IOperation = { id: 'sheet.operation.set-cell-edit-visible', @@ -65,11 +65,7 @@ function createSheetsFilterPanelServiceTestBed(workbookData: IWorkbookData) { univer.registerPlugin(UniverSheetsFilterPlugin); univer.registerPlugin(SheetsFilterPanelTestPlugin); - univer.createUniverSheet(workbookData); - - // It should be registered later in avoid of time sequence problem. - // injector.add([ISnapshotPersistenceService, { useClass: LocalSnapshotService }]); - // injector.get(ISnapshotPersistenceService); + univer.createUnit(UniverInstanceType.UNIVER_SHEET, workbookData); const commandService = get(ICommandService);