@@ -12,15 +12,14 @@ import {
1212 cleanup ,
1313 createPatchWidget ,
1414 createPatchWidgetWithDiffView ,
15- createTestFilesystem ,
1615 initializePersistenceImplForTests ,
1716 MockAidaAbortError ,
1817 mockAidaClient ,
1918 MockAidaFetchError ,
2019} from '../../testing/AiAssistanceHelpers.js' ;
2120import { updateHostConfig } from '../../testing/EnvironmentHelpers.js' ;
2221import { describeWithMockConnection } from '../../testing/MockConnection.js' ;
23- import { createContentProviderUISourceCode } from '../../testing/UISourceCodeHelpers.js' ;
22+ import { createContentProviderUISourceCode , createFileSystemUISourceCode } from '../../testing/UISourceCodeHelpers.js' ;
2423
2524import * as AiAssistance from './ai_assistance.js' ;
2625
@@ -37,7 +36,7 @@ describeWithMockConnection('PatchWidget', () => {
3736 cleanup ( ) ;
3837 } ) ;
3938
40- describe ( 'applyToWorkspace ' , ( ) => {
39+ describe ( 'applyToPageTree ' , ( ) => {
4140 beforeEach ( ( ) => {
4241 createContentProviderUISourceCode ( {
4342 url : Platform . DevToolsPath . urlString `file://test/index.html` ,
@@ -129,7 +128,7 @@ describeWithMockConnection('PatchWidget', () => {
129128 } ) ;
130129 } ) ;
131130
132- it ( 'should show FRE dialog on applyToWorkspace click if the setting is false' , async ( ) => {
131+ it ( 'should show FRE dialog on applyToPageTree click if the setting is false' , async ( ) => {
133132 Common . Settings . moduleSetting ( 'ai-assistance-patching-fre-completed' ) . set ( false ) ;
134133 const { view, widget} = await createPatchWidget ( ) ;
135134 widget . changeSummary = 'body { background-color: red; }' ;
@@ -139,7 +138,7 @@ describeWithMockConnection('PatchWidget', () => {
139138 assert . isTrue ( showFreDialogStub . called , 'Expected FreDialog to be shown but it\'s not shown' ) ;
140139 } ) ;
141140
142- it ( 'should not show FRE dialog on applyToWorkspace click if the setting is true' , async ( ) => {
141+ it ( 'should not show FRE dialog on applyToPageTree click if the setting is true' , async ( ) => {
143142 Common . Settings . moduleSetting ( 'ai-assistance-patching-fre-completed' ) . set ( true ) ;
144143 const { view, widget} = await createPatchWidget ( ) ;
145144 widget . changeSummary = 'body { background-color: red; }' ;
@@ -166,7 +165,7 @@ Files:
166165* /index.html` ) ;
167166 } ) ;
168167
169- it ( 'should show error state when applyToWorkspace fails' , async ( ) => {
168+ it ( 'should show error state when applyToPageTree fails' , async ( ) => {
170169 const { view, widget} = await createPatchWidget ( { aidaClient : mockAidaClient ( [ [ MockAidaFetchError ] ] ) } ) ;
171170 widget . changeSummary = 'body { background-color: red; }' ;
172171
@@ -188,28 +187,47 @@ Files:
188187 } ) ;
189188
190189 describe ( 'diff view' , ( ) => {
190+ const origContent = 'window.foo = () => "foo";\n' ;
191191 let fileSystemUISourceCode : Workspace . UISourceCode . UISourceCode ;
192192 let commitWorkingCopyStub :
193193 sinon . SinonStub < Parameters < typeof Workspace . UISourceCode . UISourceCode . prototype . commitWorkingCopy > > ;
194194 let resetWorkingCopyStub :
195195 sinon . SinonStub < Parameters < typeof Workspace . UISourceCode . UISourceCode . prototype . resetWorkingCopy > > ;
196196
197197 beforeEach ( ( ) => {
198- fileSystemUISourceCode = createTestFilesystem ( 'file://test' ) . uiSourceCode ;
199- Common . Settings . Settings . instance ( ) . createSetting ( 'ai-assistance-patching-selected-project-id' , 'file://test' ) ;
200198 updateHostConfig ( {
201199 devToolsFreestyler : {
202200 enabled : true ,
203201 patching : true ,
204202 } ,
205203 } ) ;
206204
205+ const url = Platform . DevToolsPath . urlString `https://example.com/script.js` ;
206+ createContentProviderUISourceCode ( {
207+ url,
208+ content : origContent ,
209+ mimeType : 'text/javascript' ,
210+ projectType : Workspace . Workspace . projectTypes . Network ,
211+ metadata : new Workspace . UISourceCode . UISourceCodeMetadata ( null , origContent . length ) ,
212+ } ) ;
213+
207214 commitWorkingCopyStub =
208215 sinon . stub ( Workspace . UISourceCode . UISourceCode . prototype , 'commitWorkingCopy' ) . callThrough ( ) ;
209216 resetWorkingCopyStub =
210217 sinon . stub ( Workspace . UISourceCode . UISourceCode . prototype , 'resetWorkingCopy' ) . callThrough ( ) ;
211218 } ) ;
212219
220+ const createBoundFileSystemUISourceCode = ( ) => {
221+ const localUrl = Platform . DevToolsPath . urlString `file:///var/www/script.js` ;
222+ ( { uiSourceCode : fileSystemUISourceCode } = createFileSystemUISourceCode ( {
223+ url : localUrl ,
224+ mimeType : 'text/javascript' ,
225+ content : origContent ,
226+ autoMapping : true ,
227+ metadata : new Workspace . UISourceCode . UISourceCodeMetadata ( null , origContent . length ) ,
228+ } ) ) ;
229+ } ;
230+
213231 it ( 'on apply should call handle function and stash changes' , async ( ) => {
214232 const {
215233 view,
@@ -223,22 +241,31 @@ Files:
223241 assert . isTrue ( changeManager . stashChanges . calledOnce ) ;
224242 } ) ;
225243
226- it ( 'save all should commit the working copy of the changed UI codes to the disk and render savedToDisk view' ,
227- async ( ) => {
228- const { view, widget} = await createPatchWidgetWithDiffView ( ) ;
229- const changeManager = sinon . createStubInstance ( AiAssistanceModel . ChangeManager ) ;
230- widget . changeManager = changeManager ;
231- fileSystemUISourceCode . setWorkingCopy ( 'working copy' ) ;
244+ it ( '"save to workspace" is not available if there is no matching file system mapping' , async ( ) => {
245+ const { view, widget} = await createPatchWidgetWithDiffView ( ) ;
246+ const changeManager = sinon . createStubInstance ( AiAssistanceModel . ChangeManager ) ;
247+ widget . changeManager = changeManager ;
248+ assert . isUndefined ( view . input . onSaveToWorkspace ) ;
249+ } ) ;
250+
251+ it ( '"save to workspace" should commit the working copy of the files to disk and update the view' , async ( ) => {
252+ createBoundFileSystemUISourceCode ( ) ;
253+ fileSystemUISourceCode . setWorkingCopy ( 'working copy' ) ;
254+ const { view, widget} = await createPatchWidgetWithDiffView ( ) ;
255+ const changeManager = sinon . createStubInstance ( AiAssistanceModel . ChangeManager ) ;
256+ widget . changeManager = changeManager ;
232257
233- view . input . onSaveAll ( ) ;
234- const nextInput = await view . nextInput ;
258+ assert . isDefined ( view . input . onSaveToWorkspace ) ;
259+ view . input . onSaveToWorkspace ( ) ;
260+ const nextInput = await view . nextInput ;
235261
236- assert . isTrue ( nextInput . savedToDisk ) ;
237- assert . isTrue ( commitWorkingCopyStub . called , 'Expected commitWorkingCopy to be called but it is not called' ) ;
238- assert . isTrue ( changeManager . dropStashedChanges . calledOnce ) ;
239- } ) ;
262+ assert . isTrue ( nextInput . savedToDisk ) ;
263+ assert . isTrue ( commitWorkingCopyStub . called , 'Expected commitWorkingCopy to be called but it is not called' ) ;
264+ assert . isTrue ( changeManager . dropStashedChanges . calledOnce ) ;
265+ } ) ;
240266
241267 it ( 'discard should discard the working copy and render the view without patchSuggestion' , async ( ) => {
268+ createBoundFileSystemUISourceCode ( ) ;
242269 const { view, widget} = await createPatchWidgetWithDiffView ( ) ;
243270 const changeManager = sinon . createStubInstance ( AiAssistanceModel . ChangeManager ) ;
244271 widget . changeManager = changeManager ;
0 commit comments