Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: snapshot area #3715

Merged
merged 4 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,42 @@
import { chromium, expect, test } from '@playwright/test';
import { generateSnapshotName } from '../const';

const SHEET_MAIN_CANVAS_ID = '#univer-sheet-main-canvas';
const isCI = !!process.env.CI;
test('diff default sheet toolbar', 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(3000);

const filename = generateSnapshotName('default-sheet-fullpage');
const screenshot = await page.screenshot({
mask: [
page.locator('.univer-headerbar'),
],
fullPage: true,
});
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });
});
test('diff default sheet content', async ({ page }) => {
await page.goto('http://localhost:3000/sheets/');
await page.waitForTimeout(2000);

await page.evaluate(() => window.E2EControllerAPI.loadDefaultSheet());
await page.waitForTimeout(5000);
await page.waitForTimeout(2000);

await expect(page).toHaveScreenshot(generateSnapshotName('default-sheet'), { maxDiffPixels: 5 });
const filename = generateSnapshotName('default-sheet');
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });
});
const isCI = !!process.env.CI;

test('diff demo sheet content', async ({ page }) => {
let errored = false;
Expand All @@ -42,7 +68,9 @@ test('diff demo sheet content', async ({ page }) => {
await page.evaluate(() => window.E2EControllerAPI.loadDemoSheet());
await page.waitForTimeout(2000);

await expect(page).toHaveScreenshot(generateSnapshotName('demo-sheet'), { maxDiffPixels: 5 });
const filename = generateSnapshotName('demo-sheet');
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });
await page.waitForTimeout(2000);
expect(errored).toBeFalsy();
});
Expand All @@ -63,9 +91,11 @@ test('diff merged cells rendering', async () => {
await page.waitForTimeout(2000);

await page.evaluate(() => window.E2EControllerAPI.loadMergeCellSheet());
await page.waitForTimeout(5000);
await page.waitForTimeout(2000);

await expect(page).toHaveScreenshot(generateSnapshotName('mergedCellsRendering'), { maxDiffPixels: 5 });
const filename = generateSnapshotName('mergedCellsRendering');
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });

await page.waitForTimeout(2000);
await browser.close();
Expand Down Expand Up @@ -127,7 +157,9 @@ test('diff merged cells rendering after scrolling', async () => {
});
await page.waitForTimeout(2000);

await expect(page).toHaveScreenshot(generateSnapshotName('mergedCellsRenderingScrolling'), { maxDiffPixels: 5 });
const filename = generateSnapshotName('mergedCellsRenderingScrolling');
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });

await page.waitForTimeout(2000);
await browser.close();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/engine-render/src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface ICanvasProps {
height?: number;
pixelRatio?: number;
mode?: CanvasRenderMode;
id?: string;
}

/**
Expand Down Expand Up @@ -126,6 +127,10 @@ export class Canvas {
return this._height;
}

setId(id: string) {
this._canvasEle!.id = id;
}

setSize(width?: number, height?: number, pixelRatioParam?: number) {
// this.setWidth(width || 0);
// this.setHeight(height || 0);
Expand Down
2 changes: 2 additions & 0 deletions packages/engine-render/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export class Engine extends ThinEngine<Scene> {

private _previousHeight = -1000;

private _unitId: string = ''; // unitId

constructor(elemWidth: number = 1, elemHeight: number = 1, pixelRatio?: number, mode?: CanvasRenderMode) {
super();
this._canvas = new Canvas({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
* limitations under the License.
*/

import { createIdentifier, Disposable, Inject, Injector, IUniverInstanceService, remove, toDisposable, UniverInstanceType } from '@univerjs/core';
import { BehaviorSubject, Subject } from 'rxjs';
import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType } from '@univerjs/core';
import type { Observable } from 'rxjs';

import { Engine } from '../engine';
import { Scene } from '../scene';
import { type IRender, RenderUnit } from './render-unit';
import type { BaseObject } from '../base-object';
import type { DocComponent } from '../components/docs/doc-component';

import type { SheetComponent } from '../components/sheets/sheet-component';
import type { Slide } from '../components/slides/slide';
import { createIdentifier, Disposable, Inject, Injector, IUniverInstanceService, remove, toDisposable, UniverInstanceType } from '@univerjs/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { Engine } from '../engine';
import { Scene } from '../scene';
import { type IRender, RenderUnit } from './render-unit';

export type RenderComponentType = SheetComponent | DocComponent | Slide | BaseObject;

Expand Down
6 changes: 6 additions & 0 deletions packages/sheets-ui/src/services/sheets-render.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { IRenderManagerService, RENDER_RAW_FORMULA_KEY, Spreadsheet } from '@univerjs/engine-render';
import { distinctUntilChanged, takeUntil } from 'rxjs';

const SHEET_MAIN_CANVAS_ID = 'univer-sheet-main-canvas';
/**
* This controller is responsible for managing units of a specific kind to be rendered on the canvas.
*/
Expand Down Expand Up @@ -83,6 +84,11 @@ export class SheetsRenderService extends RxDisposable {

private _createRenderer(workbook: Workbook): void {
const unitId = workbook.getUnitId();
this._renderManagerService.created$.subscribe((renderer) => {
if (renderer.unitId === unitId) {
renderer.engine.getCanvas().setId(SHEET_MAIN_CANVAS_ID);
}
});
this._renderManagerService.createRender(unitId);

// NOTE@wzhudev: maybe not in univer mode
Expand Down
Loading