Skip to content

Commit

Permalink
fix: fix API calling in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Oct 21, 2024
1 parent 9634032 commit 6f6578f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 50 deletions.
28 changes: 1 addition & 27 deletions e2e/visual-comparison/sheets/sheets-gridlines.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('sheets no gridlines', async () => {
await page.waitForTimeout(2000);
await page.evaluate(() => window.E2EControllerAPI.loadDefaultSheet());
await page.waitForTimeout(5000);
await page.evaluate(() => window.univerAPI.setGridlineVisible(false));
await page.evaluate(() => window.univerAPI.getActiveWorkbook().getActiveSheet().setGridlinesVisible(false));
await page.waitForTimeout(1000);

const filename = generateSnapshotName('sheets-no-gridlines');
Expand All @@ -45,29 +45,3 @@ test('sheets no gridlines', async () => {
expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });
});

test('sheets gridlines color', async () => {
const browser = await chromium.launch({
headless: !!isCI, // Set to false to see the browser window
});
const context = await browser.newContext({
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 2, // Set your desired DPR
});
const page = await context.newPage();
await page.goto('http://localhost:3000/sheets/');
await page.waitForTimeout(2000);
await page.evaluate(() => window.E2EControllerAPI.loadDefaultSheet());
await page.waitForTimeout(5000);
await page.evaluate(() => window.univerAPI.setGridlineColor('rgb(200, 0, 0)'));
await page.waitForTimeout(1000);

const filename = generateSnapshotName('sheets-gridlines-color');
const screenshot = await page.screenshot({
mask: [
page.locator('.univer-headerbar'),
],
fullPage: true,
});
expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });
});

22 changes: 1 addition & 21 deletions packages/facade/src/apis/facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ import type {
SpreadsheetRowHeader,
} from '@univerjs/engine-render';
import type { ISocket } from '@univerjs/network';
import type { IToggleGridlinesCommandParams } from '@univerjs/sheets';
import type { ISetCrosshairHighlightColorOperationParams } from '@univerjs/sheets-crosshair-highlight';

import type { IRegisterFunctionParams } from '@univerjs/sheets-formula';
import type { ISetGridlineColorOperationParams } from '@univerjs/sheets-ui';
import {
BorderStyleTypes,
debounce,
Expand All @@ -59,10 +57,9 @@ import {
import { SetFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { IRenderManagerService } from '@univerjs/engine-render';
import { ISocketService, WebSocketService } from '@univerjs/network';
import { ToggleGridlinesCommand } from '@univerjs/sheets';
import { DisableCrosshairHighlightOperation, EnableCrosshairHighlightOperation, SetCrosshairHighlightColorOperation } from '@univerjs/sheets-crosshair-highlight';
import { IRegisterFunctionService, RegisterFunctionService } from '@univerjs/sheets-formula';
import { SetGridlineColorOperation, SHEET_VIEW_KEY } from '@univerjs/sheets-ui';
import { SHEET_VIEW_KEY } from '@univerjs/sheets-ui';
import { CopyCommand, PasteCommand } from '@univerjs/ui';
import { FDocument } from './docs/f-document';
import { FHooks } from './f-hooks';
Expand Down Expand Up @@ -529,23 +526,6 @@ export class FUniver {
} as ISetCrosshairHighlightColorOperationParams);
}

/**
* Show or hide grid line.
* @param {boolean} visible If the grid line should be visible.
*/
setGridlinesVisible(visible?: boolean): Promise<boolean> {
return this._commandService.executeCommand(ToggleGridlinesCommand.id, {
showGridlines: visible,
} as IToggleGridlinesCommandParams);
}

/**
* Set the color of the gridlines.
*/
setGridlinesColor(color: string): void {
this._commandService.executeCommand(SetGridlineColorOperation.id, { color } as ISetGridlineColorOperationParams);
}

// #endregion

/**
Expand Down
16 changes: 14 additions & 2 deletions packages/facade/src/apis/sheets/f-worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

import type { ICellData, IDisposable, IFreeze, IRange, Nullable, Workbook, Worksheet } from '@univerjs/core';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import type { ISetRangeValuesMutationParams, IToggleGridlinesCommandParams } from '@univerjs/sheets';
import type { IDataValidationResCache } from '@univerjs/sheets-data-validation';
import type { FilterModel } from '@univerjs/sheets-filter';

import type { FWorkbook, IFICanvasFloatDom } from './f-workbook';
import { Direction, ICommandService, Inject, Injector, ObjectMatrix, RANGE_TYPE } from '@univerjs/core';
import { DataValidationModel } from '@univerjs/data-validation';
import { deserializeRangeWithSheet } from '@univerjs/engine-formula';
import { copyRangeStyles, InsertColCommand, InsertRowCommand, MoveColsCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, SetColHiddenCommand, SetColWidthCommand, SetFrozenCommand, SetRangeValuesMutation, SetRowHeightCommand, SetRowHiddenCommand, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetRowIsAutoHeightCommand, SheetsSelectionsService } from '@univerjs/sheets';
import { copyRangeStyles, InsertColCommand, InsertRowCommand, MoveColsCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, SetColHiddenCommand, SetColWidthCommand, SetFrozenCommand, SetRangeValuesMutation, SetRowHeightCommand, SetRowHiddenCommand, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetRowIsAutoHeightCommand, SheetsSelectionsService, ToggleGridlinesCommand } from '@univerjs/sheets';
import { SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';
import { SheetCanvasFloatDomManagerService } from '@univerjs/sheets-drawing-ui';
import { SheetsFilterService } from '@univerjs/sheets-filter';
Expand Down Expand Up @@ -1037,6 +1037,18 @@ export class FWorksheet {
return freeze.startRow;
}

/**
* Show or hide grid line.
* @param {boolean} visible If the grid line should be visible.
*/
setGridlinesVisible(visible?: boolean): Promise<boolean> {
return this._commandService.executeCommand(ToggleGridlinesCommand.id, {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
showGridlines: visible,
} as IToggleGridlinesCommandParams);
}

/**
* Subscribe to the cell data change event.
* @param callback - The callback function to be executed when the cell data changes.
Expand Down

0 comments on commit 6f6578f

Please sign in to comment.