|
4 | 4 | import { describe, expect, it } from 'vitest' |
5 | 5 | import type { ForkDependentReconfig } from '@/lib/api/contracts/workspace-fork' |
6 | 6 | import { |
| 7 | + applyDependentRepick, |
7 | 8 | dependentKey, |
8 | 9 | effectiveCopyDependentValue, |
9 | 10 | effectiveDependentValue, |
@@ -100,6 +101,74 @@ describe('effectiveCopyDependentValue', () => { |
100 | 101 | }) |
101 | 102 | }) |
102 | 103 |
|
| 104 | +describe('applyDependentRepick', () => { |
| 105 | + it('clears direct and transitive descendants without touching unrelated fields', () => { |
| 106 | + const site = field({ |
| 107 | + subBlockKey: 'siteId', |
| 108 | + currentValue: 'site-old', |
| 109 | + providesContextKey: 'siteId', |
| 110 | + }) |
| 111 | + const drive = field({ |
| 112 | + subBlockKey: 'driveId', |
| 113 | + currentValue: 'drive-old', |
| 114 | + providesContextKey: 'driveId', |
| 115 | + consumesContextKeys: ['siteId'], |
| 116 | + }) |
| 117 | + const spreadsheet = field({ |
| 118 | + subBlockKey: 'spreadsheetId', |
| 119 | + currentValue: 'spreadsheet-old', |
| 120 | + providesContextKey: 'spreadsheetId', |
| 121 | + consumesContextKeys: ['driveId'], |
| 122 | + }) |
| 123 | + const sheet = field({ |
| 124 | + subBlockKey: 'sheetName', |
| 125 | + currentValue: 'Sheet1', |
| 126 | + consumesContextKeys: ['spreadsheetId'], |
| 127 | + }) |
| 128 | + const unrelated = field({ subBlockKey: 'label', currentValue: 'keep-me' }) |
| 129 | + const previous = { |
| 130 | + [dependentKey(drive)]: 'drive-repicked', |
| 131 | + [dependentKey(spreadsheet)]: 'spreadsheet-repicked', |
| 132 | + [dependentKey(sheet)]: 'Sheet2', |
| 133 | + [dependentKey(unrelated)]: 'still-keep-me', |
| 134 | + } |
| 135 | + |
| 136 | + const next = applyDependentRepick( |
| 137 | + previous, |
| 138 | + site, |
| 139 | + [site, drive, spreadsheet, sheet, unrelated], |
| 140 | + 'site-new' |
| 141 | + ) |
| 142 | + |
| 143 | + expect(next).toEqual({ |
| 144 | + [dependentKey(site)]: 'site-new', |
| 145 | + [dependentKey(drive)]: '', |
| 146 | + [dependentKey(spreadsheet)]: '', |
| 147 | + [dependentKey(sheet)]: '', |
| 148 | + [dependentKey(unrelated)]: 'still-keep-me', |
| 149 | + }) |
| 150 | + expect(effectiveDependentValue(drive, next, false)).toBe('') |
| 151 | + expect(effectiveCopyDependentValue(sheet, next)).toBe('') |
| 152 | + }) |
| 153 | + |
| 154 | + it('only changes the selected field when it provides no selector context', () => { |
| 155 | + const leaf = field({ subBlockKey: 'issueKey', currentValue: 'ISSUE-1' }) |
| 156 | + const unrelated = field({ subBlockKey: 'label', currentValue: 'keep-me' }) |
| 157 | + |
| 158 | + expect( |
| 159 | + applyDependentRepick( |
| 160 | + { [dependentKey(unrelated)]: 'still-keep-me' }, |
| 161 | + leaf, |
| 162 | + [leaf, unrelated], |
| 163 | + 'ISSUE-2' |
| 164 | + ) |
| 165 | + ).toEqual({ |
| 166 | + [dependentKey(leaf)]: 'ISSUE-2', |
| 167 | + [dependentKey(unrelated)]: 'still-keep-me', |
| 168 | + }) |
| 169 | + }) |
| 170 | +}) |
| 171 | + |
103 | 172 | describe('isDependentConfigurationActionable', () => { |
104 | 173 | it('hides stored values when the mapped parent is unchanged', () => { |
105 | 174 | expect( |
|
0 commit comments