@@ -5,15 +5,12 @@ import { describe, expect, it } from 'vitest'
55import type { ForkDependentReconfig } from '@/lib/api/contracts/workspace-fork'
66import {
77 applyDependentRepick ,
8- DEPENDENT_CLEARED_BY_PARENT ,
98 dependentKey ,
109 effectiveCopyDependentValue ,
1110 effectiveDependentValue ,
1211 getActionableDependentFields ,
1312 getDisplayedDependentFields ,
14- isDependentClearedByParent ,
1513 isDependentConfigurationActionable ,
16- submittedDependentValue ,
1714} from '@/ee/workspace-forking/components/fork-sync/dependent-value'
1815
1916const field = ( overrides : Partial < ForkDependentReconfig > = { } ) : ForkDependentReconfig => ( {
@@ -146,39 +143,15 @@ describe('applyDependentRepick', () => {
146143
147144 expect ( next ) . toEqual ( {
148145 [ dependentKey ( site ) ] : 'site-new' ,
149- [ dependentKey ( drive ) ] : DEPENDENT_CLEARED_BY_PARENT ,
150- [ dependentKey ( spreadsheet ) ] : DEPENDENT_CLEARED_BY_PARENT ,
151- [ dependentKey ( sheet ) ] : DEPENDENT_CLEARED_BY_PARENT ,
146+ [ dependentKey ( drive ) ] : '' ,
147+ [ dependentKey ( spreadsheet ) ] : '' ,
148+ [ dependentKey ( sheet ) ] : '' ,
152149 [ dependentKey ( unrelated ) ] : 'still-keep-me' ,
153150 } )
154151 expect ( effectiveDependentValue ( drive , next , false ) ) . toBe ( '' )
155152 expect ( effectiveCopyDependentValue ( sheet , next ) ) . toBe ( '' )
156153 } )
157154
158- it ( 're-picking the value the field already had leaves its descendants alone' , ( ) => {
159- const spreadsheet = field ( {
160- subBlockKey : 'spreadsheetId' ,
161- currentValue : 'sheet-doc' ,
162- providesContextKey : 'spreadsheetId' ,
163- } )
164- const range = field ( {
165- subBlockKey : 'range' ,
166- currentValue : 'Sheet1!A1:D' ,
167- consumesContextKeys : [ 'spreadsheetId' ] ,
168- } )
169-
170- const next = applyDependentRepick (
171- { } ,
172- spreadsheet ,
173- [ spreadsheet , range ] ,
174- 'sheet-doc' ,
175- effectiveDependentValue ( spreadsheet , { } , false )
176- )
177-
178- expect ( next ) . toEqual ( { [ dependentKey ( spreadsheet ) ] : 'sheet-doc' } )
179- expect ( effectiveDependentValue ( range , next , false ) ) . toBe ( 'Sheet1!A1:D' )
180- } )
181-
182155 it ( 'only changes the selected field when it provides no selector context' , ( ) => {
183156 const leaf = field ( { subBlockKey : 'issueKey' , currentValue : 'ISSUE-1' } )
184157 const unrelated = field ( { subBlockKey : 'label' , currentValue : 'keep-me' } )
@@ -231,96 +204,12 @@ describe('applyDependentRepick', () => {
231204 )
232205 ) . toEqual ( {
233206 [ dependentKey ( projectOne ) ] : 'P1-NEW' ,
234- [ dependentKey ( issueOne ) ] : DEPENDENT_CLEARED_BY_PARENT ,
207+ [ dependentKey ( issueOne ) ] : '' ,
235208 [ dependentKey ( issueTwo ) ] : 'P2-1' ,
236209 } )
237210 } )
238211} )
239212
240- describe ( 'submittedDependentValue' , ( ) => {
241- const mappedParent = { copying : false , parentChanged : false }
242-
243- it ( 'omits an optional descendant a parent re-pick blanked, so the target keeps its value' , ( ) => {
244- const spreadsheet = field ( {
245- subBlockKey : 'spreadsheetId' ,
246- currentValue : 'doc-old' ,
247- providesContextKey : 'spreadsheetId' ,
248- } )
249- const sheet = field ( {
250- subBlockKey : 'sheetName' ,
251- currentValue : 'Sheet1' ,
252- required : true ,
253- consumesContextKeys : [ 'spreadsheetId' ] ,
254- } )
255- const range = field ( {
256- subBlockKey : 'range' ,
257- currentValue : 'A1:D50' ,
258- required : false ,
259- consumesContextKeys : [ 'spreadsheetId' ] ,
260- } )
261-
262- const next = applyDependentRepick (
263- { } ,
264- spreadsheet ,
265- [ spreadsheet , sheet , range ] ,
266- 'doc-new' ,
267- effectiveDependentValue ( spreadsheet , { } , false )
268- )
269-
270- expect ( isDependentClearedByParent ( range , next ) ) . toBe ( true )
271- expect ( submittedDependentValue ( range , next , mappedParent ) ) . toBeUndefined ( )
272- expect ( submittedDependentValue ( sheet , next , mappedParent ) ) . toBeUndefined ( )
273- expect ( submittedDependentValue ( spreadsheet , next , mappedParent ) ) . toBe ( 'doc-new' )
274- } )
275-
276- it ( 'submits an empty value the user picked themselves, so an explicit clear still clears' , ( ) => {
277- const label = field ( { subBlockKey : 'label' , currentValue : 'INBOX' } )
278-
279- const next = applyDependentRepick ( { } , label , [ label ] , '' , 'INBOX' )
280-
281- expect ( isDependentClearedByParent ( label , next ) ) . toBe ( false )
282- expect ( submittedDependentValue ( label , next , mappedParent ) ) . toBe ( '' )
283- } )
284-
285- it ( 'submits a re-picked descendant once the user chooses a replacement' , ( ) => {
286- const spreadsheet = field ( {
287- subBlockKey : 'spreadsheetId' ,
288- currentValue : 'doc-old' ,
289- providesContextKey : 'spreadsheetId' ,
290- } )
291- const range = field ( {
292- subBlockKey : 'range' ,
293- currentValue : 'A1:D50' ,
294- consumesContextKeys : [ 'spreadsheetId' ] ,
295- } )
296-
297- const cleared = applyDependentRepick (
298- { } ,
299- spreadsheet ,
300- [ spreadsheet , range ] ,
301- 'doc-new' ,
302- effectiveDependentValue ( spreadsheet , { } , false )
303- )
304- const repicked = applyDependentRepick (
305- cleared ,
306- range ,
307- [ spreadsheet , range ] ,
308- 'A1:Z' ,
309- effectiveDependentValue ( range , cleared , false )
310- )
311-
312- expect ( submittedDependentValue ( range , repicked , mappedParent ) ) . toBe ( 'A1:Z' )
313- } )
314-
315- it ( 'falls back to the stored value under an unchanged parent and to the source when copying' , ( ) => {
316- const untouched = field ( { subBlockKey : 'label' , currentValue : 'INBOX' } )
317- const copied = field ( { subBlockKey : 'documentSelector' , currentValue : '' , sourceValue : 'doc' } )
318-
319- expect ( submittedDependentValue ( untouched , { } , mappedParent ) ) . toBe ( 'INBOX' )
320- expect ( submittedDependentValue ( copied , { } , { copying : true , parentChanged : false } ) ) . toBe ( 'doc' )
321- } )
322- } )
323-
324213describe ( 'isDependentConfigurationActionable' , ( ) => {
325214 it ( 'hides stored values when the mapped parent is unchanged' , ( ) => {
326215 expect (
@@ -392,51 +281,6 @@ describe('isDependentConfigurationActionable', () => {
392281 ) . toBe ( true )
393282 } )
394283
395- it ( 'shows a required field that a parent re-pick blanked (it blocks Sync)' , ( ) => {
396- const spreadsheet = field ( {
397- subBlockKey : 'spreadsheetId' ,
398- currentValue : 'doc-old' ,
399- providesContextKey : 'spreadsheetId' ,
400- } )
401- const sheet = field ( {
402- subBlockKey : 'sheetName' ,
403- required : true ,
404- currentValue : 'Sheet1' ,
405- consumesContextKeys : [ 'spreadsheetId' ] ,
406- } )
407- const next = applyDependentRepick (
408- { } ,
409- spreadsheet ,
410- [ spreadsheet , sheet ] ,
411- 'doc-new' ,
412- effectiveDependentValue ( spreadsheet , { } , false )
413- )
414-
415- // The sync gate reads the same blank the selector shows, so the field gates and is visible.
416- expect ( effectiveDependentValue ( sheet , next , false ) ) . toBe ( '' )
417- expect (
418- isDependentConfigurationActionable ( sheet , next , {
419- parentResolved : true ,
420- parentChanged : false ,
421- copying : false ,
422- } )
423- ) . toBe ( true )
424- } )
425-
426- it ( 'shows a required field the user emptied themselves (it blocks Sync)' , ( ) => {
427- const sheet = field ( { subBlockKey : 'sheetName' , required : true , currentValue : 'Sheet1' } )
428- const next = applyDependentRepick ( { } , sheet , [ sheet ] , '' , 'Sheet1' )
429-
430- expect ( effectiveDependentValue ( sheet , next , false ) ) . toBe ( '' )
431- expect (
432- isDependentConfigurationActionable ( sheet , next , {
433- parentResolved : true ,
434- parentChanged : false ,
435- copying : false ,
436- } )
437- ) . toBe ( true )
438- } )
439-
440284 it ( 'hides dependents until their parent is resolved' , ( ) => {
441285 expect (
442286 isDependentConfigurationActionable (
0 commit comments