Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Dec 19, 2024
1 parent e13eee1 commit 6b8c1bd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 9 deletions.
62 changes: 60 additions & 2 deletions src/state/CallViewModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
map,
type Observable,
of,
skip,
switchMap,
} from "rxjs";
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
Expand Down Expand Up @@ -52,15 +53,23 @@ vi.mock("@livekit/components-core");

const localRtcMember = mockRtcMembership("@carol:example.org", "CCCC");
const aliceRtcMember = mockRtcMembership("@alice:example.org", "AAAA");
const aliceDopplegangerRtcMember = mockRtcMembership(
"@alice2:example.org",
"AAAA",
);
const bobRtcMember = mockRtcMembership("@bob:example.org", "BBBB");
const daveRtcMember = mockRtcMembership("@dave:example.org", "DDDD");

const alice = mockMatrixRoomMember(aliceRtcMember);
const alice = mockMatrixRoomMember(aliceRtcMember, { rawDisplayName: "Alice" });
const aliceDoppleganger = mockMatrixRoomMember(aliceDopplegangerRtcMember, {
rawDisplayName: "Alice",
});
const bob = mockMatrixRoomMember(bobRtcMember);
const carol = mockMatrixRoomMember(localRtcMember);
const dave = mockMatrixRoomMember(daveRtcMember);

const aliceId = `${alice.userId}:${aliceRtcMember.deviceId}`;
const aliceDopplegangerId = `${aliceDoppleganger.userId}:${aliceRtcMember.deviceId}`;
const bobId = `${bob.userId}:${bobRtcMember.deviceId}`;
const daveId = `${dave.userId}:${daveRtcMember.deviceId}`;

Expand All @@ -78,7 +87,7 @@ const bobSharingScreen = mockRemoteParticipant({
const daveParticipant = mockRemoteParticipant({ identity: daveId });

const roomMembers = new Map(
[alice, bob, carol, dave].map((p) => [p.userId, p]),
[alice, aliceDoppleganger, bob, carol, dave].map((p) => [p.userId, p]),
);

export interface GridLayoutSummary {
Expand Down Expand Up @@ -782,3 +791,52 @@ it("should show at least one tile per MatrixRTCSession", () => {
);
});
});

it("should disambiguate users with the same displayname", () => {
withTestScheduler(({ hot, expectObservable }) => {
const scenarioInputMarbles = "abcd";
const expectedLayoutMarbles = "abcd";

withCallViewModel(
of([]),
hot(scenarioInputMarbles, {
a: [],
b: [aliceRtcMember],
c: [aliceRtcMember, aliceDopplegangerRtcMember],
d: [aliceRtcMember, aliceDopplegangerRtcMember, bobRtcMember],
e: [aliceDopplegangerRtcMember, bobRtcMember],
}),
of(ConnectionState.Connected),
new Map(),
(vm) => {
// Skip the null state.
expectObservable(vm.memberDisplaynames$.pipe(skip(1))).toBe(
expectedLayoutMarbles,
{
a: new Map([["local", undefined]]),
b: new Map([
["local", undefined],
[aliceId, "Alice"],
]),
c: new Map([
["local", undefined],
[aliceId, "Alice (@alice:example.org)"],
[aliceDopplegangerId, "Alice (@alice2:example.org)"],
]),
d: new Map([
["local", undefined],
[aliceId, "Alice (@alice:example.org)"],
[aliceDopplegangerId, "Alice (@alice2:example.org)"],
[bobId, undefined],
]),
e: new Map([
["local", undefined],
[aliceDopplegangerId, "Alice"],
[bobId, undefined],
]),
},
);
},
);
});
});
12 changes: 5 additions & 7 deletions src/state/CallViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,10 @@ function shouldDisambiguate(
// Also show mxid if there are other people with the same or similar
// displayname, after hidden character removal.
return memberships
.map((m) => findMatrixRoomMember(room, `${m.sender}:${m.deviceId}`))
.some(
(m) =>
m?.userId !== userId && m?.rawDisplayName === strippedDisplayName,
)
);
.map((m) => findMatrixRoomMember(room, `${m.sender}:${m.deviceId}`))
.some(
(m) => m?.userId !== userId && m?.rawDisplayName === strippedDisplayName,
);
}

// TODO: Move wayyyy more business logic from the call and lobby views into here
Expand Down Expand Up @@ -483,7 +481,7 @@ export class CallViewModel extends ViewModel {
* any displaynames that clashes with another member. Only members
* joined to the call are considered here.
*/
private readonly memberDisplaynames$ = fromEvent(
public readonly memberDisplaynames$ = fromEvent(
this.matrixRTCSession,
MatrixRTCSessionEvent.MembershipsChanged,
).pipe(
Expand Down

0 comments on commit 6b8c1bd

Please sign in to comment.