1+ const vscode = require ( 'vscode' ) ;
2+ const path = require ( 'path' ) ;
3+ const fs = require ( 'fs' ) ;
4+
5+ describe ( 'Run Upload Test' , ( ) => {
6+ const testFilePath = path . join ( __dirname , '../../fixtures/test-upload-file.txt' ) ;
7+ const testHtmlPath = path . join ( __dirname , '../../fixtures/file-upload-test.html' ) ;
8+
9+ beforeAll ( ( ) => {
10+ // Ensure test files exist
11+ expect ( fs . existsSync ( testFilePath ) ) . toBe ( true ) ;
12+ expect ( fs . existsSync ( testHtmlPath ) ) . toBe ( true ) ;
13+ } ) ;
14+
15+ test ( 'Test file upload integration with browser action' , async ( ) => {
16+ // This test is a placeholder for the actual integration test
17+ // The real test would be run in the e2e/src/suite/browser-action-upload.test.ts file
18+
19+ // Mock the browser session
20+ const mockBrowserSession = {
21+ launchBrowser : jest . fn ( ) . mockResolvedValue ( undefined ) ,
22+ navigateToUrl : jest . fn ( ) . mockResolvedValue ( {
23+ screenshot : 'data:image/png;base64,mockScreenshot' ,
24+ logs : 'Page loaded' ,
25+ } ) ,
26+ upload : jest . fn ( ) . mockResolvedValue ( {
27+ screenshot : 'data:image/png;base64,mockScreenshot' ,
28+ logs : 'File uploaded successfully' ,
29+ } ) ,
30+ closeBrowser : jest . fn ( ) . mockResolvedValue ( { } ) ,
31+ } ;
32+
33+ // Simulate the test flow
34+ await mockBrowserSession . launchBrowser ( ) ;
35+
36+ // Navigate to the test HTML file using file:// protocol
37+ const fileUrl = `file://${ testHtmlPath } ` ;
38+ await mockBrowserSession . navigateToUrl ( fileUrl ) ;
39+
40+ // Upload the test file to the standard file input
41+ await mockBrowserSession . upload ( '#fileInput' , testFilePath ) ;
42+
43+ // Upload the test file to the hidden file input
44+ await mockBrowserSession . upload ( '#hiddenFileInput' , testFilePath ) ;
45+
46+ // Close the browser
47+ await mockBrowserSession . closeBrowser ( ) ;
48+
49+ // Verify all methods were called with the correct parameters
50+ expect ( mockBrowserSession . launchBrowser ) . toHaveBeenCalled ( ) ;
51+ expect ( mockBrowserSession . navigateToUrl ) . toHaveBeenCalledWith ( fileUrl ) ;
52+ expect ( mockBrowserSession . upload ) . toHaveBeenCalledWith ( '#fileInput' , testFilePath ) ;
53+ expect ( mockBrowserSession . upload ) . toHaveBeenCalledWith ( '#hiddenFileInput' , testFilePath ) ;
54+ expect ( mockBrowserSession . closeBrowser ) . toHaveBeenCalled ( ) ;
55+ } ) ;
56+
57+ test ( 'Test file upload with error handling' , async ( ) => {
58+ // Mock the browser session with an error for the upload method
59+ const mockBrowserSession = {
60+ launchBrowser : jest . fn ( ) . mockResolvedValue ( undefined ) ,
61+ navigateToUrl : jest . fn ( ) . mockResolvedValue ( {
62+ screenshot : 'data:image/png;base64,mockScreenshot' ,
63+ logs : 'Page loaded' ,
64+ } ) ,
65+ upload : jest . fn ( ) . mockRejectedValue ( new Error ( 'File input not found' ) ) ,
66+ closeBrowser : jest . fn ( ) . mockResolvedValue ( { } ) ,
67+ } ;
68+
69+ // Simulate the test flow
70+ await mockBrowserSession . launchBrowser ( ) ;
71+
72+ // Navigate to the test HTML file
73+ const fileUrl = `file://${ testHtmlPath } ` ;
74+ await mockBrowserSession . navigateToUrl ( fileUrl ) ;
75+
76+ // Attempt to upload to a non-existent file input
77+ try {
78+ await mockBrowserSession . upload ( '#nonExistentInput' , testFilePath ) ;
79+ fail ( 'Should have thrown an error' ) ;
80+ } catch ( error ) {
81+ expect ( error . message ) . toBe ( 'File input not found' ) ;
82+ }
83+
84+ // Close the browser
85+ await mockBrowserSession . closeBrowser ( ) ;
86+
87+ // Verify methods were called with the correct parameters
88+ expect ( mockBrowserSession . launchBrowser ) . toHaveBeenCalled ( ) ;
89+ expect ( mockBrowserSession . navigateToUrl ) . toHaveBeenCalledWith ( fileUrl ) ;
90+ expect ( mockBrowserSession . upload ) . toHaveBeenCalledWith ( '#nonExistentInput' , testFilePath ) ;
91+ expect ( mockBrowserSession . closeBrowser ) . toHaveBeenCalled ( ) ;
92+ } ) ;
93+ } ) ;
0 commit comments