@@ -136,7 +136,7 @@ describe('WorkflowDiffEngine', () => {
136136 describe ( 'hasBlockChanged detection' , ( ) => {
137137 describe ( 'locked state changes' , ( ) => {
138138 it . concurrent (
139- 'should detect when block locked state changes from false to true' ,
139+ 'should NOT detect a diff when only the locked state changes ( false -> true) ' ,
140140 async ( ) => {
141141 const freshEngine = new WorkflowDiffEngine ( )
142142 const baseline = createMockWorkflowState ( {
@@ -154,7 +154,10 @@ describe('WorkflowDiffEngine', () => {
154154 )
155155
156156 expect ( result . success ) . toBe ( true )
157- expect ( result . diff ?. diffAnalysis ?. edited_blocks ) . toContain ( 'block-1' )
157+ expect ( result . diff ?. diffAnalysis ?. edited_blocks ?? [ ] ) . not . toContain ( 'block-1' )
158+ expect (
159+ result . diff ?. diffAnalysis ?. field_diffs ?. [ 'block-1' ] ?. changed_fields ?? [ ]
160+ ) . not . toContain ( 'locked' )
158161 }
159162 )
160163
@@ -171,43 +174,57 @@ describe('WorkflowDiffEngine', () => {
171174 const result = await freshEngine . createDiffFromWorkflowState ( proposed , undefined , baseline )
172175
173176 expect ( result . success ) . toBe ( true )
174- expect ( result . diff ?. diffAnalysis ?. edited_blocks ) . not . toContain ( 'block-1' )
177+ expect ( result . diff ?. diffAnalysis ?. edited_blocks ?? [ ] ) . not . toContain ( 'block-1' )
175178 } )
176179
177- it . concurrent ( 'should detect change when locked goes from undefined to true' , async ( ) => {
178- const freshEngine = new WorkflowDiffEngine ( )
179- const baseline = createMockWorkflowState ( {
180- 'block-1' : createMockBlock ( { id : 'block-1' } ) , // locked undefined
181- } )
180+ it . concurrent (
181+ 'should NOT detect a diff when locked goes from undefined to true' ,
182+ async ( ) => {
183+ const freshEngine = new WorkflowDiffEngine ( )
184+ const baseline = createMockWorkflowState ( {
185+ 'block-1' : createMockBlock ( { id : 'block-1' } ) ,
186+ } )
182187
183- const proposed = createMockWorkflowState ( {
184- 'block-1' : createMockBlock ( { id : 'block-1' , locked : true } ) ,
185- } )
188+ const proposed = createMockWorkflowState ( {
189+ 'block-1' : createMockBlock ( { id : 'block-1' , locked : true } ) ,
190+ } )
186191
187- const result = await freshEngine . createDiffFromWorkflowState ( proposed , undefined , baseline )
192+ const result = await freshEngine . createDiffFromWorkflowState (
193+ proposed ,
194+ undefined ,
195+ baseline
196+ )
188197
189- expect ( result . success ) . toBe ( true )
190- // The hasBlockChanged function uses !!locked for comparison
191- // so undefined -> true should be detected as a change
192- expect ( result . diff ?. diffAnalysis ?. edited_blocks ) . toContain ( 'block-1' )
193- } )
198+ expect ( result . success ) . toBe ( true )
199+ expect ( result . diff ?. diffAnalysis ?. edited_blocks ?? [ ] ) . not . toContain ( 'block-1' )
200+ }
201+ )
194202
195- it . concurrent ( 'should not detect change when both locked states are falsy' , async ( ) => {
196- const freshEngine = new WorkflowDiffEngine ( )
197- const baseline = createMockWorkflowState ( {
198- 'block-1' : createMockBlock ( { id : 'block-1' } ) , // locked undefined
199- } )
203+ it . concurrent (
204+ 'should still detect real edits on a block whose locked state also changed' ,
205+ async ( ) => {
206+ const freshEngine = new WorkflowDiffEngine ( )
207+ const baseline = createMockWorkflowState ( {
208+ 'block-1' : createMockBlock ( { id : 'block-1' , enabled : true , locked : false } ) ,
209+ } )
200210
201- const proposed = createMockWorkflowState ( {
202- 'block-1' : createMockBlock ( { id : 'block-1' , locked : false } ) , // locked false
203- } )
211+ const proposed = createMockWorkflowState ( {
212+ 'block-1' : createMockBlock ( { id : 'block-1' , enabled : false , locked : true } ) ,
213+ } )
204214
205- const result = await freshEngine . createDiffFromWorkflowState ( proposed , undefined , baseline )
215+ const result = await freshEngine . createDiffFromWorkflowState (
216+ proposed ,
217+ undefined ,
218+ baseline
219+ )
206220
207- expect ( result . success ) . toBe ( true )
208- // undefined and false should both be falsy, so !! comparison makes them equal
209- expect ( result . diff ?. diffAnalysis ?. edited_blocks ) . not . toContain ( 'block-1' )
210- } )
221+ expect ( result . success ) . toBe ( true )
222+ expect ( result . diff ?. diffAnalysis ?. edited_blocks ) . toContain ( 'block-1' )
223+ const changed = result . diff ?. diffAnalysis ?. field_diffs ?. [ 'block-1' ] ?. changed_fields ?? [ ]
224+ expect ( changed ) . toContain ( 'enabled' )
225+ expect ( changed ) . not . toContain ( 'locked' )
226+ }
227+ )
211228 } )
212229
213230 describe ( 'parent scope changes' , ( ) => {
0 commit comments