Skip to content

Commit cf193d4

Browse files
committed
Update cypress tests
1 parent d21e62b commit cf193d4

11 files changed

+77
-0
lines changed

apps/desktop/cypress/e2e/branchActions.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Branch Actions', () => {
1515
mockCommand('update_branch_name', (params) => mockBackend.renameBranch(params));
1616
mockCommand('remove_branch', (params) => mockBackend.removeBranch(params));
1717
mockCommand('create_branch', (params) => mockBackend.addBranch(params));
18+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
1819

1920
cy.visit('/');
2021

apps/desktop/cypress/e2e/branches.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Branches', () => {
2424
mockBackend.createVirtualBranchFromBranch(args)
2525
);
2626
mockCommand('delete_local_branch', (params) => mockBackend.deleteLocalBranch(params));
27+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
2728

2829
cy.visit('/');
2930

apps/desktop/cypress/e2e/commitActions.cy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Commit Actions', () => {
1212
mockCommand('update_commit_message', (params) => mockBackend.updateCommitMessage(params));
1313
mockCommand('changes_in_worktree', (params) => mockBackend.getWorktreeChanges(params));
1414
mockCommand('tree_change_diffs', (params) => mockBackend.getDiff(params));
15+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
1516
mockCommand('commit_details', (params) => mockBackend.getCommitChanges(params));
1617
mockCommand('create_commit_from_worktree_changes', (params) =>
1718
mockBackend.createCommit(params)
@@ -467,6 +468,7 @@ describe('Commit Actions with lots of uncommitted changes', () => {
467468
mockBackend.createCommit(params)
468469
);
469470
mockCommand('undo_commit', (params) => mockBackend.undoCommit(params));
471+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
470472

471473
cy.visit('/');
472474

@@ -825,6 +827,7 @@ describe('Commit Actions with no stacks', () => {
825827
return params.name;
826828
}
827829
});
830+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
828831

829832
cy.visit('/');
830833

apps/desktop/cypress/e2e/errorHandling.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('Error handling - commit actions', () => {
2727
mockCommand('hunk_dependencies_for_workspace_changes', (params) =>
2828
mockBackend.getHunkDependencies(params)
2929
);
30+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
3031

3132
cy.visit('/');
3233

apps/desktop/cypress/e2e/fileTree.cy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('File Tree - multiple file changes', () => {
1010
mockCommand('stacks', () => mockBackend.getStacks());
1111
mockCommand('stack_details', (params) => mockBackend.getStackDetails(params));
1212
mockCommand('changes_in_worktree', (params) => mockBackend.getWorktreeChanges(params));
13+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
1314

1415
cy.visit('/');
1516

@@ -50,6 +51,7 @@ describe('File Tree - some file changes', () => {
5051
mockCommand('stacks', () => mockBackend.getStacks());
5152
mockCommand('stack_details', (params) => mockBackend.getStackDetails(params));
5253
mockCommand('changes_in_worktree', (params) => mockBackend.getWorktreeChanges(params));
54+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
5355

5456
cy.visit('/');
5557

apps/desktop/cypress/e2e/review.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('Review', () => {
2121
mockCommand('push_stack', (params) => mockBackend.pushStack(params));
2222
mockCommand('list_remotes', (params) => mockBackend.listRemotes(params));
2323
mockCommand('update_branch_pr_number', (params) => mockBackend.updateBranchPrNumber(params));
24+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
2425

2526
cy.intercept(
2627
{

apps/desktop/cypress/e2e/selection.cy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Selection', () => {
1212
mockCommand('stacks', () => mockBackend.getStacks());
1313
mockCommand('stack_details', (params) => mockBackend.getStackDetails(params));
1414
mockCommand('changes_in_branch', (args) => mockBackend.getBranchChanges(args));
15+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
1516

1617
cy.visit('/');
1718

@@ -65,6 +66,7 @@ describe('Selection with upstream changes', () => {
6566
mockCommand('stacks', () => mockBackend.getStacks());
6667
mockCommand('stack_details', (params) => mockBackend.getStackDetails(params));
6768
mockCommand('changes_in_branch', (args) => mockBackend.getBranchChanges(args));
69+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
6870

6971
cy.visit('/');
7072

apps/desktop/cypress/e2e/support/mock/backend.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type { Commit } from '$lib/branches/v3';
4040
import type { HunkDependencies } from '$lib/dependencies/dependencies';
4141
import type { TreeChange, TreeChanges, WorktreeChanges } from '$lib/hunks/change';
4242
import type { UnifiedDiff } from '$lib/hunks/diff';
43+
import type { HunkAssignment } from '$lib/hunks/hunk';
4344
import type { GitRemote } from '$lib/remotes/remotesService';
4445
import type { BranchDetails, Stack, StackDetails } from '$lib/stacks/stack';
4546
import type { BranchPushResult } from '$lib/stacks/stackService.svelte';
@@ -161,6 +162,59 @@ export default class MockBackend {
161162
return this.worktreeChanges;
162163
}
163164

165+
public getHunkAssignments(args: InvokeArgs | undefined): HunkAssignment[] {
166+
if (!args || !isGetWorktreeChangesParams(args)) {
167+
throw new Error('Invalid arguments for getHunkAssignments');
168+
}
169+
170+
const out = [];
171+
172+
for (const change of this.worktreeChanges.changes) {
173+
if (change.status.type === 'Addition' || change.status.type === 'Deletion') {
174+
out.push({
175+
hunkHeader: null,
176+
path: change.path,
177+
pathBytes: change.pathBytes,
178+
stackId: null,
179+
hunkLocks: []
180+
});
181+
} else if (change.status.type === 'Rename' || change.status.type === 'Modification') {
182+
const diff = this.getDiff({ projectId: args.projectId, change });
183+
if (diff) {
184+
if (diff.type === 'Binary' || diff.type === 'TooLarge') {
185+
out.push({
186+
hunkHeader: null,
187+
path: change.path,
188+
pathBytes: change.pathBytes,
189+
stackId: null,
190+
hunkLocks: []
191+
});
192+
} else {
193+
for (const hunk of diff.subject.hunks) {
194+
out.push({
195+
hunkHeader: hunk,
196+
path: change.path,
197+
pathBytes: change.pathBytes,
198+
stackId: null,
199+
hunkLocks: []
200+
});
201+
}
202+
}
203+
} else {
204+
out.push({
205+
hunkHeader: null,
206+
path: change.path,
207+
pathBytes: change.pathBytes,
208+
stackId: null,
209+
hunkLocks: []
210+
});
211+
}
212+
}
213+
}
214+
215+
return out;
216+
}
217+
164218
public getWorktreeChangesFileNames(): string[] {
165219
return this.worktreeChanges.changes
166220
.map((change) => change.path)

apps/desktop/cypress/e2e/support/mock/changes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ export type GetWorktreeChangesParams = {
8181
projectId: string;
8282
};
8383

84+
export function hasProjectId(args: unknown): args is { projectId: string } {
85+
return (
86+
typeof args === 'object' &&
87+
args !== null &&
88+
'projectId' in args &&
89+
typeof args['projectId'] === 'string'
90+
);
91+
}
92+
8493
export function isGetWorktreeChangesParams(args: unknown): args is GetWorktreeChangesParams {
8594
return (
8695
typeof args === 'object' &&

apps/desktop/cypress/e2e/unifiedDiffView.cy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('Unified Diff View', () => {
1616
mockCommand('hunk_dependencies_for_workspace_changes', (params) =>
1717
mockBackend.getHunkDependencies(params)
1818
);
19+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
1920

2021
cy.visit('/');
2122
});
@@ -259,6 +260,7 @@ describe('Unified Diff View with complex hunks', () => {
259260
mockCommand('create_commit_from_worktree_changes', (params) =>
260261
mockBackend.createCommit(params)
261262
);
263+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
262264

263265
cy.visit('/');
264266
});

apps/desktop/cypress/e2e/upstreamIntegration.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Upstream Integration', () => {
1414
mockBackend.getUpstreamIntegrationStatuses()
1515
);
1616
mockCommand('integrate_upstream', (params) => mockBackend.integrateUpstream(params));
17+
mockCommand('hunk_assignments', (params) => mockBackend.getHunkAssignments(params));
1718

1819
cy.visit('/');
1920

0 commit comments

Comments
 (0)