-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(voip): hide video button when feature not active on homeserver
- Loading branch information
marc.sirisak
committed
May 2, 2024
1 parent
740d598
commit 1a99095
Showing
3 changed files
with
113 additions
and
1 deletion.
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
99 changes: 99 additions & 0 deletions
99
test/unit-tests/tchap/components/views/voip/LegacyCallView-test.tsx
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,99 @@ | ||
import { stubClient } from "matrix-react-sdk/test/test-utils"; | ||
import SdkConfig, { ConfigOptions } from "matrix-react-sdk/src/SdkConfig"; | ||
import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg"; | ||
import React from "react"; | ||
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call"; | ||
import { CallState } from "matrix-js-sdk/src/webrtc/call"; | ||
import { fireEvent, render, waitFor } from "@testing-library/react"; | ||
import { MatrixClient } from "matrix-js-sdk/src/matrix"; | ||
|
||
import LegacyCallView from "~matrix-react-sdk/src/components/views/voip/LegacyCallView"; | ||
import DMRoomMap from "~matrix-react-sdk/src/utils/DMRoomMap"; | ||
|
||
|
||
describe("LegacyCallView", () => { | ||
const featureName: string = "feature_video_call"; | ||
const homeserverName: string = "my.home.server"; | ||
const roomId: string = "roomId"; | ||
// const fakeCall: MatrixCall = new FakeCall(roomId) as unknown as MatrixCall; | ||
let fakeCall: MatrixCall; | ||
|
||
beforeAll(() => { | ||
SdkConfig.reset(); // in case other tests didn't clean up | ||
}); | ||
|
||
beforeEach(() => { | ||
stubClient(); | ||
MatrixClientPeg.getHomeserverName = () => homeserverName; | ||
|
||
const mockClient: MatrixClient = MatrixClientPeg.safeGet(); | ||
mockClient.isFallbackICEServerAllowed = jest.fn(); | ||
|
||
const dmRoomMap = new DMRoomMap(mockClient); | ||
|
||
jest.spyOn(dmRoomMap, "getUserIdForRoomId"); | ||
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); | ||
|
||
|
||
fakeCall = new MatrixCall({ | ||
client: mockClient, | ||
roomId, | ||
}); | ||
|
||
jest.spyOn(fakeCall, "state", "get").mockReturnValue(CallState.Connected); | ||
jest.spyOn(fakeCall, "isLocalOnHold").mockReturnValue(false); | ||
jest.spyOn(fakeCall, "isRemoteOnHold").mockReturnValue(false); | ||
jest.spyOn(fakeCall, "isMicrophoneMuted").mockReturnValue(false); | ||
jest.spyOn(fakeCall, "isLocalVideoMuted").mockReturnValue(true); | ||
jest.spyOn(fakeCall, "isScreensharing").mockReturnValue(false); | ||
jest.spyOn(fakeCall, "isScreensharing").mockReturnValue(false); | ||
jest.spyOn(fakeCall, "opponentSupportsSDPStreamMetadata").mockReturnValue(true); | ||
|
||
}); | ||
|
||
afterEach(function () { | ||
SdkConfig.reset(); // we touch the config, so clean up | ||
}); | ||
|
||
const mockFeatureConfig = (homeservers: string[]) => { | ||
// mock SdkConfig.get("tchap_features") | ||
const config: ConfigOptions = { tchap_features: {} }; | ||
config.tchap_features[featureName] = homeservers; | ||
SdkConfig.put(config); | ||
}; | ||
|
||
const renderCallView = () => { | ||
return render( | ||
<LegacyCallView | ||
key="call-view" | ||
onMouseDownOnHeader={() => null} | ||
call={fakeCall} | ||
secondaryCall={fakeCall} | ||
pipMode={false} | ||
onResize={() => null} | ||
/>, | ||
); | ||
}; | ||
|
||
it("returns true when the the homeserver include video_call feature", () => { | ||
mockFeatureConfig([homeserverName]); | ||
const { container } = renderCallView(); | ||
|
||
// needs to hover on the component to make the control button appears | ||
fireEvent.mouseEnter(container); | ||
waitFor(() => container.getElementsByClassName("mx_LegacyCallViewButtons").length); | ||
|
||
expect(container.getElementsByClassName("mx_LegacyCallViewButtons_button_vid").length).toBe(1); | ||
}); | ||
|
||
it("returns false when the the homeserver doesnt include video_call feature", async () => { | ||
mockFeatureConfig(["other.homeserver"]); | ||
const { container } = renderCallView(); | ||
|
||
// needs to hover on the component to make the control button appears | ||
fireEvent.mouseEnter(container); | ||
waitFor(() => container.getElementsByClassName("mx_LegacyCallViewButtons").length); | ||
|
||
expect(container.getElementsByClassName("mx_LegacyCallViewButtons_button_vid").length).toBe(0); | ||
}); | ||
}); |