11import "~/index.css" ;
22import { EnvironmentId , ProjectId } from "@t3tools/contracts" ;
3+ import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients" ;
34import { expect , it , vi } from "vite-plus/test" ;
45import { page , userEvent } from "vite-plus/test/browser" ;
56
@@ -17,11 +18,18 @@ vi.mock(
1718) ;
1819
1920vi . mock ( import ( "../ui/toast" ) , ( ) => ( { toastManager : { add : mocks . notify } } ) as never ) ;
21+ vi . mock ( import ( "~/state/server" ) , async ( ) => {
22+ const { Atom } = await import ( "effect/reactivity" ) ;
23+ return { primaryServerKeybindingsAtom : Atom . make ( [ ] ) } as never ;
24+ } ) ;
25+ vi . mock ( import ( "./PullRequestThreadLinks" ) , ( ) => ( { PullRequestThreadLinks : ( ) => null } ) ) ;
26+ vi . mock (
27+ import ( "./PullRequestDetailActions" ) ,
28+ ( ) => ( { ActOnEnvironmentPicker : ( ) => null } ) as never ,
29+ ) ;
2030
2131import { render } from "../../../test/render" ;
22- import { Menu , MenuPopup , MenuTrigger } from "../ui/menu" ;
23-
24- import { PullRequestMaintainerEdits } from "./PullRequestMaintainerEdits" ;
32+ import { PullRequestActionsMenu } from "./PullRequestActionsMenu" ;
2533
2634const reference = { projectId : ProjectId . make ( "project" ) , repository : "owner/repo" , number : 7 } ;
2735const environmentId = EnvironmentId . make ( "environment" ) ;
@@ -30,19 +38,74 @@ function setup() {
3038 mocks . update . mockReset ( ) . mockResolvedValue ( { _tag : "Success" } ) ;
3139 mocks . notify . mockReset ( ) ;
3240 const onSaved = vi . fn ( ) ;
33- const control = ( allowed = true ) => (
34- < Menu >
35- < MenuTrigger > More pull request actions</ MenuTrigger >
36- < MenuPopup keepMounted >
37- < PullRequestMaintainerEdits
38- environmentId = { environmentId }
39- reference = { reference }
40- enabled = { true }
41- allowed = { allowed }
42- onSaved = { onSaved }
43- />
44- </ MenuPopup >
45- </ Menu >
41+ const control = ( allowed = true , enabled = true ) => (
42+ < PullRequestActionsMenu
43+ environmentId = { environmentId }
44+ reference = { reference }
45+ pullRequestKey = "owner/repo/7"
46+ detail = { {
47+ url : "https://github.com/owner/repo/pull/7" ,
48+ state : "open" ,
49+ isDraft : false ,
50+ headBranch : "feature" ,
51+ maintainerCanModify : enabled ,
52+ capabilities : {
53+ diff : true ,
54+ comment : true ,
55+ actions : [ ] ,
56+ mergeMethods : [ ] ,
57+ search : true ,
58+ review : { inlineComment : true , reply : true , resolve : true , verdicts : [ ] } ,
59+ reviewers : { request : true , listCandidates : true } ,
60+ edit : { changeRequest : true , comment : true , maintainerEdits : true } ,
61+ } ,
62+ viewerPermissions : {
63+ actions : [ ] ,
64+ comment : true ,
65+ resolve : true ,
66+ verdicts : [ ] ,
67+ requestReviewers : true ,
68+ maintainerEdits : true ,
69+ } ,
70+ } }
71+ terminology = { sourceControlClients . get ( "github" ) . changeRequest }
72+ linkThreadRef = { null }
73+ onThreadPickerOpenChange = { ( ) => { } }
74+ refreshing = { false }
75+ refreshFromHost = { async ( ) => { } }
76+ handoff = { null }
77+ attachesToComposer = { false }
78+ askAboutPullRequest = { ( ) => { } }
79+ explainPullRequest = { ( ) => { } }
80+ canFixFindings = { false }
81+ startFixFindings = { ( ) => { } }
82+ handoffLabels = { { fixFindings : "Fix review findings" } }
83+ canWriteGuide = { false }
84+ guideRunning = { false }
85+ guideWritten = { false }
86+ writeGuide = { ( ) => { } }
87+ pickableEnvironments = { [ ] }
88+ actingEnvironmentId = { environmentId }
89+ onActingEnvironmentChange = { ( ) => { } }
90+ can = { ( ) => false }
91+ autoMergeArmed = { false }
92+ showsDraftToggle = { false }
93+ showsMergeNow = { false }
94+ showsAutoMerge = { false }
95+ showsMergeMethods = { false }
96+ allowedMergeMethods = { [ ] }
97+ selectedMergeMethod = "squash"
98+ onSelectMergeMethod = { ( ) => { } }
99+ showsDeleteBranch = { false }
100+ environmentConnected = { true }
101+ canWriteSourceControl = { allowed }
102+ onMaintainerEditsSaved = { onSaved }
103+ confirmDeleteBranch = { async ( ) => { } }
104+ pendingAction = { null }
105+ perform = { async ( ) => true }
106+ openOnHostText = "Open on GitHub"
107+ copyReference = { ( ) => { } }
108+ />
46109 ) ;
47110 return { control, onSaved } ;
48111}
@@ -128,3 +191,31 @@ it("blocks a session without source control write access", async () => {
128191 await expect . element ( page . getByRole ( "menuitemcheckbox" ) ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
129192 expect ( mocks . update ) . not . toHaveBeenCalled ( ) ;
130193} ) ;
194+
195+ it ( "keeps a second save locked when the first save's refresh arrives" , async ( ) => {
196+ const { control, onSaved } = setup ( ) ;
197+ await using screen = await render ( control ( ) ) ;
198+ await screen . getByRole ( "button" , { name : "More pull request actions" } ) . click ( ) ;
199+ const checkbox = page . getByRole ( "menuitemcheckbox" ) ;
200+ await checkbox . click ( ) ;
201+ await vi . waitFor ( ( ) => expect ( onSaved ) . toHaveBeenCalledTimes ( 1 ) ) ;
202+ let settle ! : ( value : { _tag : "Success" } ) => void ;
203+ mocks . update . mockReturnValueOnce (
204+ new Promise < { _tag : "Success" } > ( ( resolve ) => {
205+ settle = resolve ;
206+ } ) ,
207+ ) ;
208+ await checkbox . click ( ) ;
209+ await expect . element ( checkbox ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
210+ await screen . rerender ( control ( true , false ) ) ;
211+ await expect . element ( checkbox ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
212+ await expect . element ( checkbox ) . toBeChecked ( ) ;
213+ await userEvent . keyboard ( "{Enter}" ) ;
214+ expect ( mocks . update ) . toHaveBeenCalledTimes ( 2 ) ;
215+ settle ( { _tag : "Success" } ) ;
216+ await expect . element ( checkbox ) . not . toHaveAttribute ( "aria-disabled" , "true" ) ;
217+ await expect . element ( checkbox ) . toBeChecked ( ) ;
218+ await screen . rerender ( control ( true , true ) ) ;
219+ await screen . rerender ( control ( true , false ) ) ;
220+ await expect . element ( checkbox ) . not . toBeChecked ( ) ;
221+ } ) ;
0 commit comments