@@ -30,29 +30,50 @@ export async function triggerFileChooser(
3030 return fileChooser ;
3131}
3232
33- export async function uploadFiles ( page : Page , filePath : string [ ] ) {
34- // button name stays the same, only tooltip is translated
35- const attachButton = page . getByRole ( 'button' , { name : 'Attach' } ) ;
36- await expect ( attachButton ) . toBeVisible ( ) ;
37-
38- const fileChooser = await triggerFileChooser ( page , attachButton ) ;
39- await fileChooser . setFiles ( filePath ) ;
33+ export async function uploadFiles (
34+ page : Page ,
35+ filePath : string [ ] ,
36+ translations : LightspeedMessages ,
37+ ) {
38+ // The attach button is now a dropdown toggle with a PlusIcon
39+ // aria-label uses 'tooltip.attach' translation
40+ const plusButton = page . getByRole ( 'button' , {
41+ name : translations [ 'tooltip.attach' ] ,
42+ } ) ;
43+ await expect ( plusButton ) . toBeVisible ( ) ;
44+
45+ // Use the hidden file input directly - this bypasses the dropdown menu
46+ // The input has the multiple attribute so it can accept multiple files
47+ const fileInput = page . locator ( 'input[data-testid="attachment-input"]' ) ;
48+
49+ // Clear the input first to ensure change event fires even for the same file
50+ // This is necessary because browsers don't fire 'change' if the same file is selected again
51+ await fileInput . evaluate ( ( el : HTMLInputElement ) => {
52+ el . value = '' ;
53+ } ) ;
54+
55+ await fileInput . setInputFiles ( filePath ) ;
4056}
4157
4258export async function uploadAndAssertDuplicate (
4359 page : Page ,
4460 filePath : string ,
4561 fileName : string ,
4662 translations : LightspeedMessages ,
47- testInfo : TestInfo ,
63+ _testInfo : TestInfo ,
4864) {
49- await validateSuccessfulUpload ( page , fileName , translations , testInfo ) ;
50- await uploadFiles ( page , [ filePath ] ) ;
65+ // First, verify the initial upload was successful by checking the file button is visible
66+ await expect ( page . getByRole ( 'button' , { name : fileName } ) ) . toBeVisible ( ) ;
67+
68+ // Upload the same file again to trigger duplicate detection
69+ await uploadFiles ( page , [ filePath ] , translations ) ;
70+
71+ // Assert the duplicate file error alert appears
5172 await expect (
5273 page . getByRole ( 'heading' , {
5374 name : translations [ 'chatbox.fileUpload.failed' ] ,
5475 } ) ,
55- ) . toBeVisible ( ) ;
76+ ) . toBeVisible ( { timeout : 10000 } ) ;
5677 await expect (
5778 page . getByText ( translations [ 'file.upload.error.alreadyExists' ] ) ,
5879 ) . toBeVisible ( ) ;
@@ -88,7 +109,11 @@ export async function validateSuccessfulUpload(
88109 . getByRole ( 'button' , { name : translations [ 'modal.close' ] } ) ,
89110 ) . toBeVisible ( ) ;
90111
91- await page . getByRole ( 'button' , { name : translations [ 'modal.edit' ] } ) . click ( ) ;
112+ // Use evaluate to click buttons via JavaScript to bypass the iframe overlay
113+ const editButton = page . getByRole ( 'button' , {
114+ name : translations [ 'modal.edit' ] ,
115+ } ) ;
116+ await editButton . evaluate ( ( el : HTMLElement ) => el . click ( ) ) ;
92117 await runAccessibilityTests ( page , testInfo ) ;
93118
94119 await expect (
@@ -98,11 +123,15 @@ export async function validateSuccessfulUpload(
98123 page . getByRole ( 'button' , { name : translations [ 'modal.cancel' ] } ) ,
99124 ) . toBeVisible ( ) ;
100125
101- await page . getByRole ( 'button' , { name : translations [ 'modal.save' ] } ) . click ( ) ;
102- await page
126+ const saveButton = page . getByRole ( 'button' , {
127+ name : translations [ 'modal.save' ] ,
128+ } ) ;
129+ await saveButton . evaluate ( ( el : HTMLElement ) => el . click ( ) ) ;
130+
131+ const closeButton = page
103132 . getByRole ( 'contentinfo' )
104- . locator ( `role= button[name=" ${ translations [ 'modal.close' ] } "]` )
105- . click ( ) ;
133+ . getByRole ( ' button' , { name : translations [ 'modal.close' ] } ) ;
134+ await closeButton . evaluate ( ( el : HTMLElement ) => el . click ( ) ) ;
106135}
107136
108137export async function validateFailedUpload (
@@ -117,7 +146,9 @@ export async function validateFailedUpload(
117146 await expect ( alertHeader ) . toBeVisible ( ) ;
118147 await expect ( alertText ) . toBeVisible ( ) ;
119148
120- await page . getByRole ( 'button' , { name : 'Close Danger alert' } ) . click ( ) ;
149+ // Use evaluate to click the button via JavaScript to bypass the iframe overlay
150+ const closeButton = page . getByRole ( 'button' , { name : 'Close Danger alert' } ) ;
151+ await closeButton . evaluate ( ( el : HTMLElement ) => el . click ( ) ) ;
121152 await expect ( alertHeader ) . toBeHidden ( ) ;
122153 await expect ( alertText ) . toBeHidden ( ) ;
123154}
0 commit comments