diff --git a/test/components/views/elements/EffectsOverlay-test.tsx b/test/components/views/elements/EffectsOverlay-test.tsx new file mode 100644 index 0000000000..48e508181d --- /dev/null +++ b/test/components/views/elements/EffectsOverlay-test.tsx @@ -0,0 +1,51 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only + * Please see LICENSE files in the repository root for full details. + * + */ + +import React from "react"; +import { render, waitFor } from "@testing-library/react"; + +import dis from "../../../../src/dispatcher/dispatcher"; +import EffectsOverlay from "../../../../src/components/views/elements/EffectsOverlay.tsx"; + +describe("", () => { + let isStarted: boolean; + beforeEach(() => { + isStarted = false; + jest.mock("../../../../src/effects/confetti/index.ts", () => { + return class Confetti { + start = () => { + isStarted = true; + }; + stop = jest.fn(); + }; + }); + }); + + afterEach(() => jest.useRealTimers()); + + it("should render", () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); + }); + + it("should start the confetti effect", async () => { + render(); + dis.dispatch({ action: "effects.confetti" }); + await waitFor(() => expect(isStarted).toBe(true)); + }); + + it("should start the confetti effect when the event is not outdated", async () => { + const eventDate = new Date("2024-09-01"); + const date = new Date("2024-09-02"); + jest.useFakeTimers().setSystemTime(date); + + render(); + dis.dispatch({ action: "effects.confetti", event: { getTs: () => eventDate.getTime() } }); + await waitFor(() => expect(isStarted).toBe(true)); + }); +}); diff --git a/test/components/views/elements/__snapshots__/EffectsOverlay-test.tsx.snap b/test/components/views/elements/__snapshots__/EffectsOverlay-test.tsx.snap new file mode 100644 index 0000000000..222d893e99 --- /dev/null +++ b/test/components/views/elements/__snapshots__/EffectsOverlay-test.tsx.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render 1`] = ` + + +`;