-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Filters support choosing any flagset category (#3797)
- Loading branch information
1 parent
7477ac9
commit ca78e83
Showing
5 changed files
with
213 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
141 changes: 141 additions & 0 deletions
141
editor.planx.uk/src/@planx/components/Filter/Editor.test.tsx
This file contains 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,141 @@ | ||
import { | ||
ComponentType as TYPES, | ||
DEFAULT_FLAG_CATEGORY, | ||
flatFlags, | ||
} from "@opensystemslab/planx-core/types"; | ||
import { fireEvent, screen, waitFor } from "@testing-library/react"; | ||
import React from "react"; | ||
import { setup } from "testUtils"; | ||
import { vi } from "vitest"; | ||
|
||
import Filter from "./Editor"; | ||
|
||
test("Adding a filter without explicit props uses the default flagset", async () => { | ||
const handleSubmit = vi.fn(); | ||
|
||
setup(<Filter handleSubmit={handleSubmit} />); | ||
|
||
expect(screen.getByTestId("flagset-category-select")).toHaveValue( | ||
DEFAULT_FLAG_CATEGORY, | ||
); | ||
|
||
fireEvent.submit(screen.getByTestId("filter-component-form")); | ||
|
||
await waitFor(() => | ||
expect(handleSubmit).toHaveBeenCalledWith( | ||
{ | ||
type: TYPES.Filter, | ||
data: { | ||
fn: "flag", | ||
category: DEFAULT_FLAG_CATEGORY, | ||
}, | ||
}, | ||
mockDefaultFlagOptions, | ||
), | ||
); | ||
}); | ||
|
||
test("Adding a filter and selecting a flagset category", async () => { | ||
const handleSubmit = vi.fn(); | ||
|
||
setup(<Filter handleSubmit={handleSubmit} />); | ||
|
||
expect(screen.getByTestId("flagset-category-select")).toHaveValue( | ||
DEFAULT_FLAG_CATEGORY, | ||
); | ||
|
||
fireEvent.change(screen.getByTestId("flagset-category-select"), { | ||
target: { value: "Community infrastructure levy" }, | ||
}); | ||
|
||
fireEvent.submit(screen.getByTestId("filter-component-form")); | ||
|
||
await waitFor(() => | ||
expect(handleSubmit).toHaveBeenCalledWith( | ||
{ | ||
type: TYPES.Filter, | ||
data: { | ||
fn: "flag", | ||
category: "Community infrastructure levy", | ||
}, | ||
}, | ||
mockCILFlagOptions, | ||
), | ||
); | ||
}); | ||
|
||
test("Updating an existing filter to another category", async () => { | ||
const handleSubmit = vi.fn(); | ||
|
||
setup( | ||
<Filter | ||
id="filterNodeId" | ||
node={mockExistingFilterNode} | ||
handleSubmit={handleSubmit} | ||
/>, | ||
); | ||
|
||
expect(screen.getByTestId("flagset-category-select")).toHaveValue( | ||
"Listed building consent", | ||
); | ||
|
||
fireEvent.change(screen.getByTestId("flagset-category-select"), { | ||
target: { value: "Community infrastructure levy" }, | ||
}); | ||
|
||
fireEvent.submit(screen.getByTestId("filter-component-form")); | ||
|
||
await waitFor(() => | ||
expect(handleSubmit).toHaveBeenCalledWith( | ||
{ | ||
type: TYPES.Filter, | ||
data: { | ||
fn: "flag", | ||
category: "Community infrastructure levy", | ||
}, | ||
}, | ||
mockCILFlagOptions, | ||
), | ||
); | ||
}); | ||
|
||
const mockExistingFilterNode = { | ||
data: { | ||
fn: "flag", | ||
category: "Listed building consent", | ||
}, | ||
type: 500, | ||
edges: ["flag1", "flag2", "flag3", "flag4", "blankFlag"], | ||
}; | ||
|
||
const mockDefaultFlagOptions = [ | ||
...flatFlags.filter((flag) => flag.category === DEFAULT_FLAG_CATEGORY), | ||
{ | ||
category: DEFAULT_FLAG_CATEGORY, | ||
text: "No flag result", | ||
value: "", | ||
}, | ||
].map((flag) => ({ | ||
type: TYPES.Answer, | ||
data: { | ||
text: flag.text, | ||
val: flag.value, | ||
}, | ||
})); | ||
|
||
const mockCILFlagOptions = [ | ||
...flatFlags.filter( | ||
(flag) => flag.category === "Community infrastructure levy", | ||
), | ||
{ | ||
category: "Community infrastructure levy", | ||
text: "No flag result", | ||
value: "", | ||
}, | ||
].map((flag) => ({ | ||
type: TYPES.Answer, | ||
data: { | ||
text: flag.text, | ||
val: flag.value, | ||
}, | ||
})); |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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