|
5 | 5 | WS_METHODS, |
6 | 6 | VcsProcessExitError, |
7 | 7 | type VcsListRefsResult, |
| 8 | + type VcsStatusResult, |
8 | 9 | } from "@t3tools/contracts"; |
9 | 10 | import { describe, expect, it } from "@effect/vitest"; |
10 | 11 | import * as Deferred from "effect/Deferred"; |
@@ -37,6 +38,7 @@ import { |
37 | 38 | commitVcsRefsRefresh, |
38 | 39 | createVcsEnvironmentAtoms, |
39 | 40 | makeCachedVcsRefsChanges, |
| 41 | + resolveQuickAction, |
40 | 42 | } from "./vcs.ts"; |
41 | 43 | import { |
42 | 44 | invalidateCachedVcsRefs, |
@@ -618,3 +620,47 @@ const grantedSessions = Atom.family((_id: EnvironmentId) => |
618 | 620 | }), |
619 | 621 | ), |
620 | 622 | ); |
| 623 | + |
| 624 | +function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult { |
| 625 | + return { |
| 626 | + isRepo: true, |
| 627 | + hasPrimaryRemote: true, |
| 628 | + isDefaultRef: false, |
| 629 | + refName: "feature/test", |
| 630 | + hasWorkingTreeChanges: false, |
| 631 | + workingTree: { |
| 632 | + files: [], |
| 633 | + insertions: 0, |
| 634 | + deletions: 0, |
| 635 | + }, |
| 636 | + hasUpstream: true, |
| 637 | + aheadCount: 0, |
| 638 | + behindCount: 0, |
| 639 | + pr: null, |
| 640 | + ...overrides, |
| 641 | + }; |
| 642 | +} |
| 643 | + |
| 644 | +describe("resolveQuickAction", () => { |
| 645 | + it("commits local changes without pushing when the branch is behind upstream", () => { |
| 646 | + const behind = status({ hasWorkingTreeChanges: true, behindCount: 2 }); |
| 647 | + const commit = { label: "Commit", disabled: false, kind: "run_action", action: "commit" }; |
| 648 | + expect(resolveQuickAction(behind, false)).toEqual(commit); |
| 649 | + expect( |
| 650 | + resolveQuickAction( |
| 651 | + { |
| 652 | + ...behind, |
| 653 | + pr: { |
| 654 | + number: 13, |
| 655 | + title: "Open PR", |
| 656 | + url: "https://example.com/pr/13", |
| 657 | + baseRef: "main", |
| 658 | + headRef: "feature/test", |
| 659 | + state: "open", |
| 660 | + }, |
| 661 | + }, |
| 662 | + false, |
| 663 | + ), |
| 664 | + ).toEqual(commit); |
| 665 | + }); |
| 666 | +}); |
0 commit comments