@@ -2,7 +2,6 @@ import { chromium, expect, test } from '@playwright/test';
22import { generateSnapshotName } from '../const' ;
33
44const SHEET_MAIN_CANVAS_ID = '#univer-sheet-main-canvas_workbook-01' ;
5- const SHEET_SCROLLBAR_SIZE = 11 ;
65const isCI = ! ! process . env . CI ;
76
87test ( 'cells rendering after scrolling' , async ( ) => {
@@ -58,139 +57,6 @@ test('cells rendering after scrolling', async () => {
5857 await expect ( screenshot ) . toMatchSnapshot ( filename , { maxDiffPixelRatio : 0.005 } ) ;
5958} ) ;
6059
61- test ( 'incremental merged-cell repaint matches a full refresh' , async ( ) => {
62- const browser = await chromium . launch ( { headless : isCI } ) ;
63- const context = await browser . newContext ( {
64- viewport : { width : 1280 , height : 1280 } ,
65- deviceScaleFactor : 2 ,
66- } ) ;
67- const page = await context . newPage ( ) ;
68- await page . goto ( 'http://localhost:3000/sheets/' ) ;
69- await page . waitForTimeout ( 2000 ) ;
70-
71- await page . evaluate ( ( ) => window . E2EControllerAPI . loadMergeCellSheet ( ) ) ;
72- await page . evaluate ( ( ) => new Promise < void > ( ( resolve ) => requestAnimationFrame ( ( ) => requestAnimationFrame ( ( ) => resolve ( ) ) ) ) ) ;
73- await expect ( page . getByText ( 'Custom Loading...' , { exact : true } ) ) . toHaveCount ( 0 , { timeout : 15_000 } ) ;
74- await page . evaluate ( async ( ) => {
75- await document . fonts . ready ;
76- await new Promise < void > ( ( resolve ) => requestAnimationFrame ( ( ) => requestAnimationFrame ( ( ) => resolve ( ) ) ) ) ;
77- } ) ;
78-
79- const canvas = page . locator ( SHEET_MAIN_CANVAS_ID ) ;
80- await canvas . evaluate ( async ( element : HTMLCanvasElement ) => {
81- const scroll = async ( deltaY : number ) => {
82- for ( let elapsed = 0 ; elapsed < 1000 ; elapsed += 30 ) {
83- element . dispatchEvent ( new WheelEvent ( 'wheel' , {
84- bubbles : true ,
85- cancelable : true ,
86- deltaY,
87- clientX : 580 ,
88- clientY : 580 ,
89- } ) ) ;
90- await new Promise ( ( resolve ) => setTimeout ( resolve , 30 ) ) ;
91- }
92- } ;
93- await scroll ( 100 ) ;
94- await scroll ( - 100 ) ;
95- } ) ;
96- await page . evaluate ( ( ) => new Promise < void > ( ( resolve ) => {
97- let previous = '' ;
98- let stableFrames = 0 ;
99- const check = ( ) => {
100- const current = JSON . stringify ( window . univerAPI . getActiveWorkbook ( ) . getActiveSheet ( ) . getScrollState ( ) ) ;
101- stableFrames = current === previous ? stableFrames + 1 : 0 ;
102- previous = current ;
103- if ( stableFrames >= 5 ) {
104- resolve ( ) ;
105- return ;
106- }
107- requestAnimationFrame ( check ) ;
108- } ;
109- requestAnimationFrame ( check ) ;
110- } ) ) ;
111-
112- await canvas . evaluate ( ( source : HTMLCanvasElement ) => {
113- const reference = document . createElement ( 'canvas' ) ;
114- reference . id = 'merge-scroll-incremental-reference' ;
115- reference . style . display = 'none' ;
116- reference . width = source . width ;
117- reference . height = source . height ;
118- const sourceContext = source . getContext ( '2d' ) ;
119- const referenceContext = reference . getContext ( '2d' ) ;
120- if ( ! sourceContext || ! referenceContext ) {
121- throw new Error ( 'Failed to read incremental canvas pixels' ) ;
122- }
123- referenceContext . putImageData ( sourceContext . getImageData ( 0 , 0 , source . width , source . height ) , 0 , 0 ) ;
124- document . body . appendChild ( reference ) ;
125- } ) ;
126-
127- await page . evaluate ( ( ) => window . univerAPI . getActiveWorkbook ( ) . getActiveSheet ( ) . refreshCanvas ( ) ) ;
128- await page . evaluate ( ( ) => new Promise < void > ( ( resolve ) => requestAnimationFrame ( ( ) => requestAnimationFrame ( ( ) => resolve ( ) ) ) ) ) ;
129-
130- const differentPixels = await canvas . evaluate ( ( source : HTMLCanvasElement , scrollBarSize ) => {
131- const reference = document . querySelector < HTMLCanvasElement > ( '#merge-scroll-incremental-reference' ) ;
132- const sourceContext = source . getContext ( '2d' ) ;
133- const referenceContext = reference ?. getContext ( '2d' ) ;
134- if ( ! reference || ! sourceContext || ! referenceContext ) {
135- throw new Error ( 'Failed to read canvas pixels' ) ;
136- }
137- if ( source . width !== reference . width || source . height !== reference . height ) {
138- return Number . POSITIVE_INFINITY ;
139- }
140- const actual = sourceContext . getImageData ( 0 , 0 , source . width , source . height ) . data ;
141- const expected = referenceContext . getImageData ( 0 , 0 , reference . width , reference . height ) . data ;
142- const activeWorkbook = window . univerAPI . getActiveWorkbook ( ) ;
143- const activeSheet = activeWorkbook . getActiveSheet ( ) ;
144- const sheetSnapshot = activeWorkbook . save ( ) . sheets [ activeSheet . getSheetId ( ) ] ;
145- const pixelRatio = source . width / source . getBoundingClientRect ( ) . width ;
146- const left = Math . round ( ( sheetSnapshot . rowHeader ?. hidden ? 0 : sheetSnapshot . rowHeader ?. width ?? 0 ) * pixelRatio ) ;
147- const top = Math . round ( ( sheetSnapshot . columnHeader ?. hidden ? 0 : sheetSnapshot . columnHeader ?. height ?? 0 ) * pixelRatio ) ;
148- const right = Math . round ( source . width - scrollBarSize * pixelRatio ) ;
149- const bottom = Math . round ( source . height - scrollBarSize * pixelRatio ) ;
150- let count = 0 ;
151- for ( let y = top ; y < bottom ; y ++ ) {
152- for ( let x = left ; x < right ; x ++ ) {
153- const index = ( y * source . width + x ) * 4 ;
154- if (
155- actual [ index ] !== expected [ index ] ||
156- actual [ index + 1 ] !== expected [ index + 1 ] ||
157- actual [ index + 2 ] !== expected [ index + 2 ] ||
158- actual [ index + 3 ] !== expected [ index + 3 ]
159- ) {
160- count ++ ;
161- }
162- }
163- }
164- reference . remove ( ) ;
165- return count ;
166- } , SHEET_SCROLLBAR_SIZE ) ;
167- await browser . close ( ) ;
168- expect ( differentPixels ) . toBeLessThanOrEqual ( 1 ) ;
169- } ) ;
170-
171- test ( 'rendering after scrolling by API' , async ( ) => {
172- const browser = await chromium . launch ( {
173- headless : isCI , // Set to false to see the browser window in local
174- } ) ;
175- const context = await browser . newContext ( {
176- viewport : { width : 1280 , height : 1280 } ,
177- deviceScaleFactor : 2 , // Set your desired DPR
178- } ) ;
179- const page = await context . newPage ( ) ;
180- await page . goto ( 'http://localhost:3000/sheets/' ) ;
181- await page . waitForTimeout ( 2000 ) ;
182-
183- await page . evaluate ( ( ) => window . E2EControllerAPI . loadMergeCellSheet ( ) ) ;
184- await page . evaluate ( async ( ) => {
185- const activeSheet = window . univerAPI . getActiveWorkbook ( ) . getActiveSheet ( ) ;
186- activeSheet . scrollToCell ( 2 , 4 ) ;
187- } ) ;
188- await page . waitForTimeout ( 1000 ) ;
189- const filename = generateSnapshotName ( 'renderingAfterScrollByAPI' ) ;
190- const screenshot = await page . locator ( SHEET_MAIN_CANVAS_ID ) . screenshot ( ) ;
191- await expect ( screenshot ) . toMatchSnapshot ( filename , { maxDiffPixelRatio : 0.005 } ) ;
192- } ) ;
193-
19460test ( 'status bar count with array formula selection' , async ( ) => {
19561 const browser = await chromium . launch ( {
19662 headless : isCI , // Set to false to see the browser window in local
0 commit comments