Skip to content

Commit

Permalink
Add proof of concept drag & drop e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsgrd committed Dec 5, 2024
1 parent 02c0124 commit c2a87c3
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 23 deletions.
1 change: 1 addition & 0 deletions apps/desktop/e2e/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# -v /tmp/e2e-pnpm-store:/tmp/pnpm-store gitbutler/e2e:latest
# 3. docker cp -a ~/.ssh/id_ed25519.pub e2e-agent:/root/.ssh/authorized_keys
# 4. ssh -p 2222 -Y root@localhost
# 4.5 Fix .ssh/ permissions with chmod and chgrp
# The rest is run inside the container in your SSH session:
# 5. cd /root/gitbutler
# 6. pnpm install && cargo build
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/e2e/scripts/confirm-analytics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -eu -o pipefail

DATA_DIR="$HOME/.local/share/com.gitbutler.app.test"
if [ ! -d "$DATA_DIR" ]; then
echo "Creating data dir: $DATA_DIR"
mkdir -p $DATA_DIR
fi
echo "Confirming analytics"
echo '{"appAnalyticsConfirmed":true}' > $DATA_DIR/settings.json

48 changes: 48 additions & 0 deletions apps/desktop/e2e/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

set -eu -o pipefail

TEMP_DIR=${1:?The first argument is a temp dir}
# Convert to absolute path
TEMP_DIR=$(realpath "$TEMP_DIR")


CLI=$(realpath "../../target/debug/gitbutler-cli")

DATA_DIR="$HOME/.local/share/com.gitbutler.app.test"
if [ -d "$DATA_DIR" ]; then
rm -rf $DATA_DIR
fi

function setGitDefaults() {
git config user.email "[email protected]"
git config user.name "Test User"
git config init.defaultBranch master
}

function tick() {
if test -z "${tick+set}"; then
tick=1675176957
else
tick=$($tick + 60)
fi
GIT_COMMITTER_DATE="$tick +0100"
GIT_AUTHOR_DATE="$tick +0100"
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
}
tick

if [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
mkdir "$TEMP_DIR"

(
cd "$TEMP_DIR"
git init remote
cd remote
setGitDefaults
echo first >file
git add . && git commit -m "init"
)

22 changes: 15 additions & 7 deletions apps/desktop/e2e/tests/add-project.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { spawnAndLog, findAndClick, setElementValue } from '../utils.js';

const TEMP_DIR = '/tmp/gitbutler-add-project';
const REPO_NAME = 'one-vbranch-on-integration';

describe('Project', () => {
before(() => {
spawnAndLog('bash', [
'-c',
'./e2e/scripts/init-repositories.sh ../../target/debug/gitbutler-cli'
`
source ./e2e/scripts/init.sh ${TEMP_DIR}
cd ${TEMP_DIR};
git clone remote ${REPO_NAME} && cd ${REPO_NAME}
$CLI project -s dev add --switch-to-workspace "$(git rev-parse --symbolic-full-name "@{u}")"
$CLI branch create virtual
`
]);
});

it('should add a local project', async () => {
await findAndClick('button[data-testid="analytics-continue"]');

const dirInput = await $('input[data-testid="test-directory-path"]');
setElementValue(dirInput, '/tmp/gb-e2e-repos/one-vbranch-on-integration');
setElementValue(dirInput, `${TEMP_DIR}/${REPO_NAME}`);

await findAndClick('button[data-testid="add-local-project"]');
await findAndClick('button[data-testid="set-base-branch"]');
await findAndClick('button[data-testid="accept-git-auth"]');
await $('button[data-testid="add-local-project"]').then(async (b) => await b.click());
await $('button[data-testid="set-base-branch"]').then(async (b) => await b.click());
await $('button[data-testid="accept-git-auth"]').then(async (b) => await b.click());

const workspaceButton = await $('button=Workspace');
await expect(workspaceButton).toExist();
await expect($('button=Workspace')).toExist();
});
});
40 changes: 40 additions & 0 deletions apps/desktop/e2e/tests/drag-file.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { spawnAndLog } from '../utils.js';
import { codeForSelectors as dragAndDrop } from 'html-dnd';

const TEMP_DIR = '/tmp/gitbutler-drag-files';
const REPO_NAME = 'simple-drag-test';

describe('Drag', () => {
before(() => {
spawnAndLog('bash', [
'-c',
`
source ./e2e/scripts/init.sh ${TEMP_DIR}
bash ./e2e/scripts/confirm-analytics.sh
cd ${TEMP_DIR};
git clone remote ${REPO_NAME} && cd ${REPO_NAME}
setGitDefaults
$CLI project -s test add --switch-to-workspace "$(git rev-parse --symbolic-full-name "@{u}")"
$CLI branch create virtual-one
$CLI branch create virtual-two
echo "hello world" > hello
`
]);
});

it('drag file from one lane to another', async () => {
const fileSelector = '[data-testid="file-hello"]';
const dropSelector = '[data-testid="virtual-two-files-dz"]';

const fileItem = await $(fileSelector);
const dropTarget = await $(dropSelector);
await fileItem.waitForDisplayed();
await dropTarget.waitForDisplayed();

// The actual drop target can be different from the element with the `dropZone` directive..
await driver.executeScript(dragAndDrop, [fileSelector, dropSelector + ' .dropzone-target']);

const finishSelector = await $('[data-testid="branch-virtual-two"] [data-testid="file-hello"]');
await finishSelector.waitForDisplayed();
});
});
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"diff-match-patch": "^1.0.5",
"fuse.js": "^7.0.0",
"git-url-parse": "^14.0.0",
"html-dnd": "^1.2.1",
"jsdom": "^24.1.1",
"lscache": "^1.3.2",
"marked": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/branch/BranchLane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
});
</script>

<div class="wrapper">
<div class="wrapper" data-testid="branch-{branch.name}">
<Stack {commitBoxOpen} {isLaneCollapsed} />

{#if selected}
Expand Down
10 changes: 8 additions & 2 deletions apps/desktop/src/lib/branch/Dropzones.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
interface Props {
children: Snippet;
type?: 'commit' | 'file' | 'all';
id?: string;
}
const { children, type = 'all' }: Props = $props();
const { children, id, type = 'all' }: Props = $props();
const actions = $derived(branchDragActionsFactory.build($branch));
Expand Down Expand Up @@ -51,7 +52,12 @@
{/snippet}

{#snippet branchDropDropzone()}
<Dropzone accepts={acceptsFiles} ondrop={actions.onBranchDrop.bind(actions)} fillHeight>
<Dropzone
accepts={acceptsFiles}
ondrop={actions.onBranchDrop.bind(actions)}
fillHeight
id={id ? id + '-files-dz' : undefined}
>
{@render children()}

{#snippet overlay({ hovered, activated })}
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/dragging/dropzone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class Dropzone {
this.registerListeners();

// Mark the dropzone as active
this.activated = true;
setTimeout(() => {
this.configuration.onActivationStart();
this.activated = true;
}, 10);
}
async reregister(newConfig: DropzoneConfiguration) {
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/lib/dropzone/Dropzone.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
interface Props {
disabled?: boolean;
fillHeight?: boolean;
id?: string;
accepts: (data: any) => boolean;
ondrop: (data: any) => Promise<void> | void;
overlay?: Snippet<[{ hovered: boolean; activated: boolean }]>;
Expand All @@ -14,6 +15,7 @@
const {
disabled = false,
fillHeight = false,
id,
accepts,
ondrop,
overlay,
Expand Down Expand Up @@ -53,6 +55,7 @@
target: '.dropzone-target'
}}
class:fill-height={fillHeight}
data-testid={id}
class="dropzone-container"
>
{#if overlay}
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/stack/Stack.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
{#if branchHasFiles}
<UncommittedChanges {commitBoxOpen} />
{:else if branchHasNoCommits}
<Dropzones type="file">
<Dropzones type="file" id={branch.name}>
<div class="new-branch">
<EmptyStatePlaceholder image={laneNewSvg} width={180} bottomMargin={48}>
{#snippet title()}
Expand Down
4 changes: 1 addition & 3 deletions apps/desktop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
"src/**/*.js",
"src/**/*.ts",
"src/**/*.svelte",
"e2e/tests/**/*.js",
"e2e/tests/**/*.ts",
"e2e/tests/**/*.svelte"
"e2e/**/*.ts",
]
}
1 change: 1 addition & 0 deletions packages/ui/src/lib/file/FileListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
tabindex="-1"
{onclick}
{onkeydown}
data-testid={'file-' + filePath}
oncontextmenu={(e) => {
if (oncontextmenu) {
e.preventDefault();
Expand Down
Loading

0 comments on commit c2a87c3

Please sign in to comment.