-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-830 Add option to Apply highlights for filtered terms (#48)
- Loading branch information
Showing
17 changed files
with
360 additions
and
54 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
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 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
35 changes: 35 additions & 0 deletions
35
...etailsMenu/DetailsMenuCard/Toggles/HighlightFiltersToggle/HighlightFiltersToggle.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,35 @@ | ||
import Cookie from "js-cookie"; | ||
import { MockInstance } from "vitest"; | ||
import { LogContextProvider } from "context/LogContext"; | ||
import { renderWithRouterMatch as render, screen } from "test_utils"; | ||
import HighlightFiltersToggle from "."; | ||
|
||
vi.mock("js-cookie"); | ||
const mockedGet = vi.spyOn(Cookie, "get") as MockInstance; | ||
|
||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<LogContextProvider initialLogLines={[]}>{children}</LogContextProvider> | ||
); | ||
|
||
describe("highlight filter toggle", () => { | ||
beforeEach(() => { | ||
mockedGet.mockImplementation(() => "true"); | ||
}); | ||
|
||
it("defaults to 'false' if cookie is unset", () => { | ||
mockedGet.mockImplementation(() => ""); | ||
render(<HighlightFiltersToggle />, { wrapper }); | ||
const highlightFiltersToggle = screen.getByDataCy( | ||
"highlight-filters-toggle", | ||
); | ||
expect(highlightFiltersToggle).toHaveAttribute("aria-checked", "false"); | ||
}); | ||
|
||
it("should read from the cookie properly", () => { | ||
render(<HighlightFiltersToggle />, { wrapper }); | ||
const highlightFiltersToggle = screen.getByDataCy( | ||
"highlight-filters-toggle", | ||
); | ||
expect(highlightFiltersToggle).toHaveAttribute("aria-checked", "true"); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...rsley/src/components/DetailsMenu/DetailsMenuCard/Toggles/HighlightFiltersToggle/index.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,28 @@ | ||
import { usePreferencesAnalytics } from "analytics"; | ||
import { useLogContext } from "context/LogContext"; | ||
import BaseToggle from "../BaseToggle"; | ||
|
||
const HighlightFiltersToggle: React.FC = () => { | ||
const { sendEvent } = usePreferencesAnalytics(); | ||
const { preferences } = useLogContext(); | ||
const { highlightFilters, setHighlightFilters } = preferences; | ||
const isChecked = highlightFilters; | ||
|
||
const onChange = (checked: boolean) => { | ||
sendEvent({ name: "Toggled Highlight Filters", on: checked }); | ||
setHighlightFilters(checked); | ||
}; | ||
return ( | ||
<BaseToggle | ||
data-cy="highlight-filters-toggle" | ||
label="Highlight Filters" | ||
leftLabel="OFF" | ||
onChange={onChange} | ||
rightLabel="ON" | ||
tooltip="Automatically add matching highlights to filters" | ||
value={isChecked} | ||
/> | ||
); | ||
}; | ||
|
||
export default HighlightFiltersToggle; |
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 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 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 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
Oops, something went wrong.