Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add tests for EffectsOverlay-test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Sep 18, 2024
1 parent 9dc83b0 commit 2a5c6eb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/components/views/elements/EffectsOverlay-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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("<EffectsOverlay/>", () => {
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(<EffectsOverlay roomWidth={100} />);
expect(asFragment()).toMatchSnapshot();
});

it("should start the confetti effect", async () => {
render(<EffectsOverlay roomWidth={100} />);
dis.dispatch({ action: "effects.confetti" });
await waitFor(() => expect(isStarted).toBe(true));
});

it("should not start the confetti effect when the event is outdated", async () => {
jest.useFakeTimers().setSystemTime(new Date("2024-01-01"));

render(<EffectsOverlay roomWidth={100} />);
dis.dispatch({ action: "effects.confetti", event: { getTs: () => 0 } });
await waitFor(() => expect(isStarted).toBe(false));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<EffectsOverlay/> should render 1`] = `
<DocumentFragment>
<canvas
aria-hidden="true"
height="768"
style="display: block; z-index: 999999; pointer-events: none; position: fixed; top: 0px; right: 0px;"
width="100"
/>
</DocumentFragment>
`;

0 comments on commit 2a5c6eb

Please sign in to comment.