From c80310a696663d5d1cc1ec45506f26b83849153a Mon Sep 17 00:00:00 2001 From: Sophie Stadler Date: Tue, 19 Sep 2023 16:31:23 -0400 Subject: [PATCH] EVG-20899: Remove Konami code (#2049) --- cypress/support/e2e.ts | 2 - .../aprilFools/useAprilFoolsAnalytics.ts | 2 +- src/constants/externalResources.ts | 3 - src/hooks/useKonamiCode/index.ts | 107 ------------- .../useKonamiCode/useKonamiCode.test.tsx | 147 ------------------ 5 files changed, 1 insertion(+), 260 deletions(-) delete mode 100644 src/hooks/useKonamiCode/index.ts delete mode 100644 src/hooks/useKonamiCode/useKonamiCode.test.tsx diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 7e4938f400..893105b529 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -129,9 +129,7 @@ beforeEach(() => { cy.setCookie(bannerCookie, "true"); cy.setCookie(CY_DISABLE_COMMITS_WELCOME_MODAL, "true"); cy.setCookie(CY_DISABLE_NEW_USER_WELCOME_MODAL, "true"); - cy.setCookie(konamiCookie, "true"); cy.setCookie(SLACK_NOTIFICATION_BANNER, "true"); }); const bannerCookie = "This is an important notification"; -const konamiCookie = "seen-konami-code"; diff --git a/src/analytics/aprilFools/useAprilFoolsAnalytics.ts b/src/analytics/aprilFools/useAprilFoolsAnalytics.ts index 0732867c75..74d769fb6f 100644 --- a/src/analytics/aprilFools/useAprilFoolsAnalytics.ts +++ b/src/analytics/aprilFools/useAprilFoolsAnalytics.ts @@ -1,6 +1,6 @@ import { useAnalyticsRoot } from "analytics/useAnalyticsRoot"; -type Action = { name: "Triggered Konami Code" }; +type Action = { name: "2024 Boilerplate!" }; export const useAprilFoolsAnalytics = () => useAnalyticsRoot("April Fools"); diff --git a/src/constants/externalResources.ts b/src/constants/externalResources.ts index 9bf766f811..a98ef74bd3 100644 --- a/src/constants/externalResources.ts +++ b/src/constants/externalResources.ts @@ -37,9 +37,6 @@ export const getJiraBugUrl = (jiraHost: string) => export const getJiraImprovementUrl = (jiraHost: string) => `https://${jiraHost}/secure/CreateIssueDetails!init.jspa?pid=12787&issuetype=4&priority=4&labels=user-feedback`; -export const konamiSoundTrackUrl = - "https://www.myinstants.com/media/sounds/mvssf-win.mp3"; - export const legacyRoutes = { distros: "/distros", hosts: "/spawn", diff --git a/src/hooks/useKonamiCode/index.ts b/src/hooks/useKonamiCode/index.ts deleted file mode 100644 index 1d6d56c59a..0000000000 --- a/src/hooks/useKonamiCode/index.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { useState, useEffect } from "react"; -import { useAprilFoolsAnalytics } from "analytics/aprilFools/useAprilFoolsAnalytics"; -import { konamiSoundTrackUrl } from "constants/externalResources"; -import { useToastContext } from "context/toast"; -import { cache } from "gql/GQLWrapper"; -import { PatchStatus } from "types/patch"; -import { TaskStatus } from "types/task"; - -const konamiCode = - "ArrowUpArrowUpArrowDownArrowDownArrowLeftArrowRightArrowLeftArrowRightba"; - -const useKonamiCode = () => { - const [pressedKeys, setPressedKeys] = useState([]); - const dispatchToast = useToastContext(); - const { sendEvent } = useAprilFoolsAnalytics(); - const downHandler = ({ key, target }: KeyboardEvent) => { - // Ignore key presses if the user is typing in an input - if ( - target instanceof HTMLInputElement || - target instanceof HTMLButtonElement || - target instanceof HTMLSelectElement - ) { - return; - } - setPressedKeys((curr) => [...curr, key]); - }; - - const playMusic = () => { - const audio = new Audio(konamiSoundTrackUrl); - audio.play(); - }; - // Listen to all key presses - useEffect(() => { - // Register event listeners - window.addEventListener("keydown", downHandler); - - return () => { - // Unregister event listeners - window.removeEventListener("keydown", downHandler); - }; - }, []); - - useEffect(() => { - // Check if the pressed keys match the konami code - if (pressedKeys.join("").includes(konamiCode)) { - dispatchToast.success("To reset just refresh the page", true, { - title: "Konami Code Activated!", - }); - sendEvent({ name: "Triggered Konami Code" }); - setPressedKeys([]); - const TaskKeys = Object.keys(cache.extract()).filter((key) => - key.includes("Task") - ); - const VersionKeys = Object.keys(cache.extract()).filter((key) => - key.includes("Version") - ); - playMusic(); - - // eslint-disable-next-line no-restricted-syntax - for (const key of TaskKeys) { - cache.modify({ - id: key, - fields: { - status: () => TaskStatus.Succeeded, - }, - broadcast: true, - }); - } - // eslint-disable-next-line no-restricted-syntax - for (const key of VersionKeys) { - cache.modify({ - id: key, - fields: { - status: () => PatchStatus.Success, - taskStatusStats: (stats) => ({ - ...stats, - counts: [ - { - count: 100, - status: TaskStatus.Succeeded, - __typename: "StatusCount", - }, - ], - }), - buildVariantStats: (stats) => { - const newStats = stats.map((stat) => ({ - ...stat, - statusCounts: [ - { - count: 100, - status: TaskStatus.Succeeded, - __typename: "StatusCount", - }, - ], - })); - return newStats; - }, - }, - broadcast: true, - }); - } - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [pressedKeys]); -}; - -export default useKonamiCode; diff --git a/src/hooks/useKonamiCode/useKonamiCode.test.tsx b/src/hooks/useKonamiCode/useKonamiCode.test.tsx deleted file mode 100644 index 0bd09fbcad..0000000000 --- a/src/hooks/useKonamiCode/useKonamiCode.test.tsx +++ /dev/null @@ -1,147 +0,0 @@ -import { MockedProvider } from "@apollo/client/testing"; -import userEvent from "@testing-library/user-event"; -import { RenderFakeToastContext } from "context/toast/__mocks__"; -import { TaskQuery, TaskQueryVariables } from "gql/generated/types"; -import { cache } from "gql/GQLWrapper"; -import { taskQuery } from "gql/mocks/taskData"; -import { GET_TASK } from "gql/queries"; -import { render, screen } from "test_utils"; -import useKonamiCode from "."; - -const KonamiCodeWrapper = ({ gqlCache }) => ( - - - -); - -const HookComponent = () => { - useKonamiCode(); - return ; -}; - -describe("useKonamiCode", () => { - afterEach(() => { - jest.resetAllMocks(); - jest.resetModules(); - }); - it("pressing the correct sequence of keys triggers the Konami code easter", async () => { - const audioPlayMock = jest.fn(); - jest.spyOn(global, "Audio").mockImplementation( - () => - ({ - play: audioPlayMock, - } as any) - ); - window.HTMLMediaElement.prototype.play = audioPlayMock; - - cache.writeQuery({ - query: GET_TASK, - data: { - ...taskQuery, - }, - }); - - const user = userEvent.setup(); - const { Component, dispatchToast } = RenderFakeToastContext( - - ); - render(); - - await user.keyboard( - "{ArrowUp}{ArrowUp}{ArrowDown}{ArrowDown}{ArrowLeft}{ArrowRight}{ArrowLeft}{ArrowRight}{b}{a}" - ); - expect(audioPlayMock).toHaveBeenCalledTimes(1); - expect(dispatchToast.success).toHaveBeenCalledWith( - "To reset just refresh the page", - true, - { title: "Konami Code Activated!" } - ); - expect( - cache.extract()[ - cache.identify({ - __typename: "Task", - id: taskQuery.task.id, - execution: taskQuery.task.execution, - }) - ].status - ).toBe("success"); - }); - it("should not trigger the Konami code if the sequence is incorrect", async () => { - const audioPlayMock = jest.fn(); - jest.spyOn(global, "Audio").mockImplementation( - () => - ({ - play: audioPlayMock, - } as any) - ); - window.HTMLMediaElement.prototype.play = audioPlayMock; - - cache.writeQuery({ - query: GET_TASK, - data: { - ...taskQuery, - }, - }); - - const user = userEvent.setup(); - const { Component, dispatchToast } = RenderFakeToastContext( - - ); - render(); - - await user.keyboard( - "{ArrowUp}{ArrowUp}{ArrowDown}{ArrowDown}{ArrowLeft}{ArrowRight}{ArrowLeft}{ArrowRight}{b}{b}" - ); - expect(audioPlayMock).toHaveBeenCalledTimes(0); - expect(dispatchToast.success).not.toHaveBeenCalled(); - expect( - cache.extract()[ - cache.identify({ - __typename: "Task", - id: taskQuery.task.id, - execution: taskQuery.task.execution, - }) - ].status - ).toBe("pending"); - }); - it("should not trigger the Konami code if it is inputted into a text field", async () => { - const audioPlayMock = jest.fn(); - jest.spyOn(global, "Audio").mockImplementation( - () => - ({ - play: audioPlayMock, - } as any) - ); - window.HTMLMediaElement.prototype.play = audioPlayMock; - - cache.writeQuery({ - query: GET_TASK, - data: { - ...taskQuery, - }, - }); - - const user = userEvent.setup(); - const { Component, dispatchToast } = RenderFakeToastContext( - - ); - render(); - - await user.type( - screen.getByRole("textbox"), - "{ArrowUp}{ArrowUp}{ArrowDown}{ArrowDown}{ArrowLeft}{ArrowRight}{ArrowLeft}{ArrowRight}{b}{a}" - ); - expect(screen.getByRole("textbox")).toHaveValue("ba"); - expect(audioPlayMock).toHaveBeenCalledTimes(0); - expect(dispatchToast.success).not.toHaveBeenCalled(); - expect( - cache.extract()[ - cache.identify({ - __typename: "Task", - id: taskQuery.task.id, - execution: taskQuery.task.execution, - }) - ].status - ).toBe("pending"); - }); -});