mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
fixup tests with fake timers
This commit is contained in:
@@ -259,14 +259,15 @@ test("handles a reaction", () => {
|
|||||||
const reactionEventId = "$my_event_id:example.org";
|
const reactionEventId = "$my_event_id:example.org";
|
||||||
const reaction = ReactionSet[1];
|
const reaction = ReactionSet[1];
|
||||||
|
|
||||||
|
vitest.useFakeTimers();
|
||||||
vitest.setSystemTime(0);
|
vitest.setSystemTime(0);
|
||||||
|
|
||||||
withTestScheduler(({ schedule, expectObservable }) => {
|
withTestScheduler(({ schedule, time, expectObservable }) => {
|
||||||
renderHook(() => {
|
renderHook(() => {
|
||||||
const { reactions$ } = useReactionsReader(
|
const { reactions$ } = useReactionsReader(
|
||||||
rtcSession as unknown as MatrixRTCSession,
|
rtcSession as unknown as MatrixRTCSession,
|
||||||
);
|
);
|
||||||
schedule("ab", {
|
schedule(`abc`, {
|
||||||
a: () => {},
|
a: () => {},
|
||||||
b: () => {
|
b: () => {
|
||||||
rtcSession.room.emit(
|
rtcSession.room.emit(
|
||||||
@@ -291,7 +292,7 @@ test("handles a reaction", () => {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
c: () => {
|
c: () => {
|
||||||
vitest.advanceTimersByTime(5000);
|
vitest.advanceTimersByTime(REACTION_ACTIVE_TIME_MS);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expectObservable(reactions$).toBe(
|
expectObservable(reactions$).toBe(
|
||||||
@@ -440,6 +441,7 @@ test("that reactions cannot be spammed", () => {
|
|||||||
const reactionA = ReactionSet[1];
|
const reactionA = ReactionSet[1];
|
||||||
const reactionB = ReactionSet[2];
|
const reactionB = ReactionSet[2];
|
||||||
|
|
||||||
|
vitest.useFakeTimers();
|
||||||
vitest.setSystemTime(0);
|
vitest.setSystemTime(0);
|
||||||
|
|
||||||
withTestScheduler(({ schedule, expectObservable }) => {
|
withTestScheduler(({ schedule, expectObservable }) => {
|
||||||
@@ -447,7 +449,7 @@ test("that reactions cannot be spammed", () => {
|
|||||||
const { reactions$ } = useReactionsReader(
|
const { reactions$ } = useReactionsReader(
|
||||||
rtcSession as unknown as MatrixRTCSession,
|
rtcSession as unknown as MatrixRTCSession,
|
||||||
);
|
);
|
||||||
schedule("abc", {
|
schedule("abcd", {
|
||||||
a: () => {},
|
a: () => {},
|
||||||
b: () => {
|
b: () => {
|
||||||
rtcSession.room.emit(
|
rtcSession.room.emit(
|
||||||
@@ -493,9 +495,12 @@ test("that reactions cannot be spammed", () => {
|
|||||||
{} as IRoomTimelineData,
|
{} as IRoomTimelineData,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
d: () => {
|
||||||
|
vitest.advanceTimersByTime(REACTION_ACTIVE_TIME_MS);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
expectObservable(reactions$).toBe(
|
expectObservable(reactions$).toBe(
|
||||||
`ab ${REACTION_ACTIVE_TIME_MS - 1}ms c`,
|
`ab- ${REACTION_ACTIVE_TIME_MS - 2}ms d`,
|
||||||
{
|
{
|
||||||
a: {},
|
a: {},
|
||||||
b: {
|
b: {
|
||||||
@@ -504,7 +509,7 @@ test("that reactions cannot be spammed", () => {
|
|||||||
expireAfter: new Date(REACTION_ACTIVE_TIME_MS),
|
expireAfter: new Date(REACTION_ACTIVE_TIME_MS),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
c: {},
|
d: {},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -208,6 +208,9 @@ export default function useReactionsReader(rtcSession: MatrixRTCSession): {
|
|||||||
const currentReactions = reactionsSubject$.current.value;
|
const currentReactions = reactionsSubject$.current.value;
|
||||||
if (currentReactions[identifier]) {
|
if (currentReactions[identifier]) {
|
||||||
// We've still got a reaction from this user, ignore it to prevent spamming
|
// We've still got a reaction from this user, ignore it to prevent spamming
|
||||||
|
logger.warn(
|
||||||
|
`Got reaction from ${identifier} but one is still playing`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reactionsSubject$.current.next({
|
reactionsSubject$.current.next({
|
||||||
|
|||||||
Reference in New Issue
Block a user