This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore chat effect when older than 48h (#48)
* Ignore effect later than 48h * Add tests for `EffectsOverlay-test.tsx`
- Loading branch information
1 parent
0cc0ebe
commit 4776f87
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/components/views/elements/__snapshots__/EffectsOverlay-test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |