Add tests for handling logical operators in UISearchFilter

This commit is contained in:
Andrew Kingston 2024-10-29 15:10:02 +00:00
parent 721b3ab610
commit 765b3d2f97
No known key found for this signature in database
1 changed files with 91 additions and 0 deletions

View File

@ -4298,6 +4298,97 @@ describe.each([
}, },
], ],
}, },
{
name: "can handle logical operator any",
insert: [{ string: "bar" }, { string: "foo" }],
query: {
groups: [
{
logicalOperator: UILogicalOperator.ANY,
filters: [
{
operator: BasicOperator.EQUAL,
field: "string",
value: "foo",
},
{
operator: BasicOperator.EQUAL,
field: "string",
value: "bar",
},
],
},
],
},
searchOpts: {
sort: "string",
sortOrder: SortOrder.ASCENDING,
},
expected: [{ string: "bar" }, { string: "foo" }],
},
{
name: "can handle logical operator all",
insert: [
{ string: "bar", num: 1 },
{ string: "foo", num: 2 },
],
query: {
groups: [
{
logicalOperator: UILogicalOperator.ALL,
filters: [
{
operator: BasicOperator.EQUAL,
field: "string",
value: "foo",
},
{
operator: BasicOperator.EQUAL,
field: "num",
value: 2,
},
],
},
],
},
searchOpts: {
sort: "string",
sortOrder: SortOrder.ASCENDING,
},
expected: [{ string: "foo", num: 2 }],
},
{
name: "overrides allOr with logical operators",
insert: [
{ string: "bar", num: 1 },
{ string: "foo", num: 1 },
],
query: {
groups: [
{
logicalOperator: UILogicalOperator.ALL,
filters: [
{ operator: "allOr" },
{
operator: BasicOperator.EQUAL,
field: "string",
value: "foo",
},
{
operator: BasicOperator.EQUAL,
field: "num",
value: 1,
},
],
},
],
},
searchOpts: {
sort: "string",
sortOrder: SortOrder.ASCENDING,
},
expected: [{ string: "foo", num: 1 }],
},
] ]
it.each(testCases)( it.each(testCases)(