Skip to content

Commit 06a02b4

Browse files
Half-Shotrobintown
authored andcommitted
Add test
1 parent c560b58 commit 06a02b4

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/room/ReactionAudioRenderer.test.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import {
1717
} from "../utils/testReactions";
1818
import { ReactionsAudioRenderer } from "./ReactionAudioRenderer";
1919
import { GenericReaction, ReactionSet } from "../reactions";
20-
import { playReactionsSound } from "../settings/settings";
20+
import {
21+
playReactionsSound,
22+
soundEffectVolumeSetting,
23+
} from "../settings/settings";
2124

2225
const memberUserIdAlice = "@alice:example.org";
2326
const memberUserIdBob = "@bob:example.org";
@@ -49,6 +52,7 @@ function TestComponent({
4952
const originalPlayFn = window.HTMLMediaElement.prototype.play;
5053
afterAll(() => {
5154
playReactionsSound.setValue(playReactionsSound.defaultValue);
55+
soundEffectVolumeSetting.setValue(soundEffectVolumeSetting.defaultValue);
5256
window.HTMLMediaElement.prototype.play = originalPlayFn;
5357
});
5458

@@ -125,6 +129,28 @@ test("will play the generic audio sound when there is soundless reaction", () =>
125129
expect(audioIsPlaying[0]).toContain(GenericReaction.sound?.ogg);
126130
});
127131

132+
test("will play an audio sound with the correct volume", () => {
133+
playReactionsSound.setValue(true);
134+
soundEffectVolumeSetting.setValue(0.5);
135+
const room = new MockRoom(memberUserIdAlice);
136+
const rtcSession = new MockRTCSession(room, membership);
137+
const { getByTestId } = render(<TestComponent rtcSession={rtcSession} />);
138+
139+
// Find the first reaction with a sound effect
140+
const chosenReaction = ReactionSet.find((r) => !!r.sound);
141+
if (!chosenReaction) {
142+
throw Error(
143+
"No reactions have sounds configured, this test cannot succeed",
144+
);
145+
}
146+
act(() => {
147+
room.testSendReaction(memberEventAlice, chosenReaction, membership);
148+
});
149+
expect((getByTestId(chosenReaction.name) as HTMLAudioElement).volume).toEqual(
150+
0.5,
151+
);
152+
});
153+
128154
test("will play multiple audio sounds when there are multiple different reactions", () => {
129155
const audioIsPlaying: string[] = [];
130156
window.HTMLMediaElement.prototype.play = async function (): Promise<void> {

src/room/ReactionAudioRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ReactNode, useEffect, useRef } from "react";
1010
import { useReactions } from "../useReactions";
1111
import {
1212
playReactionsSound,
13-
effectSoundVolume as effectSoundVolumeSetting,
13+
soundEffectVolumeSetting as effectSoundVolumeSetting,
1414
useSetting,
1515
} from "../settings/settings";
1616
import { GenericReaction, ReactionSet } from "../reactions";

src/settings/SettingsModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
developerSettingsTab as developerSettingsTabSetting,
2929
duplicateTiles as duplicateTilesSetting,
3030
useOptInAnalytics,
31-
effectSoundVolume,
31+
soundEffectVolumeSetting,
3232
} from "./settings";
3333
import { isFirefox } from "../Platform";
3434
import { PreferencesSettingsTab } from "./PreferencesSettingsTab";
@@ -118,7 +118,7 @@ export const SettingsModal: FC<Props> = ({
118118
const devices = useMediaDevices();
119119
useMediaDeviceNames(devices, open);
120120

121-
const [soundVolume, setSoundVolume] = useSetting(effectSoundVolume);
121+
const [soundVolume, setSoundVolume] = useSetting(soundEffectVolumeSetting);
122122

123123
const audioTab: Tab<SettingsTab> = {
124124
key: "audio",

src/settings/settings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export const playReactionsSound = new Setting<boolean>(
100100
true,
101101
);
102102

103-
export const effectSoundVolume = new Setting<number>("effects-sound-volume", 1);
103+
export const soundEffectVolumeSetting = new Setting<number>(
104+
"sound-effect-volume",
105+
1,
106+
);
104107

105108
export const alwaysShowSelf = new Setting<boolean>("always-show-self", true);

0 commit comments

Comments
 (0)