Skip to content

Commit

Permalink
Add test for removeRule allowLastRuleDelete prop
Browse files Browse the repository at this point in the history
  • Loading branch information
morganadrales committed Sep 17, 2024
1 parent e200af2 commit 64524ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe("PropertyFilterBuilderRuleRenderer", () => {
const button = container.querySelector(".fb-toolbar")?.childNodes[1];
expect(button).toBeTruthy();
fireEvent.click(button!);
expect(removeItemSpy).toHaveBeenCalledWith(defaultProps.path);
expect(removeItemSpy).toHaveBeenCalledWith(defaultProps.path, undefined);
});

it("dispatches operator change when operator is changed", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ describe("usePropertyFilterBuilder", () => {
});
});

it("removes last rule from group if allowLastRuleDelete prop is set to true", () => {
const { result } = renderHook(() => usePropertyFilterBuilder());
const { actions } = result.current;

let { rootGroup } = result.current;
expect(rootGroup.items).to.have.lengthOf(1);

act(() => {
actions.removeItem([rootGroup.items[0].id], true);
});

rootGroup = result.current.rootGroup;
expect(result.current.rootGroup.items).to.have.lengthOf(0);
});

it("does not change state if parent group is not found when removing item", () => {
const { result } = renderHook(() => usePropertyFilterBuilder());
const { actions, rootGroup } = result.current;
Expand Down

0 comments on commit 64524ef

Please sign in to comment.