|
1 | 1 | /** |
2 | 2 | * @vitest-environment node |
3 | 3 | */ |
4 | | -import { describe, expect, it } from 'vitest' |
| 4 | +import { describe, expect, it, vi } from 'vitest' |
| 5 | +import { getBlock } from '@/blocks/registry' |
5 | 6 | import { |
| 7 | + applyDependentOverrides, |
6 | 8 | customBlockInputStorageKey, |
7 | 9 | type ForkReferenceResolver, |
| 10 | + reconfigurableDependentIds, |
8 | 11 | remapForkBlockType, |
9 | 12 | replaceCustomBlockInputs, |
10 | 13 | scanWorkflowReferences, |
@@ -195,3 +198,77 @@ describe('replaceCustomBlockInputs target carry-over', () => { |
195 | 198 | expect(result.workflowId).toEqual({ value: 'wf-prod' }) |
196 | 199 | }) |
197 | 200 | }) |
| 201 | + |
| 202 | +describe('reconfigurableDependentIds', () => { |
| 203 | + const SUBS = [ |
| 204 | + { id: 'credential', type: 'oauth-input' }, |
| 205 | + { id: 'issueType', type: 'short-input', dependsOn: ['credential'] }, |
| 206 | + { id: 'notes', type: 'long-input', dependsOn: ['credential'] }, |
| 207 | + { |
| 208 | + id: 'labelId', |
| 209 | + type: 'file-selector', |
| 210 | + dependsOn: ['credential'], |
| 211 | + selectorKey: 'gmail.labels', |
| 212 | + }, |
| 213 | + { |
| 214 | + id: 'projectId', |
| 215 | + type: 'project-selector', |
| 216 | + dependsOn: ['credential'], |
| 217 | + selectorKey: 'jira.projects', |
| 218 | + canonicalParamId: 'projectId', |
| 219 | + }, |
| 220 | + { |
| 221 | + id: 'manualProjectId', |
| 222 | + type: 'short-input', |
| 223 | + dependsOn: ['credential'], |
| 224 | + canonicalParamId: 'projectId', |
| 225 | + }, |
| 226 | + { id: 'watchColumns', type: 'dropdown', dependsOn: ['credential'] }, |
| 227 | + { id: 'standalone', type: 'short-input' }, |
| 228 | + ] |
| 229 | + |
| 230 | + it('offers selector-backed and plain text dependents', () => { |
| 231 | + const allowed = reconfigurableDependentIds(SUBS) |
| 232 | + expect([...allowed].sort()).toEqual(['issueType', 'labelId', 'notes', 'projectId']) |
| 233 | + }) |
| 234 | + |
| 235 | + it('excludes the manual half of a selector-backed canonical pair', () => { |
| 236 | + expect(reconfigurableDependentIds(SUBS).has('manualProjectId')).toBe(false) |
| 237 | + }) |
| 238 | + |
| 239 | + it('excludes a dependent the modal can render no control for', () => { |
| 240 | + // A `dropdown` with no selector has options to fetch and no way to fetch them here. |
| 241 | + expect(reconfigurableDependentIds(SUBS).has('watchColumns')).toBe(false) |
| 242 | + }) |
| 243 | + |
| 244 | + it('excludes a field that depends on nothing', () => { |
| 245 | + expect(reconfigurableDependentIds(SUBS).has('standalone')).toBe(false) |
| 246 | + }) |
| 247 | + |
| 248 | + it('is the SAME set the sync actually writes back', () => { |
| 249 | + // The collector offers these and `applyDependentOverrides` writes them. Encoding the rule |
| 250 | + // twice is what let text dependents be collected, stored, gated on — then silently dropped |
| 251 | + // on apply, leaving the field wiped on every push with nowhere for the value to go. |
| 252 | + vi.mocked(getBlock).mockReturnValue({ type: 'jira', subBlocks: SUBS } as never) |
| 253 | + const applied = applyDependentOverrides( |
| 254 | + { |
| 255 | + issueType: { value: 'old' }, |
| 256 | + labelId: { value: 'old' }, |
| 257 | + manualProjectId: { value: 'keep-me' }, |
| 258 | + watchColumns: { value: 'keep-me' }, |
| 259 | + }, |
| 260 | + 'jira', |
| 261 | + new Map([ |
| 262 | + ['issueType', 'Bug'], |
| 263 | + ['labelId', 'LABEL_1'], |
| 264 | + ['manualProjectId', 'hacked'], |
| 265 | + ['watchColumns', 'hacked'], |
| 266 | + ]) |
| 267 | + ) |
| 268 | + expect(applied.issueType).toEqual({ value: 'Bug' }) |
| 269 | + expect(applied.labelId).toEqual({ value: 'LABEL_1' }) |
| 270 | + // Not offered, so not writable — an override naming one must not slip through. |
| 271 | + expect(applied.manualProjectId).toEqual({ value: 'keep-me' }) |
| 272 | + expect(applied.watchColumns).toEqual({ value: 'keep-me' }) |
| 273 | + }) |
| 274 | +}) |
0 commit comments