Add test
This commit is contained in:
@@ -17,7 +17,10 @@ import {
|
|||||||
} from "../utils/testReactions";
|
} from "../utils/testReactions";
|
||||||
import { ReactionsAudioRenderer } from "./ReactionAudioRenderer";
|
import { ReactionsAudioRenderer } from "./ReactionAudioRenderer";
|
||||||
import { GenericReaction, ReactionSet } from "../reactions";
|
import { GenericReaction, ReactionSet } from "../reactions";
|
||||||
import { playReactionsSound } from "../settings/settings";
|
import {
|
||||||
|
playReactionsSound,
|
||||||
|
soundEffectVolumeSetting,
|
||||||
|
} from "../settings/settings";
|
||||||
|
|
||||||
const memberUserIdAlice = "@alice:example.org";
|
const memberUserIdAlice = "@alice:example.org";
|
||||||
const memberUserIdBob = "@bob:example.org";
|
const memberUserIdBob = "@bob:example.org";
|
||||||
@@ -49,6 +52,7 @@ function TestComponent({
|
|||||||
const originalPlayFn = window.HTMLMediaElement.prototype.play;
|
const originalPlayFn = window.HTMLMediaElement.prototype.play;
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
playReactionsSound.setValue(playReactionsSound.defaultValue);
|
playReactionsSound.setValue(playReactionsSound.defaultValue);
|
||||||
|
soundEffectVolumeSetting.setValue(soundEffectVolumeSetting.defaultValue);
|
||||||
window.HTMLMediaElement.prototype.play = originalPlayFn;
|
window.HTMLMediaElement.prototype.play = originalPlayFn;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -125,6 +129,28 @@ test("will play the generic audio sound when there is soundless reaction", () =>
|
|||||||
expect(audioIsPlaying[0]).toContain(GenericReaction.sound?.ogg);
|
expect(audioIsPlaying[0]).toContain(GenericReaction.sound?.ogg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("will play an audio sound with the correct volume", () => {
|
||||||
|
playReactionsSound.setValue(true);
|
||||||
|
soundEffectVolumeSetting.setValue(0.5);
|
||||||
|
const room = new MockRoom(memberUserIdAlice);
|
||||||
|
const rtcSession = new MockRTCSession(room, membership);
|
||||||
|
const { getByTestId } = render(<TestComponent rtcSession={rtcSession} />);
|
||||||
|
|
||||||
|
// Find the first reaction with a sound effect
|
||||||
|
const chosenReaction = ReactionSet.find((r) => !!r.sound);
|
||||||
|
if (!chosenReaction) {
|
||||||
|
throw Error(
|
||||||
|
"No reactions have sounds configured, this test cannot succeed",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
act(() => {
|
||||||
|
room.testSendReaction(memberEventAlice, chosenReaction, membership);
|
||||||
|
});
|
||||||
|
expect((getByTestId(chosenReaction.name) as HTMLAudioElement).volume).toEqual(
|
||||||
|
0.5,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("will play multiple audio sounds when there are multiple different reactions", () => {
|
test("will play multiple audio sounds when there are multiple different reactions", () => {
|
||||||
const audioIsPlaying: string[] = [];
|
const audioIsPlaying: string[] = [];
|
||||||
window.HTMLMediaElement.prototype.play = async function (): Promise<void> {
|
window.HTMLMediaElement.prototype.play = async function (): Promise<void> {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { ReactNode, useEffect, useRef } from "react";
|
|||||||
import { useReactions } from "../useReactions";
|
import { useReactions } from "../useReactions";
|
||||||
import {
|
import {
|
||||||
playReactionsSound,
|
playReactionsSound,
|
||||||
effectSoundVolume as effectSoundVolumeSetting,
|
soundEffectVolumeSetting as effectSoundVolumeSetting,
|
||||||
useSetting,
|
useSetting,
|
||||||
} from "../settings/settings";
|
} from "../settings/settings";
|
||||||
import { GenericReaction, ReactionSet } from "../reactions";
|
import { GenericReaction, ReactionSet } from "../reactions";
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
developerSettingsTab as developerSettingsTabSetting,
|
developerSettingsTab as developerSettingsTabSetting,
|
||||||
duplicateTiles as duplicateTilesSetting,
|
duplicateTiles as duplicateTilesSetting,
|
||||||
useOptInAnalytics,
|
useOptInAnalytics,
|
||||||
effectSoundVolume,
|
soundEffectVolumeSetting,
|
||||||
} from "./settings";
|
} from "./settings";
|
||||||
import { isFirefox } from "../Platform";
|
import { isFirefox } from "../Platform";
|
||||||
import { PreferencesSettingsTab } from "./PreferencesSettingsTab";
|
import { PreferencesSettingsTab } from "./PreferencesSettingsTab";
|
||||||
@@ -118,7 +118,7 @@ export const SettingsModal: FC<Props> = ({
|
|||||||
const devices = useMediaDevices();
|
const devices = useMediaDevices();
|
||||||
useMediaDeviceNames(devices, open);
|
useMediaDeviceNames(devices, open);
|
||||||
|
|
||||||
const [soundVolume, setSoundVolume] = useSetting(effectSoundVolume);
|
const [soundVolume, setSoundVolume] = useSetting(soundEffectVolumeSetting);
|
||||||
|
|
||||||
const audioTab: Tab<SettingsTab> = {
|
const audioTab: Tab<SettingsTab> = {
|
||||||
key: "audio",
|
key: "audio",
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ export const playReactionsSound = new Setting<boolean>(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const effectSoundVolume = new Setting<number>("effects-sound-volume", 1);
|
export const soundEffectVolumeSetting = new Setting<number>(
|
||||||
|
"sound-effect-volume",
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
export const alwaysShowSelf = new Setting<boolean>("always-show-self", true);
|
export const alwaysShowSelf = new Setting<boolean>("always-show-self", true);
|
||||||
|
|||||||
Reference in New Issue
Block a user