Skip to content

Commit 34e26e6

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[PatchWidget] Handle discard and saveAll actions
Fixed: 399559699 Change-Id: I14073f0e3b8107ff4b632c0b87c7c90aeec1feab Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6348560 Reviewed-by: Wolfgang Beyer <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent ee4571a commit 34e26e6

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

front_end/panels/ai_assistance/PatchWidget.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as PanelCommon from '../../panels/common/common.js';
99
import {
1010
cleanup,
1111
createPatchWidget,
12+
createPatchWidgetWithDiffView,
1213
createTestFilesystem,
1314
initializePersistenceImplForTests,
1415
mockAidaClient,
@@ -176,4 +177,51 @@ Files:
176177
assert.strictEqual(input.projectName, 'test2');
177178
});
178179
});
180+
181+
describe('diff view', () => {
182+
let commitWorkingCopyStub:
183+
sinon.SinonStub<Parameters<typeof Workspace.UISourceCode.UISourceCode.prototype.commitWorkingCopy>>;
184+
let resetWorkingCopyStub:
185+
sinon.SinonStub<Parameters<typeof Workspace.UISourceCode.UISourceCode.prototype.resetWorkingCopy>>;
186+
187+
beforeEach(() => {
188+
createTestFilesystem('file://test');
189+
updateHostConfig({
190+
devToolsFreestyler: {
191+
enabled: true,
192+
patching: true,
193+
},
194+
});
195+
196+
commitWorkingCopyStub =
197+
sinon.stub(Workspace.UISourceCode.UISourceCode.prototype, 'commitWorkingCopy').callThrough();
198+
resetWorkingCopyStub =
199+
sinon.stub(Workspace.UISourceCode.UISourceCode.prototype, 'resetWorkingCopy').callThrough();
200+
});
201+
202+
it('save all should commit the working copy of the changed UI codes to the disk and render savedToDisk view',
203+
async () => {
204+
const {uiSourceCode} = createTestFilesystem('file://test');
205+
const {view} = await createPatchWidgetWithDiffView();
206+
207+
uiSourceCode.setWorkingCopy('working copy');
208+
view.input.onSaveAll();
209+
const nextInput = await view.nextInput;
210+
211+
assert.isTrue(nextInput.savedToDisk);
212+
assert.isTrue(commitWorkingCopyStub.called, 'Expected commitWorkingCopy to be called but it is not called');
213+
});
214+
215+
it('discard should discard the working copy and render the view without patchSuggestion', async () => {
216+
const {uiSourceCode} = createTestFilesystem('file://test');
217+
const {view} = await createPatchWidgetWithDiffView();
218+
uiSourceCode.setWorkingCopy('working copy');
219+
220+
view.input.onDiscard();
221+
const nextInput = await view.nextInput;
222+
223+
assert.notExists(nextInput.patchSuggestion);
224+
assert.isTrue(resetWorkingCopyStub.called, 'Expected resetWorkingCopy to be called but it is not called');
225+
});
226+
});
179227
});

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,21 @@ ${processedFiles.map(filename => `* ${filename}`).join('\n')}`;
501501
}
502502

503503
#onDiscard(): void {
504-
// TODO: Remove changes from the working copies as well.
504+
this.#workspaceDiff.modifiedUISourceCodes().forEach(modifiedUISourceCode => {
505+
modifiedUISourceCode.resetWorkingCopy();
506+
});
507+
505508
this.#patchSuggestion = undefined;
506509
this.#patchSources = undefined;
507510
this.requestUpdate();
508511
}
509512

510513
#onSaveAll(): void {
511-
// TODO: Handle saving all the files.
514+
// TODO: What should we do for the inspector stylesheet?
515+
this.#workspaceDiff.modifiedUISourceCodes().forEach(modifiedUISourceCode => {
516+
modifiedUISourceCode.commitWorkingCopy();
517+
});
518+
512519
this.#savedToDisk = true;
513520
this.requestUpdate();
514521
}

front_end/testing/AiAssistanceHelpers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ export async function createPatchWidget(options?: {
229229
};
230230
}
231231

232+
export async function createPatchWidgetWithDiffView() {
233+
const {view, panel, aidaClient} =
234+
await createPatchWidget({aidaClient: mockAidaClient([[{explanation: 'patch applied'}]])});
235+
panel.changeSummary = 'body { background-color: red; }';
236+
view.input.onApplyToWorkspace();
237+
assert.exists((await view.nextInput).patchSuggestion);
238+
239+
return {panel, view, aidaClient};
240+
}
241+
232242
export function initializePersistenceImplForTests(): void {
233243
const workspace = Workspace.Workspace.WorkspaceImpl.instance({forceNew: true});
234244
const debuggerWorkspaceBinding = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance({

0 commit comments

Comments
 (0)