|
| 1 | +/* |
| 2 | + * Copyright 2024 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + * |
| 7 | + */ |
| 8 | + |
| 9 | +import React from "react"; |
| 10 | +import { render, waitFor } from "@testing-library/react"; |
| 11 | + |
| 12 | +import dis from "../../../../src/dispatcher/dispatcher"; |
| 13 | +import EffectsOverlay from "../../../../src/components/views/elements/EffectsOverlay.tsx"; |
| 14 | + |
| 15 | +describe("<EffectsOverlay/>", () => { |
| 16 | + let isStarted: boolean; |
| 17 | + beforeEach(() => { |
| 18 | + isStarted = false; |
| 19 | + jest.mock("../../../../src/effects/confetti/index.ts", () => { |
| 20 | + return class Confetti { |
| 21 | + start = () => { |
| 22 | + isStarted = true; |
| 23 | + }; |
| 24 | + stop = jest.fn(); |
| 25 | + }; |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + afterEach(() => jest.useRealTimers()); |
| 30 | + |
| 31 | + it("should render", () => { |
| 32 | + const { asFragment } = render(<EffectsOverlay roomWidth={100} />); |
| 33 | + expect(asFragment()).toMatchSnapshot(); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should start the confetti effect", async () => { |
| 37 | + render(<EffectsOverlay roomWidth={100} />); |
| 38 | + dis.dispatch({ action: "effects.confetti" }); |
| 39 | + await waitFor(() => expect(isStarted).toBe(true)); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should start the confetti effect when the event is not outdated", async () => { |
| 43 | + const eventDate = new Date("2024-09-01"); |
| 44 | + const date = new Date("2024-09-02"); |
| 45 | + jest.useFakeTimers().setSystemTime(date); |
| 46 | + |
| 47 | + render(<EffectsOverlay roomWidth={100} />); |
| 48 | + dis.dispatch({ action: "effects.confetti", event: { getTs: () => eventDate.getTime() } }); |
| 49 | + await waitFor(() => expect(isStarted).toBe(true)); |
| 50 | + }); |
| 51 | +}); |
0 commit comments