Skip to content

Commit 65c0480

Browse files
committed
Move branch: e2e tests
Add some cool e2e tests to make sure this whole moving branch works
1 parent bfcd3eb commit 65c0480

File tree

6 files changed

+201
-16
lines changed

6 files changed

+201
-16
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
echo "GIT CONFIG $GIT_CONFIG_GLOBAL"
4+
echo "DATA DIR $GITBUTLER_CLI_DATA_DIR"
5+
echo "BUT_TESTING $BUT_TESTING"
6+
echo "BRANCH TO APPLY: $1"
7+
echo "DIRECTORY: $2"
8+
9+
# Apply remote branch to the workspace.
10+
pushd "$2"
11+
$BUT_TESTING -j stack-branches -u -b $1
12+
popd

e2e/playwright/scripts/project-with-remote-branches__apply-branch-1.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
echo "GIT CONFIG $GIT_CONFIG_GLOBAL"
4+
echo "DATA DIR $GITBUTLER_CLI_DATA_DIR"
5+
echo "BUT_TESTING $BUT_TESTING"
6+
7+
# Setup a remote project.
8+
# GitButler currently requires projects to have a remote
9+
mkdir remote-project
10+
pushd remote-project
11+
git init -b master --object-format=sha1
12+
echo "foo" >> a_file
13+
echo "bar" >> a_file
14+
echo "baz" >> a_file
15+
git add a_file
16+
git commit -am "Hey, look! A commit."
17+
18+
# Create branch 1
19+
git checkout -b branch1
20+
echo "branch1 commit 1" >> a_file
21+
git commit -am "branch1: first commit"
22+
echo "branch1 commit 2" >> a_file
23+
git commit -am "branch1: second commit"
24+
echo "branch1 commit 1" >> a_file
25+
git commit -am "branch1: third commit"
26+
echo "branch1 commit 2" >> a_file
27+
git commit -am "branch1: fourth commit"
28+
git checkout master
29+
30+
# Create branch 2
31+
# Branch 2 is independent
32+
git checkout -b branch2
33+
echo "branch2 commit 1" >> b_file
34+
git add b_file
35+
git commit -am "branch2: first commit"
36+
echo "branch2 commit 2" >> b_file
37+
git commit -am "branch2: second commit"
38+
git checkout master
39+
40+
# Create branch 3, also independent
41+
git checkout -b branch3
42+
echo "branch3 commit 1" >> c_file
43+
git add c_file
44+
git commit -am "branch3: first commit"
45+
echo "branch3 commit 2" >> c_file
46+
git commit -am "branch3: second commit"
47+
git checkout master
48+
popd
49+
50+
# Clone the remote into a folder and add the project to the application.
51+
git clone remote-project local-clone
52+
pushd local-clone
53+
git checkout master
54+
$BUT_TESTING add-project --switch-to-workspace "$(git rev-parse --symbolic-full-name @{u})"
55+
popd

e2e/playwright/src/util.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,27 @@ export async function dragAndDropByTestId(
5656
await page.mouse.up();
5757
}
5858

59+
type DropOptions = {
60+
force?: boolean;
61+
position?: {
62+
x: number;
63+
y: number;
64+
};
65+
};
66+
5967
/**
6068
* Drag and drop an element onto another element by their locators.
6169
*/
62-
export async function dragAndDropByLocator(page: Page, source: Locator, target: Locator) {
70+
export async function dragAndDropByLocator(
71+
page: Page,
72+
source: Locator,
73+
target: Locator,
74+
options: DropOptions = {}
75+
) {
6376
await source.hover();
6477
await page.mouse.down();
65-
await target.hover();
66-
await target.hover({ force: true });
78+
await target.hover({ force: options.force, position: options.position });
79+
await target.hover({ force: true, position: options.position });
6780
await page.mouse.up();
6881
}
6982

e2e/playwright/tests/branches.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test('should be able to apply a remote branch and integrate the remote changes -
137137
const fileCPath = gitbutler.pathInWorkdir('local-clone/c_file');
138138

139139
await gitbutler.runScript('project-with-remote-branches.sh');
140-
await gitbutler.runScript('project-with-remote-branches__apply-branch-1.sh');
140+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
141141

142142
await page.goto('/');
143143

@@ -197,7 +197,7 @@ test('should be able to apply a remote branch and integrate the remote changes -
197197
const filePath = gitbutler.pathInWorkdir('local-clone/a_file');
198198

199199
await gitbutler.runScript('project-with-remote-branches.sh');
200-
await gitbutler.runScript('project-with-remote-branches__apply-branch-1.sh');
200+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
201201

202202
await page.goto('/');
203203

@@ -543,7 +543,7 @@ test('should handle gracefully applying two conflicting branches', async ({
543543
gitbutler = await startGitButler(workdir, configdir, context);
544544

545545
await gitbutler.runScript('project-with-remote-branches.sh');
546-
await gitbutler.runScript('project-with-remote-branches__apply-branch-1.sh');
546+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
547547

548548
await page.goto('/');
549549

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { getBaseURL, type GitButler, startGitButler } from '../src/setup.ts';
2+
import { dragAndDropByLocator, sleep, waitForTestId } from '../src/util.ts';
3+
import { expect, test } from '@playwright/test';
4+
5+
let gitbutler: GitButler;
6+
7+
test.use({
8+
baseURL: getBaseURL()
9+
});
10+
11+
test.afterEach(async () => {
12+
gitbutler?.destroy();
13+
});
14+
15+
test('move branch to top of other stack', async ({ page, context }, testInfo) => {
16+
const workdir = testInfo.outputPath('workdir');
17+
const configdir = testInfo.outputPath('config');
18+
gitbutler = await startGitButler(workdir, configdir, context);
19+
20+
await gitbutler.runScript('project-with-stacks.sh');
21+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
22+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch2', 'local-clone']);
23+
24+
await page.goto('/');
25+
26+
// Should load the workspace
27+
await waitForTestId(page, 'workspace-view');
28+
29+
let stacks = page.getByTestId('stack');
30+
await expect(stacks).toHaveCount(2);
31+
const stack1 = stacks.filter({ hasText: 'branch1' });
32+
await stack1.isVisible();
33+
const stack2 = stacks.filter({ hasText: 'branch2' });
34+
await stack2.isVisible();
35+
36+
let branchHeaders = page.getByTestId('branch-header');
37+
await expect(branchHeaders).toHaveCount(2);
38+
const branch1Locator = branchHeaders.filter({ hasText: 'branch1' });
39+
const branch2Locator = branchHeaders.filter({ hasText: 'branch2' });
40+
41+
// We need to modify the position a bit in order to drop it in the right dropzone
42+
await dragAndDropByLocator(page, branch1Locator, branch2Locator, {
43+
position: {
44+
x: 120,
45+
y: 0
46+
}
47+
});
48+
49+
// Should have moved branch1 to the top of stack2
50+
stacks = page.getByTestId('stack');
51+
await expect(stacks).toHaveCount(1);
52+
branchHeaders = page.getByTestId('branch-header');
53+
await expect(branchHeaders).toHaveCount(2);
54+
});
55+
56+
test('move branch to the middle of other stack', async ({ page, context }, testInfo) => {
57+
const workdir = testInfo.outputPath('workdir');
58+
const configdir = testInfo.outputPath('config');
59+
gitbutler = await startGitButler(workdir, configdir, context);
60+
61+
await gitbutler.runScript('project-with-stacks.sh');
62+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch1', 'local-clone']);
63+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch2', 'local-clone']);
64+
await gitbutler.runScript('apply-upstream-branch.sh', ['branch3', 'local-clone']);
65+
66+
await page.goto('/');
67+
68+
// Should load the workspace
69+
await waitForTestId(page, 'workspace-view');
70+
71+
let stacks = page.getByTestId('stack');
72+
await expect(stacks).toHaveCount(3);
73+
const stack1 = stacks.filter({ hasText: 'branch1' });
74+
await stack1.isVisible();
75+
const stack2 = stacks.filter({ hasText: 'branch2' });
76+
await stack2.isVisible();
77+
const stack3 = stacks.filter({ hasText: 'branch3' });
78+
await stack3.isVisible();
79+
80+
let branchHeaders = page.getByTestId('branch-header');
81+
await expect(branchHeaders).toHaveCount(3);
82+
let branch1Locator = branchHeaders.filter({ hasText: 'branch1' });
83+
const branch2Locator = branchHeaders.filter({ hasText: 'branch2' });
84+
85+
// Move branch 2 on top of branch 1
86+
await dragAndDropByLocator(page, branch2Locator, branch1Locator, {
87+
position: {
88+
x: 120,
89+
y: 0
90+
}
91+
});
92+
stacks = page.getByTestId('stack');
93+
await expect(stacks).toHaveCount(2);
94+
95+
await sleep(500); // It seems that we need to wait a bit for the DOM to stabilize
96+
97+
branchHeaders = page.getByTestId('branch-header');
98+
await expect(branchHeaders).toHaveCount(3);
99+
// Move branch3 on top of branch 1 (which is now in the middle of stack)
100+
const branch3Locator = branchHeaders.filter({ hasText: 'branch3' });
101+
branch1Locator = branchHeaders.filter({ hasText: 'branch1' });
102+
await dragAndDropByLocator(page, branch3Locator, branch1Locator, {
103+
force: true,
104+
position: {
105+
x: 120,
106+
y: -4
107+
}
108+
});
109+
110+
// Should have moved branch1 to the top of stack2
111+
stacks = page.getByTestId('stack');
112+
await expect(stacks).toHaveCount(1);
113+
branchHeaders = page.getByTestId('branch-header');
114+
await expect(branchHeaders).toHaveCount(3);
115+
});

0 commit comments

Comments
 (0)