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

Commit 2620dfe

Browse files
committed
Add tests for EffectsOverlay-test.tsx
1 parent 9dc83b0 commit 2620dfe

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<EffectsOverlay/> should render 1`] = `
4+
<DocumentFragment>
5+
<canvas
6+
aria-hidden="true"
7+
height="768"
8+
style="display: block; z-index: 999999; pointer-events: none; position: fixed; top: 0px; right: 0px;"
9+
width="100"
10+
/>
11+
</DocumentFragment>
12+
`;

0 commit comments

Comments
 (0)