11import React from 'react' ;
2- import { describe , it , expect , vi } from 'vitest' ;
2+ import { beforeEach , describe , it , expect , vi } from 'vitest' ;
33import { screen , waitFor } from '@testing-library/react' ;
44import { Formik , Form } from 'formik' ;
55import TransitionForm from './TransitionForm' ;
66import testRender from '../../../../../utils/tests/test-render' ;
77import { WorkflowActionType , CommentMode } from './utils' ;
88import type { WorkflowEditionFormValues } from './WorkflowEditionDrawer' ;
99import type { FilterGroup } from '../../../../../utils/filters/filtersHelpers-types' ;
10+ import useEnterpriseEdition from '../../../../../utils/hooks/useEnterpriseEdition' ;
1011
1112// ---------------------------------------------------------------------------
1213// Mock heavy sub-components with no relevance to the tested logic
@@ -23,6 +24,18 @@ vi.mock('../../../../../components/TextField', () => ({
2324 default : ( { field } : { field : { name : string } } ) => < input data-testid = { `field-${ field . name } ` } /> ,
2425} ) ) ;
2526
27+ vi . mock ( '../../../../../utils/hooks/useEnterpriseEdition' , ( ) => ( {
28+ default : vi . fn ( ) ,
29+ } ) ) ;
30+
31+ vi . mock ( '../../../common/entreprise_edition/EEChip' , ( ) => ( {
32+ default : ( ) => < span data-testid = "ee-chip" /> ,
33+ } ) ) ;
34+
35+ vi . mock ( '../../../common/form/ObjectOrganizationField' , ( ) => ( {
36+ default : ( ) => < div data-testid = "object-organization-field" /> ,
37+ } ) ) ;
38+
2639// ---------------------------------------------------------------------------
2740// Helper: render TransitionForm inside a Formik context
2841// ---------------------------------------------------------------------------
@@ -40,6 +53,10 @@ const renderForm = (initialValues: Partial<WorkflowEditionFormValues>, onSubmit
4053// Tests
4154// ---------------------------------------------------------------------------
4255describe ( 'TransitionForm – comment section' , ( ) => {
56+ beforeEach ( ( ) => {
57+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( true ) ;
58+ } ) ;
59+
4360 it ( 'renders "Enable comment" switch unchecked when comment is "disable"' , ( ) => {
4461 renderForm ( { event : 'approve' , comment : CommentMode . disabled , syncActions : [ ] } ) ;
4562 const enableSwitch = screen . getByRole ( 'checkbox' , { name : / e n a b l e c o m m e n t / i } ) ;
@@ -146,6 +163,10 @@ describe('TransitionForm – comment section', () => {
146163} ) ;
147164
148165describe ( 'TransitionForm – action toggles' , ( ) => {
166+ beforeEach ( ( ) => {
167+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( true ) ;
168+ } ) ;
169+
149170 it ( '"Update authorized members" switch is unchecked when action is absent' , ( ) => {
150171 renderForm ( { event : 'approve' , comment : CommentMode . disabled , syncActions : [ ] } ) ;
151172 const uamSwitch = screen . getByRole ( 'checkbox' , { name : / u p d a t e a u t h o r i z e d m e m b e r s / i } ) ;
@@ -256,6 +277,10 @@ describe('TransitionForm – action toggles', () => {
256277} ) ;
257278
258279describe ( 'TransitionForm – rendering' , ( ) => {
280+ beforeEach ( ( ) => {
281+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( true ) ;
282+ } ) ;
283+
259284 it ( 'renders the transition name field' , ( ) => {
260285 renderForm ( { event : 'approve' , comment : CommentMode . disabled , syncActions : [ ] } ) ;
261286 expect ( screen . getByTestId ( 'field-event' ) ) . toBeDefined ( ) ;
@@ -282,3 +307,78 @@ describe('TransitionForm – rendering', () => {
282307 expect ( screen . getByTestId ( 'workflow-field-list' ) ) . toBeDefined ( ) ;
283308 } ) ;
284309} ) ;
310+
311+ // ---------------------------------------------------------------------------
312+ // EE / CE gating
313+ // ---------------------------------------------------------------------------
314+ describe ( 'TransitionForm – EE / CE gating' , ( ) => {
315+ const emptyFilterGroup : FilterGroup = { mode : 'and' , filters : [ ] , filterGroups : [ ] } ;
316+ const eeActions = [ { type : WorkflowActionType . updateAuthorizedMembers , params : { authorized_members : [ ] } } ] ;
317+
318+ it ( 'disables EE-only switches in CE' , ( ) => {
319+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( false ) ;
320+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : [ ] , asyncActions : [ ] } ) ;
321+
322+ expect ( ( screen . getByRole ( 'checkbox' , { name : / u p d a t e a u t h o r i z e d m e m b e r s / i } ) as HTMLInputElement ) . disabled ) . toBe ( true ) ;
323+ expect ( ( screen . getByRole ( 'checkbox' , { name : / s h a r e w i t h o r g a n i z a t i o n s / i } ) as HTMLInputElement ) . disabled ) . toBe ( true ) ;
324+ expect ( ( screen . getByRole ( 'checkbox' , { name : / u n s h a r e f r o m o r g a n i z a t i o n s / i } ) as HTMLInputElement ) . disabled ) . toBe ( true ) ;
325+ } ) ;
326+
327+ it ( 'enables EE-only switches in EE' , ( ) => {
328+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( true ) ;
329+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : [ ] , asyncActions : [ ] } ) ;
330+
331+ expect ( ( screen . getByRole ( 'checkbox' , { name : / u p d a t e a u t h o r i z e d m e m b e r s / i } ) as HTMLInputElement ) . disabled ) . toBe ( false ) ;
332+ expect ( ( screen . getByRole ( 'checkbox' , { name : / s h a r e w i t h o r g a n i z a t i o n s / i } ) as HTMLInputElement ) . disabled ) . toBe ( false ) ;
333+ expect ( ( screen . getByRole ( 'checkbox' , { name : / u n s h a r e f r o m o r g a n i z a t i o n s / i } ) as HTMLInputElement ) . disabled ) . toBe ( false ) ;
334+ } ) ;
335+
336+ it ( '"Validate draft" switch is always enabled regardless of EE status' , ( ) => {
337+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( false ) ;
338+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : [ ] } ) ;
339+
340+ expect ( ( screen . getByRole ( 'checkbox' , { name : / v a l i d a t e d r a f t / i } ) as HTMLInputElement ) . disabled ) . toBe ( false ) ;
341+ } ) ;
342+
343+ it ( 'renders the conditions block with pointer-events:none in CE' , ( ) => {
344+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( false ) ;
345+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : [ ] , conditions : { filters : emptyFilterGroup } } ) ;
346+
347+ const conditionFilters = screen . getByTestId ( 'workflow-condition-filters' ) ;
348+ const wrapper = conditionFilters . parentElement ! ;
349+ expect ( wrapper . style . pointerEvents ) . toBe ( 'none' ) ;
350+ expect ( wrapper . style . opacity ) . toBe ( '0.5' ) ;
351+ } ) ;
352+
353+ it ( 'renders the conditions block without pointer-events restriction in EE' , ( ) => {
354+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( true ) ;
355+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : [ ] , conditions : { filters : emptyFilterGroup } } ) ;
356+
357+ const conditionFilters = screen . getByTestId ( 'workflow-condition-filters' ) ;
358+ const wrapper = conditionFilters . parentElement ! ;
359+ // 'auto' is CSS default so it serializes as '' in jsdom; just confirm it's not 'none'
360+ expect ( wrapper . style . pointerEvents ) . not . toBe ( 'none' ) ;
361+ expect ( wrapper . style . opacity ) . not . toBe ( '0.5' ) ;
362+ } ) ;
363+
364+ it ( 'renders the WorkflowFieldList with pointer-events:none in CE when EE actions exist' , ( ) => {
365+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( false ) ;
366+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : eeActions } ) ;
367+
368+ const fieldList = screen . getByTestId ( 'workflow-field-list' ) ;
369+ const wrapper = fieldList . parentElement ! ;
370+ expect ( wrapper . style . pointerEvents ) . toBe ( 'none' ) ;
371+ expect ( wrapper . style . opacity ) . toBe ( '0.5' ) ;
372+ } ) ;
373+
374+ it ( 'renders the WorkflowFieldList without pointer-events restriction in EE' , ( ) => {
375+ vi . mocked ( useEnterpriseEdition ) . mockReturnValue ( true ) ;
376+ renderForm ( { event : 'close' , comment : CommentMode . disabled , syncActions : eeActions } ) ;
377+
378+ const fieldList = screen . getByTestId ( 'workflow-field-list' ) ;
379+ const wrapper = fieldList . parentElement ! ;
380+ // 'auto' is CSS default so it serializes as '' in jsdom; just confirm it's not 'none'
381+ expect ( wrapper . style . pointerEvents ) . not . toBe ( 'none' ) ;
382+ expect ( wrapper . style . opacity ) . not . toBe ( '0.5' ) ;
383+ } ) ;
384+ } ) ;
0 commit comments