Skip to content

Commit 3c659d6

Browse files
committed
e2e: Test that dragging to start commit
Test the ability to drag a file into the branch header in order to start a commit.
1 parent e8ff537 commit 3c659d6

File tree

4 files changed

+170
-48
lines changed

4 files changed

+170
-48
lines changed

e2e/playwright/src/commit.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,3 @@ export async function verifyCommitPlaceholderPosition(page: Page) {
7474
await expect(commitTargetPosition).toHaveCount(1);
7575
await expect(commitTargetPosition).toContainClass('first');
7676
}
77-
78-
/**
79-
* Unstage all files in the uncommitted changes list.
80-
*/
81-
export async function unstageAllFiles(page: Page) {
82-
const uncommittedFilesCheckbox = page
83-
.getByTestId('uncommitted-changes-header')
84-
.locator('input[type="checkbox"]');
85-
await expect(uncommittedFilesCheckbox).toBeVisible();
86-
await expect(uncommittedFilesCheckbox).toBeChecked();
87-
await uncommittedFilesCheckbox.click();
88-
}
89-
90-
/**
91-
* Stage the first file in the uncommitted changes list.
92-
*/
93-
export async function stageFirstFile(page: Page) {
94-
const fileItemCheckbox = getByTestId(page, 'uncommitted-changes-file-list')
95-
.getByTestId('file-list-item')
96-
.first()
97-
.locator('input[type="checkbox"]');
98-
await expect(fileItemCheckbox).toBeVisible();
99-
await fileItemCheckbox.click();
100-
}

e2e/playwright/src/file.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,71 @@ export async function discardFile(fileName: string, page: Page): Promise<void> {
5454
.filter({ hasText: fileName });
5555
await expect(fileItem).not.toBeVisible();
5656
}
57+
58+
/**
59+
* Verify that there are no uncommitted changes.
60+
*/
61+
export async function assertNoUncommittedChanges(page: Page): Promise<void> {
62+
const uncommittedChangesList = getByTestId(page, 'uncommitted-changes-file-list');
63+
await expect(uncommittedChangesList).toBeVisible();
64+
const fileItems = uncommittedChangesList.getByTestId('file-list-item');
65+
await expect(fileItems).toHaveCount(0);
66+
}
67+
68+
/**
69+
* Stage the first file in the uncommitted changes list.
70+
*/
71+
export async function stageFirstFile(page: Page) {
72+
const fileItemCheckbox = getByTestId(page, 'uncommitted-changes-file-list')
73+
.getByTestId('file-list-item')
74+
.first()
75+
.locator('input[type="checkbox"]');
76+
await expect(fileItemCheckbox).toBeVisible();
77+
await fileItemCheckbox.click();
78+
}
79+
80+
/**
81+
* Verify that a file is staged for a commit.
82+
*/
83+
export async function assertFileIsStaged(page: Page, fileName: string) {
84+
const fileItemCheckbox = getByTestId(page, 'uncommitted-changes-file-list')
85+
.getByTestId('file-list-item')
86+
.filter({ hasText: fileName })
87+
.locator('input[type="checkbox"]');
88+
await expect(fileItemCheckbox).toBeVisible();
89+
await expect(fileItemCheckbox).toBeChecked();
90+
}
91+
92+
/**
93+
* Verify that a file is unstaged for a commit.
94+
*/
95+
export async function assertFileIsUnstaged(page: Page, fileName: string) {
96+
const fileItemCheckbox = getByTestId(page, 'uncommitted-changes-file-list')
97+
.getByTestId('file-list-item')
98+
.filter({ hasText: fileName })
99+
.locator('input[type="checkbox"]');
100+
await expect(fileItemCheckbox).toBeVisible();
101+
await expect(fileItemCheckbox).not.toBeChecked();
102+
}
103+
104+
/**
105+
* Unstage all files in the uncommitted changes list.
106+
*/
107+
export async function unstageAllFiles(page: Page) {
108+
const uncommittedFilesCheckbox = page
109+
.getByTestId('uncommitted-changes-header')
110+
.locator('input[type="checkbox"]');
111+
await expect(uncommittedFilesCheckbox).toBeVisible();
112+
await expect(uncommittedFilesCheckbox).toBeChecked();
113+
await uncommittedFilesCheckbox.click();
114+
}
115+
116+
/**
117+
* Verify that a file is present in the uncommitted changes list.
118+
*/
119+
export async function assertFileIsUncommitted(page: Page, fileName: string) {
120+
const fileItem = getByTestId(page, 'uncommitted-changes-file-list')
121+
.getByTestId('file-list-item')
122+
.filter({ hasText: fileName });
123+
await expect(fileItem).toBeVisible();
124+
}

e2e/playwright/tests/commitActions.spec.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import {
22
openCommitDrawer,
3-
stageFirstFile,
43
startEditingCommitMessage,
5-
unstageAllFiles,
64
updateCommitMessage,
75
verifyCommitDrawerContent,
86
verifyCommitMessageEditor,
97
verifyCommitPlaceholderPosition
108
} from '../src/commit.ts';
11-
import { writeFiles } from '../src/file.ts';
9+
import { stageFirstFile, unstageAllFiles, writeFiles } from '../src/file.ts';
1210
import { getBaseURL, type GitButler, startGitButler } from '../src/setup.ts';
1311
import {
1412
clickByTestId,
@@ -41,33 +39,13 @@ test('should be able to amend a file to a commit', async ({ page, context }, tes
4139
const filePath = gitbutler.pathInWorkdir('local-clone/b_file');
4240

4341
await gitbutler.runScript('project-with-remote-branches.sh');
42+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
4443

4544
await page.goto('/');
4645

4746
// Should load the workspace
4847
await waitForTestId(page, 'workspace-view');
4948

50-
// Should navigate to the branches page when clicking the branches button
51-
await clickByTestId(page, 'navigation-branches-button');
52-
const header = await waitForTestId(page, 'branch-header');
53-
54-
await expect(header).toContainText('origin/master');
55-
56-
const branchListCards = getByTestId(page, 'branch-list-card');
57-
await expect(branchListCards).toHaveCount(3);
58-
59-
const firstBranchCard = branchListCards.filter({ hasText: 'branch1' });
60-
await expect(firstBranchCard).toBeVisible();
61-
await firstBranchCard.click();
62-
63-
// The delete branch should be visible
64-
await waitForTestId(page, 'branches-view-delete-local-branch-button');
65-
66-
// Apply the branch
67-
await clickByTestId(page, 'branches-view-apply-branch-button');
68-
// Should be redirected to the workspace
69-
await waitForTestId(page, 'workspace-view');
70-
7149
// There should be only one stack
7250
const stacks = getByTestId(page, 'stack');
7351
await expect(stacks).toHaveCount(1);
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { updateCommitMessage, verifyCommitMessageEditor } from '../src/commit.ts';
2+
import {
3+
assertFileContent,
4+
assertFileIsStaged,
5+
assertFileIsUncommitted,
6+
assertFileIsUnstaged
7+
} from '../src/file.ts';
8+
import { getBaseURL, type GitButler, startGitButler } from '../src/setup.ts';
9+
import { clickByTestId, dragAndDropByLocator, getByTestId, waitForTestId } from '../src/util.ts';
10+
import { expect, test } from '@playwright/test';
11+
import { writeFileSync } from 'fs';
12+
13+
let gitbutler: GitButler;
14+
15+
test.use({
16+
baseURL: getBaseURL()
17+
});
18+
19+
test.afterEach(async () => {
20+
await gitbutler.destroy();
21+
});
22+
23+
test('should be able to start a commit by dragging a file', async ({ page, context }, testInfo) => {
24+
const workdir = testInfo.outputPath('workdir');
25+
const configdir = testInfo.outputPath('config');
26+
gitbutler = await startGitButler(workdir, configdir, context);
27+
28+
const fileName = 'b_file';
29+
const filePath = gitbutler.pathInWorkdir('local-clone/' + fileName);
30+
const fileContent = 'Hello! this is file b\n';
31+
const anotherFileName = 'c_file';
32+
const anotherFilePath = gitbutler.pathInWorkdir('local-clone/' + anotherFileName);
33+
const anotherFileContent = 'Hello! this is file c\n';
34+
35+
await gitbutler.runScript('project-with-remote-branches.sh');
36+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
37+
38+
await page.goto('/');
39+
40+
// Should load the workspace
41+
await waitForTestId(page, 'workspace-view');
42+
43+
// There should be only one stack
44+
const stacks = getByTestId(page, 'stack');
45+
await expect(stacks).toHaveCount(1);
46+
const stack = stacks.first();
47+
await expect(stack).toContainText('branch1');
48+
49+
// The stack should have two commits
50+
const commits = getByTestId(page, 'commit-row');
51+
await expect(commits).toHaveCount(2);
52+
53+
// Push the changes to the remote branch
54+
// (it's basically a no-op, just makes sure that the same commits after rebasing are on the remote)
55+
await clickByTestId(page, 'stack-push-button');
56+
57+
// Add a two new files to the workdir
58+
writeFileSync(filePath, fileContent, { flag: 'w' });
59+
writeFileSync(anotherFilePath, anotherFileContent, { flag: 'w' });
60+
61+
const fileLocator = page
62+
.getByTestId('uncommitted-changes-file-list')
63+
.getByTestId('file-list-item')
64+
.filter({
65+
hasText: fileName
66+
});
67+
await expect(fileLocator).toHaveCount(1);
68+
await expect(fileLocator).toBeVisible();
69+
70+
const branchCardLocators = await waitForTestId(page, 'branch-card');
71+
const branchCardLocator = branchCardLocators.filter({
72+
hasText: 'branch1'
73+
});
74+
75+
// Drag the new file onto the top commit, to amend it
76+
await dragAndDropByLocator(page, fileLocator, branchCardLocator);
77+
78+
// Verify that the only the dragged file is now staged
79+
await assertFileIsStaged(page, fileName);
80+
await assertFileIsUnstaged(page, anotherFileName);
81+
82+
const commitTitle = 'New file added';
83+
const commitMessage = `Added ${fileName} to the project`;
84+
85+
// Fill the commit message
86+
await verifyCommitMessageEditor(page, '', '');
87+
await updateCommitMessage(page, commitTitle, commitMessage);
88+
89+
// Submit the commit
90+
await clickByTestId(page, 'commit-drawer-action-button');
91+
const commitRow = getByTestId(page, 'commit-row').filter({ hasText: commitTitle });
92+
await expect(commitRow).toHaveCount(1);
93+
94+
// Verify that the other file is still uncommitted
95+
await assertFileIsUncommitted(page, anotherFileName);
96+
97+
// Verify the file contents are correct
98+
await assertFileContent(filePath, fileContent);
99+
await assertFileContent(anotherFilePath, anotherFileContent);
100+
});

0 commit comments

Comments
 (0)