@@ -5,7 +5,10 @@ import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises';
55import { join } from 'node:path' ;
66import { tmpdir } from 'node:os' ;
77export async function verifySidebar ( window , recents ) {
8- const run = ( code ) => window . webContents . executeJavaScript ( code ) ;
8+ const run = ( code ) =>
9+ window . webContents . executeJavaScript ( code ) . catch ( ( error ) => {
10+ throw Error ( 'Sidebar script failed: ' + code , { cause : error } ) ;
11+ } ) ;
912 async function wait ( code ) {
1013 for ( let i = 0 ; i < 200 ; i ++ ) {
1114 if ( await run ( code ) ) return ;
@@ -25,7 +28,9 @@ export async function verifySidebar(window, recents) {
2528 const folder = await mkdtemp ( join ( tmpdir ( ) , 'sidebar-smoke-' ) ) ;
2629 try {
2730 await wait ( 'window.previewReady' ) ;
28- await run ( `window.previewPreferences.save({interactionMode:'reading',automatic:false})` ) ;
31+ await run (
32+ `window.previewPreferences.save({interactionMode:'reading',automatic:false,uiLanguage:'en'})` ,
33+ ) ;
2934 const pdf = await PDFDocument . load (
3035 await readFile ( new URL ( '../public/sample.pdf' , import . meta. url ) ) ,
3136 ) ;
@@ -66,11 +71,49 @@ export async function verifySidebar(window, recents) {
6671 await wait ( 'window.previewReady' ) ;
6772 await run ( `document.querySelector('[data-recent-id="${ id } "]').click()` ) ;
6873 await wait (
69- `!window.previewRenderDiagnostics().opening&&document.querySelectorAll('.sidebar-navigation-switch button').length===3` ,
70- ) ;
74+ `!window.previewRenderDiagnostics().opening&&document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)').length===3` ,
75+ ) ;
76+ if ( await run ( `window.previewAppearance.platform==='win32'` ) ) {
77+ window . show ( ) ;
78+ window . focus ( ) ;
79+ window . webContents . focus ( ) ;
80+ await new Promise ( ( resolve ) => setTimeout ( resolve , 350 ) ) ;
81+ assert . equal (
82+ await run (
83+ `getComputedStyle(document.querySelector('.sidebar-navigation-switch fluent-tab')).getPropertyValue('-webkit-app-region')` ,
84+ ) ,
85+ 'no-drag' ,
86+ ) ;
87+ const point = await run (
88+ `(()=>{const r=document.querySelectorAll('.sidebar-navigation-switch fluent-tab')[1].getBoundingClientRect();return {x:Math.round(r.x+r.width/2),y:Math.round(r.y+r.height/2)};})()` ,
89+ ) ;
90+ window . webContents . sendInputEvent ( { type : 'mouseMove' , ...point } ) ;
91+ await new Promise ( ( resolve ) => setTimeout ( resolve , 30 ) ) ;
92+ window . webContents . sendInputEvent ( {
93+ type : 'mouseDown' ,
94+ button : 'left' ,
95+ clickCount : 1 ,
96+ ...point ,
97+ } ) ;
98+ window . webContents . sendInputEvent ( {
99+ type : 'mouseUp' ,
100+ button : 'left' ,
101+ clickCount : 1 ,
102+ ...point ,
103+ } ) ;
104+ await wait (
105+ `document.querySelectorAll('.sidebar-navigation-switch fluent-tab')[1].dataset.state==='on'` ,
106+ ) ;
107+ await run ( `document.querySelectorAll('.sidebar-navigation-switch fluent-tab')[0].click()` ) ;
108+ await wait (
109+ `document.querySelectorAll('.sidebar-navigation-switch fluent-tab')[0].dataset.state==='on'` ,
110+ ) ;
111+ }
71112 async function verifyKeys ( ) {
72113 // Arrow navigation follows clicked items, not the reader's scroll position.
73- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[0].click()` ) ;
114+ await run (
115+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[0].click()` ,
116+ ) ;
74117 await wait ( `!!document.querySelector('.thumb[data-page-number="1"]')` ) ;
75118 await run ( `document.querySelector('.thumb[data-page-number="1"]').click()` ) ;
76119 await wait ( `document.activeElement?.dataset.pageNumber==='1'` ) ;
@@ -98,7 +141,9 @@ export async function verifySidebar(window, recents) {
98141 ) ;
99142 }
100143
101- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[1].click()` ) ;
144+ await run (
145+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[1].click()` ,
146+ ) ;
102147 await wait ( `document.querySelectorAll('.sidebar-outline-item').length===2` ) ;
103148 await run ( `document.querySelector('.sidebar-outline-item').click()` ) ;
104149 await wait (
@@ -116,7 +161,9 @@ export async function verifySidebar(window, recents) {
116161 await wait (
117162 `document.activeElement?.textContent.includes('Original chapter')&&window.previewRenderDiagnostics().active===2` ,
118163 ) ;
119- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[2].click()` ) ;
164+ await run (
165+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[2].click()` ,
166+ ) ;
120167 await wait ( `document.querySelectorAll('.sidebar-annotation-item').length===2` ) ;
121168 await run ( `document.querySelector('.sidebar-annotation-item').click()` ) ;
122169 await wait (
@@ -143,11 +190,13 @@ export async function verifySidebar(window, recents) {
143190 }
144191 assert . equal (
145192 await run (
146- `document.querySelector('.sidebar-navigation-switch button[aria-pressed=true]').textContent` ,
193+ `document.querySelector('.sidebar-navigation-switch :is( button,fluent-tab):is( [aria-pressed=true],[data-state=on]) ').textContent` ,
147194 ) ,
148195 'Thumbnails' ,
149196 ) ;
150- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[1].click()` ) ;
197+ await run (
198+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[1].click()` ,
199+ ) ;
151200 await wait ( `!!document.querySelector('.sidebar-outline-item')` ) ;
152201 assert . equal (
153202 await run ( `document.querySelector('.sidebar-outline-item').textContent` ) ,
@@ -176,7 +225,9 @@ export async function verifySidebar(window, recents) {
176225 await wait (
177226 `!document.querySelector('.document-motion-snapshot,.sidebar-motion-enter-active,.sidebar-view-motion-enter-active,.workspace.document-opening')` ,
178227 ) ;
179- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[0].click()` ) ;
228+ await run (
229+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[0].click()` ,
230+ ) ;
180231 await wait (
181232 `!!document.querySelector('.thumbnail-list')&&!document.querySelector('.sidebar-view-motion-enter-active')` ,
182233 ) ;
@@ -216,7 +267,9 @@ export async function verifySidebar(window, recents) {
216267 ) ;
217268 await wait ( `document.querySelector('.sidebar').getBoundingClientRect().width>${ expanded + 10 } ` ) ;
218269 for ( const tab of [ 1 , 2 , 0 , 1 ] ) {
219- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[${ tab } ].click()` ) ;
270+ await run (
271+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[${ tab } ].click()` ,
272+ ) ;
220273 await wait ( `!document.querySelector('.sidebar-view-motion-enter-active')` ) ;
221274 assert . ok (
222275 Math . abs (
@@ -248,7 +301,9 @@ export async function verifySidebar(window, recents) {
248301 await wait (
249302 `window.previewRenderDiagnostics().active===2&&!!document.querySelector('.reference-return-button')` ,
250303 ) ;
251- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[2].click()` ) ;
304+ await run (
305+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[2].click()` ,
306+ ) ;
252307 await wait ( `document.querySelectorAll('.sidebar-annotation-item').length===2` ) ;
253308 assert . equal (
254309 await run (
@@ -296,13 +351,15 @@ export async function verifySidebar(window, recents) {
296351 `window.previewRenderDiagnostics().active===2&&!!document.querySelector('.reference-return-button')` ,
297352 ) ;
298353 await run (
299- `document.querySelectorAll('.sidebar-navigation-switch button')[1].click();document.querySelector('.sidebar-outline-item')?.click()` ,
354+ `document.querySelectorAll('.sidebar-navigation-switch :is( button,fluent-tab) ')[1].click();document.querySelector('.sidebar-outline-item')?.click()` ,
300355 ) ;
301356 await wait ( `!!document.querySelector('.sidebar-outline-item')` ) ;
302357 await run ( `document.querySelector('.sidebar-outline-item').click()` ) ;
303358 await wait ( `window.previewRenderDiagnostics().active===2` ) ;
304359 assert . equal ( await run ( `window.previewRenderDiagnostics().readingView.showTranslations` ) , true ) ;
305- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[2].click()` ) ;
360+ await run (
361+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[2].click()` ,
362+ ) ;
306363 await wait ( `document.querySelectorAll('.sidebar-annotation-item').length===2` ) ;
307364 await new Promise ( ( r ) => setTimeout ( r , 250 ) ) ;
308365 await writeFile (
@@ -314,15 +371,21 @@ export async function verifySidebar(window, recents) {
314371 ) ;
315372 assert . equal ( footer . within , true ) ;
316373 assert . ok ( footer . gap < 16 ) ;
317- await run ( `document.querySelector('.sidebar-navigation-switch button').click()` ) ;
374+ await run (
375+ `document.querySelector('.sidebar-navigation-switch :is(button,fluent-tab)').click()` ,
376+ ) ;
318377 assert . ok (
319- await run ( `document.querySelector('.sidebar-tab-indicator').getAnimations().length>0` ) ,
378+ await run (
379+ `window.previewAppearance?.platform==='win32'?!!document.querySelector('.sidebar-navigation-switch fluent-tab[data-state=on]'):document.querySelector('.sidebar-tab-indicator').getAnimations().length>0` ,
380+ ) ,
320381 'tab selection animates' ,
321382 ) ;
322383 await wait ( `window.previewRenderDiagnostics().thumbnails.length>0` ) ;
323384 await run ( `window.sidebarThumbnailNode=document.querySelector('.thumbnail-list')` ) ;
324385 for ( const tab of [ 1 , 2 , 0 , 2 , 1 , 0 ] ) {
325- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[${ tab } ].click()` ) ;
386+ await run (
387+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[${ tab } ].click()` ,
388+ ) ;
326389 await new Promise ( ( r ) => setTimeout ( r , 35 ) ) ;
327390 }
328391 await wait (
@@ -349,7 +412,9 @@ export async function verifySidebar(window, recents) {
349412 ) ,
350413 'switch remains at the bottom after rapid switching' ,
351414 ) ;
352- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[1].click()` ) ;
415+ await run (
416+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[1].click()` ,
417+ ) ;
353418 await wait (
354419 `!!document.querySelector('.sidebar-outline-item')&&!document.querySelector('.sidebar-view-motion-enter-active')` ,
355420 ) ;
@@ -376,7 +441,9 @@ export async function verifySidebar(window, recents) {
376441 'resized sidebar width survives hide/show' ,
377442 ) ;
378443 for ( const tab of [ 0 , 1 , 2 ] ) {
379- await run ( `document.querySelectorAll('.sidebar-navigation-switch button')[${ tab } ].click()` ) ;
444+ await run (
445+ `document.querySelectorAll('.sidebar-navigation-switch :is(button,fluent-tab)')[${ tab } ].click()` ,
446+ ) ;
380447 await new Promise ( ( r ) => setTimeout ( r , 220 ) ) ;
381448 const motion = await run (
382449 `(async()=>{const app=document.querySelector('.app'),sidebar=document.querySelector('.sidebar');const padding=()=>parseFloat(getComputedStyle(sidebar).paddingTop);const start=padding();app.classList.add('immersive-header-hidden');await new Promise(r=>setTimeout(r,70));const middle=padding();await new Promise(r=>setTimeout(r,160));const hidden=padding();app.classList.remove('immersive-header-hidden');await new Promise(r=>setTimeout(r,70));const returning=padding();await new Promise(r=>setTimeout(r,160));return {start,middle,hidden,returning,end:padding()};})()` ,
0 commit comments