Skip to content

Commit c4365b4

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
test(selectors): consolidate migration regression coverage
1 parent 677f3ea commit c4365b4

4 files changed

Lines changed: 29 additions & 210 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox.test.tsx

Lines changed: 11 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,14 @@ beforeEach(() => {
9595
})
9696

9797
describe('SelectorCombobox label hydration', () => {
98-
it.each([
99-
{
100-
state: 'preview',
101-
isPreview: true,
102-
disabled: false,
103-
previewValue: 'preview-label',
104-
detailId: 'preview-label',
105-
},
106-
{
107-
state: 'disabled',
108-
isPreview: false,
109-
disabled: true,
110-
previewValue: undefined,
111-
detailId: 'stored-label',
112-
},
113-
])('keeps the list disabled but hydrates the selected value when $state', (state) => {
98+
it('renders a hydrated selected label while disabled without enabling the list', () => {
11499
const html = renderToStaticMarkup(
115100
<SelectorCombobox
116101
blockId='block-1'
117102
subBlock={{ id: 'label', title: 'Label', type: 'combobox' }}
118103
selectorKey='jira.issues'
119104
selectorContext={{ workspaceId: 'workspace-1', oauthCredential: 'credential-1' }}
120-
isPreview={state.isPreview}
121-
disabled={state.disabled}
122-
previewValue={state.previewValue}
105+
disabled
123106
/>
124107
)
125108

@@ -130,72 +113,14 @@ describe('SelectorCombobox label hydration', () => {
130113
)
131114
expect(mockUseSelectorOptionDetail).toHaveBeenCalledWith(
132115
'jira.issues',
133-
expect.objectContaining({ detailId: state.detailId, enabled: true })
116+
expect.objectContaining({ detailId: 'stored-label', enabled: true })
134117
)
135118
})
136119

137-
it.each([
138-
{
139-
state: 'preview',
140-
isPreview: true,
141-
disabled: false,
142-
previewValue: ['preview-label', '{{SHARED_LABEL}}', '<Block.output>'],
143-
detailIds: ['preview-label', '{{SHARED_LABEL}}'],
144-
},
145-
{
146-
state: 'disabled',
147-
isPreview: false,
148-
disabled: true,
149-
previewValue: undefined,
150-
detailIds: ['stored-one', 'stored-two'],
151-
},
152-
])('hydrates selected multi-values without enabling the list when $state', (state) => {
153-
if (!state.isPreview) selectorState.storeValue = ['stored-one', 'stored-two']
154-
155-
const html = renderToStaticMarkup(
156-
<SelectorCombobox
157-
blockId='block-1'
158-
subBlock={{ id: 'labels', title: 'Labels', type: 'combobox' }}
159-
selectorKey='jira.issues'
160-
selectorContext={{ workspaceId: 'workspace-1', oauthCredential: 'credential-1' }}
161-
isPreview={state.isPreview}
162-
disabled={state.disabled}
163-
previewValue={state.previewValue}
164-
multiSelect
165-
/>
166-
)
167-
168-
for (const id of state.detailIds) expect(html).toContain(`Hydrated ${id}`)
169-
if (state.isPreview) expect(html).toContain('&lt;Block.output&gt;')
170-
expect(mockUseSelectorOptions).toHaveBeenCalledWith(
171-
'jira.issues',
172-
expect.objectContaining({ enabled: false })
173-
)
174-
expect(mockUseSelectorOptionDetails).toHaveBeenCalledWith(
175-
'jira.issues',
176-
expect.objectContaining({ detailIds: state.detailIds, enabled: true })
177-
)
178-
})
179-
180-
it.each([
181-
{
182-
state: 'preview',
183-
isPreview: true,
184-
disabled: false,
185-
previewValue: ['preview-label', '{{SHARED_LABEL}}', '<Block.output>'],
186-
listedValues: ['preview-label'],
187-
},
188-
{
189-
state: 'disabled',
190-
isPreview: false,
191-
disabled: true,
192-
previewValue: undefined,
193-
listedValues: ['stored-one', 'stored-two'],
194-
},
195-
])('uses a search-free list to hydrate no-detail multi-values when $state', (state) => {
196-
if (!state.isPreview) selectorState.storeValue = ['stored-one', 'stored-two']
120+
it('renders preview labels from a search-free list when detail lookup is unsupported', () => {
121+
const previewValue = ['preview-label', '{{SHARED_LABEL}}', '<Block.output>']
197122
mockUseSelectorOptions.mockReturnValue({
198-
data: state.listedValues.map((id) => ({ id, label: `Listed ${id}` })),
123+
data: [{ id: 'preview-label', label: 'Listed preview-label' }],
199124
isLoading: false,
200125
hasMore: false,
201126
error: null,
@@ -207,18 +132,15 @@ describe('SelectorCombobox label hydration', () => {
207132
subBlock={{ id: 'labels', title: 'Labels', type: 'combobox' }}
208133
selectorKey='gmail.labels'
209134
selectorContext={{ workspaceId: 'workspace-1', oauthCredential: 'credential-1' }}
210-
isPreview={state.isPreview}
211-
disabled={state.disabled}
212-
previewValue={state.previewValue}
135+
isPreview
136+
previewValue={previewValue}
213137
multiSelect
214138
/>
215139
)
216140

217-
for (const id of state.listedValues) expect(html).toContain(`Listed ${id}`)
218-
if (state.isPreview) {
219-
expect(html).toContain('{{SHARED_LABEL}}')
220-
expect(html).toContain('&lt;Block.output&gt;')
221-
}
141+
expect(html).toContain('Listed preview-label')
142+
expect(html).toContain('{{SHARED_LABEL}}')
143+
expect(html).toContain('&lt;Block.output&gt;')
222144
expect(mockUseSelectorOptions).toHaveBeenCalledWith(
223145
'gmail.labels',
224146
expect.objectContaining({ enabled: true, search: undefined })
@@ -228,24 +150,4 @@ describe('SelectorCombobox label hydration', () => {
228150
expect.objectContaining({ enabled: false })
229151
)
230152
})
231-
232-
it('does not detail-hydrate a runtime reference', () => {
233-
selectorState.storeValue = '<Block.output>'
234-
235-
const html = renderToStaticMarkup(
236-
<SelectorCombobox
237-
blockId='block-1'
238-
subBlock={{ id: 'label', title: 'Label', type: 'combobox' }}
239-
selectorKey='gmail.labels'
240-
selectorContext={{ workspaceId: 'workspace-1', oauthCredential: 'credential-1' }}
241-
disabled
242-
/>
243-
)
244-
245-
expect(html).toContain('&lt;Block.output&gt;')
246-
expect(mockUseSelectorOptionDetail).toHaveBeenCalledWith(
247-
'gmail.labels',
248-
expect.objectContaining({ detailId: undefined, enabled: false })
249-
)
250-
})
251153
})

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-fetched-options.test.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ beforeEach(() => {
5353
})
5454

5555
describe('useFetchedOptions label hydration', () => {
56-
it.each([
57-
{ state: 'preview', isPreview: true, disabled: false },
58-
{ state: 'disabled', isPreview: false, disabled: true },
59-
])('keeps the list disabled but hydrates the selected value when $state', (state) => {
56+
it('hydrates a selected value while a disabled control keeps list interaction off', () => {
6057
function Probe() {
6158
const result = useFetchedOptions({
6259
blockId: 'block-1',
6360
subBlockId: 'label',
6461
dependsOnFields: ['credential'],
6562
selectorKey: 'jira.issues',
66-
isPreview: state.isPreview,
67-
disabled: state.disabled,
63+
isPreview: false,
64+
disabled: true,
6865
valueToHydrate: 'issue-1',
6966
localOptions: [],
7067
})
@@ -82,18 +79,15 @@ describe('useFetchedOptions label hydration', () => {
8279
)
8380
})
8481

85-
it.each([
86-
{ state: 'preview', isPreview: true, disabled: false },
87-
{ state: 'disabled', isPreview: false, disabled: true },
88-
])('hydrates selected multi-values without enabling the list when $state', (state) => {
82+
it('hydrates only eligible multi-values while preview keeps list interaction off', () => {
8983
function Probe() {
9084
const result = useFetchedOptions({
9185
blockId: 'block-1',
9286
subBlockId: 'labels',
9387
dependsOnFields: ['credential'],
9488
selectorKey: 'jira.issues',
95-
isPreview: state.isPreview,
96-
disabled: state.disabled,
89+
isPreview: true,
90+
disabled: false,
9791
valueToHydrate: undefined,
9892
valuesToHydrate: ['label-1', '{{SHARED_LABEL}}', '<Block.output>', 'local-label'],
9993
localOptions: [{ id: 'local-label' }],
@@ -117,10 +111,7 @@ describe('useFetchedOptions label hydration', () => {
117111
)
118112
})
119113

120-
it.each([
121-
{ state: 'preview', isPreview: true, disabled: false },
122-
{ state: 'disabled', isPreview: false, disabled: true },
123-
])('uses a search-free list to hydrate no-detail multi-values when $state', (state) => {
114+
it('uses a search-free list to hydrate a no-detail selector while disabled', () => {
124115
mockUseSelectorOptions.mockReturnValue({
125116
data: [{ id: 'label-1', label: 'Primary label' }],
126117
isLoading: false,
@@ -135,8 +126,8 @@ describe('useFetchedOptions label hydration', () => {
135126
subBlockId: 'labels',
136127
dependsOnFields: ['credential'],
137128
selectorKey: 'gmail.labels',
138-
isPreview: state.isPreview,
139-
disabled: state.disabled,
129+
isPreview: false,
130+
disabled: true,
140131
valueToHydrate: undefined,
141132
valuesToHydrate: ['label-1', '{{SHARED_LABEL}}', '<Block.output>'],
142133
localOptions: [],

apps/sim/lib/imap/selector-policy.test.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

apps/sim/lib/workflows/search-replace/indexer-selector-context.test.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,16 @@ vi.mock('@/tools/params', () => ({
4141
import { getToolInputParamConfigs } from '@/lib/workflows/search-replace/indexer'
4242

4343
describe('tool-input selector fallback context', () => {
44-
beforeEach(() => {
45-
getSubBlocksForToolInput.mockReturnValue(null)
46-
})
47-
48-
it('includes sibling display parameters in selector context', () => {
49-
const configs = getToolInputParamConfigs({
50-
tool: {
51-
type: 'test',
52-
operation: 'list',
53-
params: {
54-
credential: 'credential-1',
55-
resourceId: 'resource-1',
56-
},
57-
},
58-
})
59-
60-
expect(configs.find((config) => config.paramId === 'resourceId')?.selectorContext).toEqual({
61-
oauthCredential: 'credential-1',
62-
})
63-
})
64-
65-
it('includes sibling display parameters when tool sub-blocks also exist', () => {
66-
getSubBlocksForToolInput.mockReturnValue({
67-
subBlocks: [{ id: 'message', title: 'Message', type: 'short-input' }],
68-
})
44+
beforeEach(() => getSubBlocksForToolInput.mockReset())
6945

46+
it.each([
47+
['without generated sub-blocks', null],
48+
[
49+
'with generated sub-blocks',
50+
{ subBlocks: [{ id: 'message', title: 'Message', type: 'short-input' }] },
51+
],
52+
])('includes sibling display parameters $0', (_state, subBlocksResult) => {
53+
getSubBlocksForToolInput.mockReturnValue(subBlocksResult)
7054
const configs = getToolInputParamConfigs({
7155
tool: {
7256
type: 'test',

0 commit comments

Comments
 (0)