Ignore chat effect when older than 48h (#48)
* Ignore effect later than 48h * Add tests for `EffectsOverlay-test.tsx`
This commit is contained in:
parent
0cc0ebe2ed
commit
4776f87775
4 changed files with 84 additions and 3 deletions
51
test/components/views/elements/EffectsOverlay-test.tsx
Normal file
51
test/components/views/elements/EffectsOverlay-test.tsx
Normal file
|
@ -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("<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 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(<EffectsOverlay roomWidth={100} />);
|
||||
dis.dispatch({ action: "effects.confetti", event: { getTs: () => eventDate.getTime() } });
|
||||
await waitFor(() => expect(isStarted).toBe(true));
|
||||
});
|
||||
});
|
|
@ -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>
|
||||
`;
|
Loading…
Add table
Add a link
Reference in a new issue