Skip to content

Commit 8629cd8

Browse files
authored
chore: Extends test (#4041)
1 parent e0e818b commit 8629cd8

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

src/property-filter/__tests__/property-filter-token-editor.test.tsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,55 @@ describe.each([false, true])('token editor, expandToViewport=%s', expandToViewpo
139139
expect(editor.header.getElement()).toHaveTextContent(i18nStrings.editTokenHeader!);
140140
});
141141

142-
test('changing the property to a string property without providing a value defaults the value to empty string', () => {
142+
test('changing token property to another property sets correct default value type', () => {
143+
function changeTokenProperty(propertyKey: string) {
144+
const propertyFilter = createWrapper().findPropertyFilter()!;
145+
const tokens = propertyFilter.findTokens();
146+
147+
tokens[0].findLabel().click();
148+
const dropdown = propertyFilter.findTokens()[0].findEditorDropdown({ expandToViewport })!;
149+
const select = dropdown.findForm().findSelect()!;
150+
select.openDropdown();
151+
select.selectOptionByValue(propertyKey);
152+
dropdown.findSubmitButton().click();
153+
}
154+
143155
const onChange = jest.fn();
144-
const { container } = renderComponent({
156+
renderComponent({
145157
onChange,
158+
filteringProperties: [
159+
{ key: 'string', propertyLabel: 'string', operators: ['=', '!='], groupValuesLabel: '' },
160+
{ key: 'other-string', propertyLabel: 'string-other', operators: ['=', '!='], groupValuesLabel: '' },
161+
{ key: 'enum', propertyLabel: 'enum', operators: [{ operator: '=', tokenType: 'enum' }], groupValuesLabel: '' },
162+
{
163+
key: 'date',
164+
propertyLabel: 'date',
165+
operators: [{ operator: '=', form: () => <div /> }],
166+
groupValuesLabel: '',
167+
},
168+
],
146169
query: { tokens: [{ propertyKey: 'string', value: 'value', operator: '=' }], operation: 'and' },
147170
expandToViewport,
148171
});
149172

150-
const propertyFilter = createWrapper(container).findPropertyFilter()!;
151-
const tokens = propertyFilter.findTokens();
152-
expect(tokens).toHaveLength(1);
173+
changeTokenProperty('other-string');
174+
expect(onChange).toHaveBeenCalledWith(
175+
expect.objectContaining({
176+
detail: { tokens: [{ propertyKey: 'other-string', operator: '=', value: '' }], operation: 'and' },
177+
})
178+
);
153179

154-
tokens[0].findLabel().click();
155-
const dropdown = propertyFilter.findTokens()[0].findEditorDropdown({ expandToViewport })!;
156-
const select = dropdown.findForm().findSelect()!;
157-
select.openDropdown();
158-
select.selectOptionByValue('other-string');
159-
dropdown.findSubmitButton().click();
180+
changeTokenProperty('enum');
181+
expect(onChange).toHaveBeenCalledWith(
182+
expect.objectContaining({
183+
detail: { tokens: [{ propertyKey: 'enum', operator: '=', value: [] }], operation: 'and' },
184+
})
185+
);
160186

161-
expect(onChange).toHaveBeenCalledTimes(1);
187+
changeTokenProperty('date');
162188
expect(onChange).toHaveBeenCalledWith(
163189
expect.objectContaining({
164-
detail: {
165-
tokens: [{ propertyKey: 'other-string', value: '', operator: '=' }],
166-
operation: 'and',
167-
},
190+
detail: { tokens: [{ propertyKey: 'date', operator: '=', value: null }], operation: 'and' },
168191
})
169192
);
170193
});

0 commit comments

Comments
 (0)