Skip to content

Commit 2056294

Browse files
committed
fix & E2E: Add edit mode e2e test and fix the edit commit flow
Add a Playwright E2E test (e2e/playwright/tests/editMode.spec.ts) that exercises editing a commit via the edit mode UI. The test sets up a gitbutler workspace, applies a remote branch, opens the app, triggers the edit commit flow, writes a new file in the workdir, and clicks the save-and-exit button to ensure changes are persisted. Also, fix: - How we determine whether to show the warning for the users that want to edit a conflicted commit - Some reactivity issues that would potentially trigger ‘expected to be in the edit mode’ errors
1 parent f5df576 commit 2056294

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

apps/desktop/src/components/CommitContextMenu.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<ContextMenuItem
173173
label="Edit commit"
174174
icon="edit-commit"
175+
testId={TestId.CommitRowContextMenu_EditCommit}
175176
disabled={isReadOnly}
176177
onclick={(e: MouseEvent) => {
177178
if (!isReadOnly) {

apps/desktop/src/components/EditMode.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@
165165
}
166166
167167
async function abort() {
168+
if (loading) return;
168169
await abortEdit({ projectId });
169170
}
170171
171172
async function save() {
173+
if (loading) return;
172174
await saveEdit({ projectId });
173175
}
174176
@@ -342,7 +344,7 @@
342344
</p>
343345
{#snippet controls(close)}
344346
<Button kind="outline" type="reset" onclick={close}>Cancel</Button>
345-
<Button style="error" type="submit">Save and exit</Button>
347+
<Button style="error" type="submit" {loading}>Save and exit</Button>
346348
{/snippet}
347349
</Modal>
348350

apps/desktop/src/components/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function isLocalAndRemoteCommit(commit: Commit | UpstreamCommit): commit
4848
}
4949

5050
export function hasConflicts(commit: Commit): boolean {
51-
return commit.state.type === 'LocalAndRemote' && commit.id !== commit.state.subject;
51+
return commit.hasConflicts;
5252
}
5353

5454
export function getBranchStatusLabelAndColor(pushStatus: PushStatus): {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { getBaseURL, startGitButler, type GitButler } from '../src/setup.ts';
2+
import { clickByTestId, waitForTestId } from '../src/util.ts';
3+
import { expect, test } from '@playwright/test';
4+
import { readFileSync, writeFileSync } from 'fs';
5+
6+
let gitbutler: GitButler;
7+
8+
test.use({
9+
baseURL: getBaseURL()
10+
});
11+
12+
test.afterEach(async () => {
13+
gitbutler?.destroy();
14+
});
15+
16+
test('should be able to edit a commit through the edit mode', async ({
17+
page,
18+
context
19+
}, testInfo) => {
20+
const workdir = testInfo.outputPath('workdir');
21+
const configdir = testInfo.outputPath('config');
22+
gitbutler = await startGitButler(workdir, configdir, context);
23+
24+
const fileBPath = gitbutler.pathInWorkdir('file-b.txt');
25+
26+
await gitbutler.runScript('project-with-remote-branches.sh');
27+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
28+
29+
await page.goto('/');
30+
31+
// Should load the workspace
32+
await waitForTestId(page, 'workspace-view');
33+
34+
const commitRows = page.getByTestId('commit-row');
35+
await expect(commitRows).toHaveCount(2);
36+
const bottomCommit = commitRows.filter({ hasText: 'branch1: first commit' });
37+
38+
bottomCommit.click({ button: 'right' });
39+
await clickByTestId(page, 'commit-row-context-menu-edit-commit');
40+
// Should open the edit mode
41+
await waitForTestId(page, 'edit-mode');
42+
43+
// Create another file to commit
44+
writeFileSync(fileBPath, 'This is file B\n', { encoding: 'utf-8' });
45+
46+
// Click the save and exit button
47+
await clickByTestId(page, 'edit-mode-save-and-exit-button');
48+
49+
// Should be back in the workspace
50+
await waitForTestId(page, 'workspace-view');
51+
52+
const fileBContent = readFileSync(fileBPath, { encoding: 'utf-8' });
53+
54+
expect(fileBContent).toEqual('This is file B\n');
55+
});

packages/ui/src/lib/utils/testIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export enum TestId {
4343
CommitRowContextMenu = 'commit-row-context-menu',
4444
CommitRowContextMenu_UncommitMenuButton = 'commit-row-context-menu-uncommit-menu-btn',
4545
CommitRowContextMenu_EditMessageMenuButton = 'commit-row-context-menu-edit-message-menu-btn',
46+
CommitRowContextMenu_EditCommit = 'commit-row-context-menu-edit-commit',
4647
NewCommitView = 'new-commit-view',
4748
StackDraft = 'draft-stack',
4849
YourCommitGoesHere = 'your-commit-goes-here',

0 commit comments

Comments
 (0)