@@ -13,8 +13,8 @@ async function uploadAndDisplay(page: Page, fileName: string) {
1313 await uploadFile ( page , fileName ) ;
1414
1515 // Wait for link with document-link class
16- await page . waitForSelector ( '.document-link' , { timeout : 20000 } ) ;
17- await page . getByText ( fileName ) . click ( ) ;
16+ const size = fileName . endsWith ( '.pdf' ) ? '0.02 MB' : '0.33 MB' ;
17+ await page . getByRole ( 'link' , { name : ` ${ fileName } ${ size } ` } ) . click ( ) ;
1818
1919 // Wait for the document to load
2020 if ( fileName . endsWith ( '.pdf' ) ) {
@@ -27,25 +27,23 @@ async function uploadAndDisplay(page: Page, fileName: string) {
2727
2828async function waitAndClickPlay ( page : Page ) {
2929 // Wait for play button selector without disabled attribute
30- await page . waitForSelector ( 'button[aria-label="Play"]:not([disabled]) ' , { timeout : 20000 } ) ;
31- // Play the TTS by aria-label play button
32- await page . locator ( 'button[aria-label=" Play"]' ) . click ( ) ;
30+ await expect ( page . getByRole ( 'button' , { name : 'Play' } ) ) . toBeVisible ( ) ;
31+ // Play the TTS by clicking the button
32+ await page . getByRole ( 'button' , { name : ' Play' } ) . click ( ) ;
3333
34- // Wait for buttons to be disabled
35- await Promise . all ( [
36- page . waitForSelector ( 'button[aria-label="Skip forward"][disabled]' ) ,
37- page . waitForSelector ( 'button[aria-label="Skip backward"][disabled]' ) ,
38- ] ) ;
34+ // Expect for buttons to be disabled
35+ await expect ( page . locator ( 'button[aria-label="Skip forward"][disabled]' ) ) . toBeVisible ( ) ;
36+ await expect ( page . locator ( 'button[aria-label="Skip backward"][disabled]' ) ) . toBeVisible ( ) ;
3937
4038 // Wait for the TTS to stop processing
4139 await Promise . all ( [
42- page . waitForSelector ( 'button[aria-label="Skip forward"]:not([disabled])' , { timeout : 30000 } ) ,
43- page . waitForSelector ( 'button[aria-label="Skip backward"]:not([disabled])' , { timeout : 30000 } ) ,
40+ page . waitForSelector ( 'button[aria-label="Skip forward"]:not([disabled])' , { timeout : 45000 } ) ,
41+ page . waitForSelector ( 'button[aria-label="Skip backward"]:not([disabled])' , { timeout : 45000 } ) ,
4442 ] ) ;
4543
4644 await page . waitForFunction ( ( ) => {
4745 return navigator . mediaSession ?. playbackState === 'playing' ;
48- } , { timeout : 30000 } )
46+ } ) ;
4947}
5048
5149async function playTTSAndWaitForASecond ( page : Page , fileName : string ) {
@@ -61,12 +59,14 @@ test.describe('Document flow', () => {
6159 test . beforeEach ( async ( { page } ) => {
6260 // Navigate to the home page before each test
6361 await page . goto ( '/' ) ;
62+ await page . waitForLoadState ( 'networkidle' ) ;
6463
6564 // Click the "done" button to dismiss the welcome message
6665 await page . getByText ( 'Done' ) . click ( ) ;
6766 } ) ;
6867
69- test . describe ( 'PDF check' , ( ) => {
68+ // Basic upload tests can run in parallel
69+ test . describe ( 'Basic document tests' , ( ) => {
7070 test ( 'upload a PDF document' , async ( { page } ) => {
7171 // Upload the file
7272 await uploadFile ( page , 'sample.pdf' ) ;
@@ -75,47 +75,52 @@ test.describe('Document flow', () => {
7575 await expect ( page . getByText ( 'sample.pdf' ) ) . toBeVisible ( { timeout : 10000 } ) ;
7676 } ) ;
7777
78+ test ( 'upload a EPUB document' , async ( { page } ) => {
79+ // Upload the file
80+ await uploadFile ( page , 'sample.epub' ) ;
81+ // Verify upload success
82+ await expect ( page . getByText ( 'sample.epub' ) ) . toBeVisible ( { timeout : 10000 } ) ;
83+ } ) ;
84+
7885 test ( 'display a PDF document' , async ( { page } ) => {
7986 // Upload and display the PDF document
8087 await uploadAndDisplay ( page , 'sample.pdf' ) ;
8188
8289 // Verify PDF viewer is displayed
8390 await expect ( page . locator ( '.react-pdf__Document' ) ) . toBeVisible ( ) ;
8491 await expect ( page . locator ( '.react-pdf__Page' ) ) . toBeVisible ( ) ;
85- } ) ;
86-
87- test ( 'play and pause TTS for a PDF document (naive)' , async ( { page } ) => {
88- // Play TTS for the PDF document
89- await playTTSAndWaitForASecond ( page , 'sample.pdf' ) ;
90- // Click pause to stop playback
91- await page . locator ( 'button[aria-label="Pause"]' ) . click ( ) ;
92- // Check for play button to be visible
93- await expect ( page . locator ( 'button[aria-label="Play"]' ) ) . toBeVisible ( { timeout : 10000 } ) ;
94- } ) ;
95- } ) ;
96-
97- test . describe ( 'EPUB check' , ( ) => {
98- test ( 'upload a EPUB document' , async ( { page } ) => {
99- // Upload the file
100- await uploadFile ( page , 'sample.epub' ) ;
101- // Verify upload success
102- await expect ( page . getByText ( 'sample.epub' ) ) . toBeVisible ( { timeout : 10000 } ) ;
92+ await expect ( page . getByText ( 'Sample PDF' ) ) . toBeVisible ( ) ;
10393 } ) ;
10494
10595 test ( 'display an EPUB document' , async ( { page } ) => {
10696 // Upload and display the EPUB document
10797 await uploadAndDisplay ( page , 'sample.epub' ) ;
10898 // Verify EPUB viewer is displayed
10999 await expect ( page . locator ( '.epub-container' ) ) . toBeVisible ( { timeout : 10000 } ) ;
100+ await expect ( page . getByRole ( 'button' , { name : '‹' } ) ) . toBeVisible ( ) ;
101+ await expect ( page . getByRole ( 'button' , { name : '›' } ) ) . toBeVisible ( ) ;
102+ } ) ;
103+ } ) ;
104+
105+ // TTS tests run with limited concurrency
106+ test . describe ( 'TTS functionality' , ( ) => {
107+ test . describe . configure ( { mode : 'serial' } ) ;
108+ test ( 'play and pause TTS for a PDF document' , async ( { page } ) => {
109+ // Play TTS for the PDF document
110+ await playTTSAndWaitForASecond ( page , 'sample.pdf' ) ;
111+ // Click pause to stop playback
112+ await page . getByRole ( 'button' , { name : 'Pause' } ) . click ( ) ;
113+ // Check for play button to be visible
114+ await expect ( page . getByRole ( 'button' , { name : 'Play' } ) ) . toBeVisible ( { timeout : 10000 } ) ;
110115 } ) ;
111116
112- test ( 'play and pause TTS for an EPUB document (naive) ' , async ( { page } ) => {
117+ test ( 'play and pause TTS for an EPUB document' , async ( { page } ) => {
113118 // Play TTS for the EPUB document
114119 await playTTSAndWaitForASecond ( page , 'sample.epub' ) ;
115120 // Click pause to stop playback
116- await page . locator ( 'button[aria-label=" Pause"]' ) . click ( ) ;
121+ await page . getByRole ( 'button' , { name : ' Pause' } ) . click ( ) ;
117122 // Check for play button to be visible
118- await expect ( page . locator ( 'button[aria-label=" Play"]' ) ) . toBeVisible ( { timeout : 10000 } ) ;
123+ await expect ( page . getByRole ( 'button' , { name : ' Play' } ) ) . toBeVisible ( { timeout : 10000 } ) ;
119124 } ) ;
120125 } ) ;
121126} ) ;
0 commit comments