-
Notifications
You must be signed in to change notification settings - Fork 77
[WC-3417]: Datagrid Text Filter: fix string filter's empty and non-empty operators #2225
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
Open
rahmanunver
wants to merge
1
commit into
main
Choose a base branch
from
fix/dg2-string-filter-empty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/shared/widget-plugin-filtering/src/__tests__/StringInputFilterStore.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| jest.mock("mendix/filters/builders"); | ||
| import { ListAttributeValue } from "mendix"; | ||
| import { and, attribute, equals, literal, notEqual, or } from "mendix/filters/builders"; | ||
| import { configure } from "mobx"; | ||
| import { attrId, listAttribute } from "@mendix/widget-plugin-test-utils"; | ||
| import { StringInputFilterStore } from "../stores/input/StringInputFilterStore"; | ||
|
|
||
| configure({ enforceActions: "never" }); | ||
|
|
||
| describe("StringInputFilterStore", () => { | ||
| describe("get condition()", () => { | ||
| let attr: ListAttributeValue<string>; | ||
| let store: StringInputFilterStore; | ||
|
|
||
| beforeEach(() => { | ||
| attr = listAttribute(() => "") as ListAttributeValue<string>; | ||
| attr.id = attrId("attr_unset"); | ||
| store = new StringInputFilterStore([attr], null); | ||
| }); | ||
|
|
||
| it("returns compound or() for 'empty' so it catches both null and ''", () => { | ||
| store.filterFunction = "empty"; | ||
| attr.id = attrId("attr_empty_string"); | ||
| expect(store.condition).toEqual( | ||
| or(equals(attribute(attr.id), literal(undefined)), equals(attribute(attr.id), literal(""))) | ||
| ); | ||
| }); | ||
|
|
||
| it("returns compound and() for 'notEmpty' so it excludes both null and ''", () => { | ||
| store.filterFunction = "notEmpty"; | ||
| attr.id = attrId("attr_notempty_string"); | ||
| expect(store.condition).toEqual( | ||
| and(notEqual(attribute(attr.id), literal(undefined)), notEqual(attribute(attr.id), literal(""))) | ||
| ); | ||
| }); | ||
|
|
||
| it("returns plain equals when filterFunction is 'equal'", () => { | ||
| store.filterFunction = "equal"; | ||
| store.arg1.value = "abc"; | ||
| attr.id = attrId("attr_equal"); | ||
| expect(store.condition).toEqual(equals(attribute(attr.id), literal("abc"))); | ||
| }); | ||
| }); | ||
|
|
||
| describe("fromViewState()", () => { | ||
| let attr: ListAttributeValue<string>; | ||
|
|
||
| beforeEach(() => { | ||
| attr = listAttribute(() => "") as ListAttributeValue<string>; | ||
| attr.id = attrId("attr_view"); | ||
| }); | ||
|
|
||
| it("restores 'empty' from compound or() shape", () => { | ||
| const cond = or(equals(attribute(attr.id), literal(undefined)), equals(attribute(attr.id), literal(""))); | ||
| const store = new StringInputFilterStore([attr], cond); | ||
| expect(store.filterFunction).toBe("empty"); | ||
| expect(store.isInitialized).toBe(true); | ||
| }); | ||
|
|
||
| it("restores 'empty' regardless of arg order in compound or()", () => { | ||
| const cond = or(equals(attribute(attr.id), literal("")), equals(attribute(attr.id), literal(undefined))); | ||
| const store = new StringInputFilterStore([attr], cond); | ||
| expect(store.filterFunction).toBe("empty"); | ||
| }); | ||
|
|
||
| it("restores 'notEmpty' from compound and() shape", () => { | ||
| const cond = and( | ||
| notEqual(attribute(attr.id), literal(undefined)), | ||
| notEqual(attribute(attr.id), literal("")) | ||
| ); | ||
| const store = new StringInputFilterStore([attr], cond); | ||
| expect(store.filterFunction).toBe("notEmpty"); | ||
| expect(store.isInitialized).toBe(true); | ||
| }); | ||
|
|
||
| it("restores 'notEmpty' regardless of arg order in compound and()", () => { | ||
| const cond = and( | ||
| notEqual(attribute(attr.id), literal("")), | ||
| notEqual(attribute(attr.id), literal(undefined)) | ||
| ); | ||
| const store = new StringInputFilterStore([attr], cond); | ||
| expect(store.filterFunction).toBe("notEmpty"); | ||
| }); | ||
|
|
||
| it("does NOT confuse a between-style and() with notEmpty", () => { | ||
| // sanity guard: arbitrary and(...) shape that doesn't match the compound contract | ||
| // must NOT be misread as "notEmpty" | ||
| const cond = and( | ||
| notEqual(attribute(attr.id), literal("foo")), | ||
| notEqual(attribute(attr.id), literal("bar")) | ||
| ); | ||
| const store = new StringInputFilterStore([attr], cond); | ||
| expect(store.filterFunction).not.toBe("notEmpty"); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What? If mock is not behaving the same as the real life, we should fix the mock