Skip to content

Commit

Permalink
chore: snapshot only on canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Oct 11, 2024
1 parent 8987b65 commit ec0e0f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
37 changes: 5 additions & 32 deletions e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,16 @@
import { chromium, expect, test } from '@playwright/test';
import { generateSnapshotName } from '../const';

const SHEET_MAIN_CANVAS_ID = '#univer-sheet-main-canvas';
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 expect(page).toHaveScreenshot(generateSnapshotName('default-sheet'), { maxDiffPixels: 5 });
const filename = generateSnapshotName('default-sheet');
// ignore DOM part when comparison
const screenshot = await page.screenshot({
clip: {
x: 0,
y: 92,
width: 1280,
height: 592, // 720 - 92(header) - 36(bottom)
},
});
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });
});
const isCI = !!process.env.CI;
Expand All @@ -53,18 +45,8 @@ 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');
// ignore DOM part when comparison
const screenshot = await page.screenshot({
clip: {
x: 0,
y: 92,
width: 1280,
height: 592, // 720 - 92(header) - 36(bottom)
},
});
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 @@ -88,9 +70,8 @@ test('diff merged cells rendering', async () => {
await page.evaluate(() => window.E2EControllerAPI.loadMergeCellSheet());
await page.waitForTimeout(2000);

// await expect(page).toHaveScreenshot(generateSnapshotName('mergedCellsRendering'), { maxDiffPixels: 5 });
const filename = generateSnapshotName('mergedCellsRendering');
const screenshot = await page.locator('#univer-sheet-main-canvas').screenshot();
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });

await page.waitForTimeout(2000);
Expand Down Expand Up @@ -153,16 +134,8 @@ 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.screenshot({
clip: {
x: 0,
y: 92,
width: 1280,
height: 1152,
},
});
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });

await page.waitForTimeout(2000);
Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -85,7 +86,7 @@ export class SheetsRenderService extends RxDisposable {
const unitId = workbook.getUnitId();
this._renderManagerService.created$.subscribe((renderer) => {
if (renderer.unitId === unitId) {
renderer.engine.getCanvas().setId('univer-sheet-main-canvas');
renderer.engine.getCanvas().setId(SHEET_MAIN_CANVAS_ID);
}
});
this._renderManagerService.createRender(unitId);
Expand Down

0 comments on commit ec0e0f1

Please sign in to comment.