From 70bcc3c4652b2d6e7a8379d2673b8d3175e06c97 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Mon, 16 Oct 2023 11:25:39 -0400 Subject: [PATCH] test cookie --- .../myPatches/patchCard/dropdown_menu.ts | 14 +++++++++++ src/components/PatchesPage/index.tsx | 7 +++++- src/constants/cookies.ts | 25 ++++++++++--------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/cypress/integration/myPatches/patchCard/dropdown_menu.ts b/cypress/integration/myPatches/patchCard/dropdown_menu.ts index 346dd49e8b..a58cbfa7b4 100644 --- a/cypress/integration/myPatches/patchCard/dropdown_menu.ts +++ b/cypress/integration/myPatches/patchCard/dropdown_menu.ts @@ -1,3 +1,5 @@ +import { INCLUDE_HIDDEN_PATCHES } from "constants/cookies"; + const patchWithoutVersion = "test meee"; const patchWithVersion = "main: EVG-7823 add a commit queue message (#4048)"; const patchWithVersionOnCommitQueue = @@ -100,8 +102,10 @@ describe("Dropdown Menu of Patch Actions", { testIsolation: false }, () => { }); cy.dataCy("enqueue-patch").should("be.disabled"); }); + it("Toggle patch visibility", () => { // "Include hidden" checkbox is not checked and patch is visible + cy.getCookie(INCLUDE_HIDDEN_PATCHES).should("not.exist"); cy.getInputByLabel("Include hidden").should("not.be.checked"); cy.location("search").should("not.contain", "hidden=true"); getPatchCardByDescription("testtest") @@ -116,6 +120,11 @@ describe("Dropdown Menu of Patch Actions", { testIsolation: false }, () => { cy.get("@targetPatchCard").should("not.exist"); // Check "Include hidden" checkbox and unhide patch card cy.dataCy("include-hidden-checkbox").check({ force: true }); + cy.getCookie(INCLUDE_HIDDEN_PATCHES).should( + "have.property", + "value", + "true" + ); cy.location("search").should("contain", "hidden=true"); cy.get("@targetPatchCard") .should("be.visible") @@ -127,6 +136,11 @@ describe("Dropdown Menu of Patch Actions", { testIsolation: false }, () => { cy.get("@targetPatchCard").should("be.visible"); // Uncheck "Include hidden" and verify patch card is visible cy.dataCy("include-hidden-checkbox").uncheck({ force: true }); + cy.getCookie(INCLUDE_HIDDEN_PATCHES).should( + "have.property", + "value", + "false" + ); cy.location("search").should("contain", "hidden=false"); cy.get("@targetPatchCard").should("be.visible"); }); diff --git a/src/components/PatchesPage/index.tsx b/src/components/PatchesPage/index.tsx index 33d885ca3e..7230db8f0a 100644 --- a/src/components/PatchesPage/index.tsx +++ b/src/components/PatchesPage/index.tsx @@ -12,6 +12,7 @@ import { PageWrapper, FiltersWrapper, PageTitle } from "components/styles"; import { INCLUDE_COMMIT_QUEUE_PROJECT_PATCHES, INCLUDE_COMMIT_QUEUE_USER_PATCHES, + INCLUDE_HIDDEN_PATCHES, } from "constants/cookies"; import { size } from "constants/tokens"; import { PatchesPagePatchesFragment, PatchesInput } from "gql/generated/types"; @@ -63,7 +64,10 @@ export const PatchesPage: React.FC = ({ Cookies.get(cookie) === "true" ); const [includeHiddenCheckboxChecked, setIsIncludeHiddenCheckboxChecked] = - useQueryParam(PatchPageQueryParams.Hidden, false); + useQueryParam( + PatchPageQueryParams.Hidden, + Cookies.get(INCLUDE_HIDDEN_PATCHES) === "true" + ); const { limit, page } = usePatchesInputFromSearch(search); const { inputValue, setAndSubmitInputValue } = useFilterInputChangeHandler({ urlParam: PatchPageQueryParams.PatchName, @@ -86,6 +90,7 @@ export const PatchesPage: React.FC = ({ e: React.ChangeEvent ): void => { setIsIncludeHiddenCheckboxChecked(e.target.checked); + Cookies.set(INCLUDE_HIDDEN_PATCHES, e.target.checked ? "true" : "false"); // eslint-disable-next-line no-unused-expressions analyticsObject.sendEvent({ name: "Filter Hidden" }); }; diff --git a/src/constants/cookies.ts b/src/constants/cookies.ts index b28c0a9e8e..1d997b1ac3 100644 --- a/src/constants/cookies.ts +++ b/src/constants/cookies.ts @@ -1,20 +1,21 @@ -export const HIDE_FEEDBACK = "HIDE_FEEDBACK"; export const ANNOUNCEMENT_TOAST = "announcement-toast"; -export const SUBSCRIPTION_METHOD = "subscription-method"; -export const getNotificationTriggerCookie = (type: string) => - `${type}-notification-trigger`; -export const SLACK_NOTIFICATION_BANNER = "has-closed-slack-banner"; -export const CURRENT_PROJECT = "mci-project-cookie"; export const COMMIT_CHART_TYPE_VIEW_OPTIONS_ACCORDION = "commit-chart-view-options-accordion"; +export const CURRENT_PROJECT = "mci-project-cookie"; +export const CY_DISABLE_COMMITS_WELCOME_MODAL = + "cy-disable-commits-welcome-modal"; +export const CY_DISABLE_NEW_USER_WELCOME_MODAL = + "cy-disable-new-user-welcome-modal"; export const DISABLE_QUERY_POLLING = "disable-query-polling"; -export const SEEN_MIGRATE_GUIDE_CUE = "seen-migrate-guide-cue"; -export const SEEN_HONEYCOMB_GUIDE_CUE = "seen-honeycomb-guide-cue"; +export const getNotificationTriggerCookie = (type: string) => + `${type}-notification-trigger`; +export const HIDE_FEEDBACK = "HIDE_FEEDBACK"; export const INCLUDE_COMMIT_QUEUE_PROJECT_PATCHES = "include-commit-queue-project-patches"; export const INCLUDE_COMMIT_QUEUE_USER_PATCHES = "include-commit-queue-user-patches"; -export const CY_DISABLE_NEW_USER_WELCOME_MODAL = - "cy-disable-new-user-welcome-modal"; -export const CY_DISABLE_COMMITS_WELCOME_MODAL = - "cy-disable-commits-welcome-modal"; +export const INCLUDE_HIDDEN_PATCHES = "include-hidden-patches"; +export const SEEN_HONEYCOMB_GUIDE_CUE = "seen-honeycomb-guide-cue"; +export const SEEN_MIGRATE_GUIDE_CUE = "seen-migrate-guide-cue"; +export const SLACK_NOTIFICATION_BANNER = "has-closed-slack-banner"; +export const SUBSCRIPTION_METHOD = "subscription-method";