@@ -20,7 +20,6 @@ const mockState = vi.hoisted(() => ({
2020 tooltip : 'Ready to deploy' ,
2121 } ,
2222 handleDeployClick : vi . fn ( ) ,
23- modalProps : null as { open : boolean } | null ,
2423} ) )
2524
2625vi . mock ( '@sim/emcn' , ( ) => ( {
@@ -38,16 +37,14 @@ vi.mock('@sim/emcn', () => ({
3837} ) )
3938
4039vi . mock ( '@sim/emcn/icons' , ( ) => ( {
41- Upload : ( ) => < span data-testid = 'upload-icon' /> ,
40+ Upload : ( ) => < span /> ,
4241} ) )
4342
4443vi . mock (
4544 '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/deploy-modal' ,
4645 ( ) => ( {
47- DeployModal : ( props : { open : boolean } ) => {
48- mockState . modalProps = props
49- return props . open ? < div role = 'dialog' > Deploy workflow</ div > : null
50- } ,
46+ DeployModal : ( { open } : { open : boolean } ) =>
47+ open ? < div role = 'dialog' > Deploy workflow</ div > : null ,
5148 } )
5249)
5350
@@ -98,7 +95,7 @@ let root: Root
9895
9996function renderDeploy (
10097 overrides : Partial < typeof mockState > = { } ,
101- props : { disabled ?: boolean ; disabledTooltip ?: string } = { }
98+ props : { disabled ?: boolean ; canAdmin ?: boolean } = { }
10299) {
103100 Object . assign ( mockState , overrides )
104101 act ( ( ) => {
@@ -108,14 +105,13 @@ function renderDeploy(
108105 userPermissions = { {
109106 canRead : true ,
110107 canEdit : true ,
111- canAdmin : true ,
112- userPermissions : 'admin' ,
108+ canAdmin : props . canAdmin ?? true ,
109+ userPermissions : props . canAdmin === false ? 'write' : 'admin' ,
113110 isLoading : false ,
114111 error : null ,
115112 } }
116113 compact
117- className = 'resource-action'
118- { ...props }
114+ disabled = { props . disabled }
119115 />
120116 )
121117 } )
@@ -140,7 +136,6 @@ beforeEach(() => {
140136 }
141137 mockState . handleDeployClick . mockReset ( )
142138 mockState . handleDeployClick . mockResolvedValue ( { success : true , shouldOpenModal : true } )
143- mockState . modalProps = null
144139} )
145140
146141afterEach ( ( ) => {
@@ -149,82 +144,34 @@ afterEach(() => {
149144} )
150145
151146describe ( 'Deploy compact mode' , ( ) => {
152- it ( 'renders an accessible compact Deploy action for an undeployed workflow' , ( ) => {
153- renderDeploy ( )
154-
155- const button = container . querySelector ( 'button' )
156- expect ( button ?. getAttribute ( 'aria-label' ) ) . toBe ( 'Deploy' )
157- expect ( button ?. className ) . toContain ( 'resource-action' )
158- expect ( container . querySelector ( '[data-testid="upload-icon"]' ) ) . not . toBeNull ( )
159- expect ( button ?. getAttribute ( 'variant' ) ) . toBe ( 'subtle' )
160- expect ( container . textContent ) . not . toContain ( 'DeployLiveUpdate' )
161- } )
162-
163- it ( 'uses the deployment status in the compact action label' , ( ) => {
164- renderDeploy ( { isDeployed : true } )
165- expect ( container . querySelector ( 'button' ) ?. getAttribute ( 'aria-label' ) ) . toBe ( 'Live' )
166-
167- renderDeploy ( { isDeployed : true , changeDetected : true } )
168- expect ( container . querySelector ( 'button' ) ?. getAttribute ( 'aria-label' ) ) . toBe ( 'Update' )
169- } )
170-
171- it ( 'disables deployment while the active tab is still hydrating another workflow' , ( ) => {
172- renderDeploy ( { hydrationWorkflowId : 'workflow-2' , registryActiveWorkflowId : 'workflow-2' } )
173-
174- expect ( container . querySelector ( 'button' ) ?. disabled ) . toBe ( true )
175- expect ( container . textContent ) . toContain ( 'Loading workflow...' )
176- } )
177-
178- it ( 'uses a caller-provided tooltip for external loading states' , ( ) => {
179- renderDeploy ( { } , { disabled : true , disabledTooltip : 'Loading workflow lock status...' } )
147+ it . each ( [
148+ [ 'Deploy' , { } ] ,
149+ [ 'Live' , { isDeployed : true } ] ,
150+ [ 'Update' , { isDeployed : true , changeDetected : true } ] ,
151+ ] ) ( 'exposes the %s action for its deployment state' , ( label , overrides ) => {
152+ renderDeploy ( overrides )
180153
181- expect ( container . querySelector ( 'button' ) ?. disabled ) . toBe ( true )
182- expect ( container . textContent ) . toContain ( 'Loading workflow lock status...' )
154+ expect ( container . querySelector ( 'button' ) ?. getAttribute ( 'aria-label' ) ) . toBe ( label )
183155 } )
184156
185157 it . each ( [
186- [ 'non-admin users' , { canAdmin : false } ] ,
187- [ 'empty workflows' , { hasBlocks : false } ] ,
188- [ 'locked workflows' , { disabled : true } ] ,
158+ [ 'non-admin users' , { } , { canAdmin : false } ] ,
159+ [ 'empty workflows' , { hasBlocks : false } , { } ] ,
160+ [ 'locked workflows' , { } , { disabled : true } ] ,
189161 [
190162 'unsynchronized workflows' ,
191163 {
192164 readiness : { isBlocked : true , isSyncing : false , tooltip : 'Saving workflow changes' } ,
193165 } ,
166+ { } ,
194167 ] ,
195- ] ) ( 'disables the action for %s' , ( _reason , overrides ) => {
196- const permissions =
197- overrides . canAdmin === false
198- ? {
199- canRead : true ,
200- canEdit : true ,
201- canAdmin : false ,
202- userPermissions : 'write' as const ,
203- isLoading : false ,
204- error : null ,
205- }
206- : undefined
207-
208- Object . assign ( mockState , overrides )
209- act ( ( ) => {
210- root . render (
211- < Deploy
212- activeWorkflowId = 'workflow-1'
213- userPermissions = {
214- permissions ?? {
215- canRead : true ,
216- canEdit : true ,
217- canAdmin : true ,
218- userPermissions : 'admin' ,
219- isLoading : false ,
220- error : null ,
221- }
222- }
223- compact
224- disabled = { overrides . disabled === true }
225- />
226- )
227- } )
168+ [
169+ 'workflows that are still loading' ,
170+ { hydrationWorkflowId : 'workflow-2' , registryActiveWorkflowId : 'workflow-2' } ,
171+ { } ,
172+ ] ,
173+ ] ) ( 'disables the action for %s' , ( _reason , overrides , props ) => {
174+ renderDeploy ( overrides , props )
228175
229176 expect ( container . querySelector ( 'button' ) ?. disabled ) . toBe ( true )
230177 } )
@@ -236,8 +183,6 @@ describe('Deploy compact mode', () => {
236183 container . querySelector ( 'button' ) ?. click ( )
237184 } )
238185
239- expect ( mockState . handleDeployClick ) . toHaveBeenCalledOnce ( )
240- expect ( mockState . modalProps ?. open ) . toBe ( true )
241186 expect ( container . querySelector ( '[role="dialog"]' ) ) . not . toBeNull ( )
242187 } )
243188} )
0 commit comments