Skip to content

Commit

Permalink
fix: fix filter test
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Oct 10, 2024
1 parent 5c14d45 commit c6f7276
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/services/command/command.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, testWorkbookDataFactory());

const commandService = get(ICommandService);
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEditorBridgeServiceVisibleParam> = {
id: 'sheet.operation.set-cell-edit-visible',
Expand Down Expand Up @@ -85,7 +85,7 @@ function createFilterOperationTestBed() {
univer.registerPlugin(UniverSheetsFilterPlugin);
univer.registerPlugin(SheetsFilterOperationTestPlugin);

univer.createUniverSheet(testWorkbookDataFactory());
univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, testWorkbookDataFactory());

get(LocaleService).load({});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, TEST_WORKBOOK_DATA_DEMO);

return { univer, get, sheet };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEditorBridgeServiceVisibleParam> = {
id: 'sheet.operation.set-cell-edit-visible',
Expand Down Expand Up @@ -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<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, workbookData);

const commandService = get(ICommandService);

Expand Down

0 comments on commit c6f7276

Please sign in to comment.