-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Property filter token type Enum #85
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,6 +587,95 @@ describe('extended operators', () => { | |
}); | ||
}); | ||
|
||
describe('matching enum token', () => { | ||
const obj = { value: 0 }; | ||
const items = [ | ||
/* index=0 */ { status: 'ACTIVE' }, | ||
/* index=1 */ { status: 'ACTIVATING' }, | ||
/* index=2 */ { status: 'NOT_ACTIVE' }, | ||
/* index=3 */ { status: 'DEACTIVATING' }, | ||
/* index=4 */ { status: 'TERMINATED' }, | ||
/* index=5 */ { status: 0 }, | ||
/* index=6 */ { status: obj }, | ||
]; | ||
|
||
function processWithProperty(propertyKey: string, operator: string, token: any, itemsOverride = items) { | ||
return processItems( | ||
itemsOverride, | ||
{ | ||
propertyFilteringQuery: { operation: 'and', tokens: [{ propertyKey, operator, value: token }] }, | ||
}, | ||
{ | ||
propertyFiltering: { | ||
filteringProperties: [ | ||
{ | ||
key: 'status', | ||
operators: [ | ||
{ operator: '=', tokenType: 'enum' }, | ||
{ operator: '!=', tokenType: 'enum' }, | ||
{ operator: ':', tokenType: 'enum' }, | ||
{ operator: '!:', tokenType: 'value' }, | ||
], | ||
groupValuesLabel: 'Status values', | ||
propertyLabel: 'Status', | ||
}, | ||
], | ||
}, | ||
} | ||
).items; | ||
} | ||
|
||
test.each(['=', '!=', ':'])('matches nothing when token=null and operator="%s"', operator => { | ||
const processed = processWithProperty('status', operator, null); | ||
expect(processed).toEqual([]); | ||
}); | ||
|
||
test.each(['=', '!=', ':'])('matches nothing when token="" and operator="%s"', operator => { | ||
const processed = processWithProperty('status', operator, ''); | ||
expect(processed).toEqual([]); | ||
}); | ||
|
||
test('matches all when token=[] and operator="!="', () => { | ||
const processed = processWithProperty('status', '!=', []); | ||
expect(processed).toEqual(items); | ||
}); | ||
|
||
test('matches nothing when token=[] and operator="="', () => { | ||
const processed = processWithProperty('status', '=', []); | ||
expect(processed).toEqual([]); | ||
}); | ||
|
||
test.each([{ token: ['NOT_ACTIVE', 'ACTIVE'] }])('matches some when token=$token and operator="="', ({ token }) => { | ||
const processed = processWithProperty('status', '=', token); | ||
expect(processed).toEqual([items[0], items[2]]); | ||
}); | ||
|
||
test.each([{ token: [obj, 0] }])('matches some when token=$token and operator="="', ({ token }) => { | ||
const processed = processWithProperty('status', '=', token); | ||
expect(processed).toEqual([items[5], items[6]]); | ||
}); | ||
|
||
test.each([{ token: ['ACTIVE', 'NOT_ACTIVE'] }])('matches some when token=$token and operator="!="', ({ token }) => { | ||
const processed = processWithProperty('status', '!=', token); | ||
expect(processed).toEqual([items[1], items[3], items[4], items[5], items[6]]); | ||
}); | ||
|
||
test.each([{ token: [0, obj] }])('matches some when token=$token and operator="!="', ({ token }) => { | ||
const processed = processWithProperty('status', '!=', token); | ||
expect(processed).toEqual([items[0], items[1], items[2], items[3], items[4]]); | ||
}); | ||
|
||
test.each([['ACTIVE'], 'ACTIVE'])('matches nothing when token=%s and operator=":"', token => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is because the token type for ":" is set as "enum" so the enum matchers are used and those are only defined for "=" and "!=". It will work should the token type be "value" or missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, I'd missed the line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say it is enough to ensure the Btw, we can alternatively throw instead of returning false when an unsupported configuration is used. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throwing might be excessive, but I think a dev time warning would make sense, sounds a good improvement. |
||
const processed = processWithProperty('status', ':', token); | ||
expect(processed).toEqual([]); | ||
}); | ||
|
||
test('matches some when token="ING" and operator="!:"', () => { | ||
const processed = processWithProperty('status', '!:', 'ING'); | ||
expect(processed).toEqual([items[0], items[2], items[4], items[5], items[6]]); | ||
}); | ||
}); | ||
|
||
describe('Token groups', () => { | ||
test('token groups have precedence over tokens', () => { | ||
const { items: processed } = processItems( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
test.each
here (and below)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is partially for convenience with other tests so that the tokens are defined here and not in the test body and partially to reflect the token in the test description (with $token).