This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Use the same avatar colour when creating 1:1 DM rooms #9850
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72e95f1
Ensure 1:1 DM rooms always have the same avatar colour
weeman1337 8ef31d7
Tweak filterConsole
weeman1337 b045a3d
Fix strict type issues
weeman1337 f21b3d7
Add beforeAll to console filter; scope replaced functions
weeman1337 04aae51
Merge branch 'develop' into weeman1337/local-room-avatar
weeman1337 58f7f4c
Merge branch 'develop' into weeman1337/local-room-avatar
weeman1337 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,78 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix"; | ||
import { mocked } from "jest-mock"; | ||
|
||
import RoomAvatar from "../../../../src/components/views/avatars/RoomAvatar"; | ||
import { filterConsole, stubClient } from "../../../test-utils"; | ||
import DMRoomMap from "../../../../src/utils/DMRoomMap"; | ||
import { LocalRoom } from "../../../../src/models/LocalRoom"; | ||
import * as AvatarModule from "../../../../src/Avatar"; | ||
import { DirectoryMember } from "../../../../src/utils/direct-messages"; | ||
|
||
describe("RoomAvatar", () => { | ||
let client: MatrixClient; | ||
|
||
filterConsole( | ||
// unrelated for this test | ||
"Room !room:example.com does not have an m.room.create event", | ||
); | ||
|
||
beforeAll(() => { | ||
client = stubClient(); | ||
const dmRoomMap = new DMRoomMap(client); | ||
jest.spyOn(dmRoomMap, "getUserIdForRoomId"); | ||
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap); | ||
jest.spyOn(AvatarModule, "defaultAvatarUrlForString"); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
mocked(DMRoomMap.shared().getUserIdForRoomId).mockReset(); | ||
mocked(AvatarModule.defaultAvatarUrlForString).mockClear(); | ||
}); | ||
|
||
it("should render as expected for a Room", () => { | ||
const room = new Room("!room:example.com", client, client.getSafeUserId()); | ||
room.name = "test room"; | ||
expect(render(<RoomAvatar room={room} />).container).toMatchSnapshot(); | ||
expect(AvatarModule.defaultAvatarUrlForString).toHaveBeenCalledWith(room.roomId); | ||
}); | ||
|
||
it("should render as expected for a DM room", () => { | ||
const userId = "@dm_user@example.com"; | ||
const room = new Room("!room:example.com", client, client.getSafeUserId()); | ||
room.name = "DM room"; | ||
mocked(DMRoomMap.shared().getUserIdForRoomId).mockReturnValue(userId); | ||
expect(render(<RoomAvatar room={room} />).container).toMatchSnapshot(); | ||
expect(AvatarModule.defaultAvatarUrlForString).toHaveBeenCalledWith(userId); | ||
}); | ||
|
||
it("should render as expected for a LocalRoom", () => { | ||
const userId = "@local_room_user@example.com"; | ||
const localRoom = new LocalRoom("!room:example.com", client, client.getSafeUserId()); | ||
localRoom.name = "local test room"; | ||
localRoom.targets.push(new DirectoryMember({ user_id: userId })); | ||
expect(render(<RoomAvatar room={localRoom} />).container).toMatchSnapshot(); | ||
expect(AvatarModule.defaultAvatarUrlForString).toHaveBeenCalledWith(userId); | ||
}); | ||
}); |
76 changes: 76 additions & 0 deletions
76
test/components/views/avatars/__snapshots__/RoomAvatar-test.tsx.snap
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,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`RoomAvatar should render as expected for a DM room 1`] = ` | ||
<div> | ||
<span | ||
class="mx_BaseAvatar" | ||
role="presentation" | ||
> | ||
<span | ||
aria-hidden="true" | ||
class="mx_BaseAvatar_initial" | ||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;" | ||
> | ||
D | ||
</span> | ||
<img | ||
alt="" | ||
aria-hidden="true" | ||
class="mx_BaseAvatar_image" | ||
data-testid="avatar-img" | ||
src="data:image/png;base64,00" | ||
style="width: 36px; height: 36px;" | ||
/> | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`RoomAvatar should render as expected for a LocalRoom 1`] = ` | ||
<div> | ||
<span | ||
class="mx_BaseAvatar" | ||
role="presentation" | ||
> | ||
<span | ||
aria-hidden="true" | ||
class="mx_BaseAvatar_initial" | ||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;" | ||
> | ||
L | ||
</span> | ||
<img | ||
alt="" | ||
aria-hidden="true" | ||
class="mx_BaseAvatar_image" | ||
data-testid="avatar-img" | ||
src="data:image/png;base64,00" | ||
style="width: 36px; height: 36px;" | ||
/> | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`RoomAvatar should render as expected for a Room 1`] = ` | ||
<div> | ||
<span | ||
class="mx_BaseAvatar" | ||
role="presentation" | ||
> | ||
<span | ||
aria-hidden="true" | ||
class="mx_BaseAvatar_initial" | ||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;" | ||
> | ||
T | ||
</span> | ||
<img | ||
alt="" | ||
aria-hidden="true" | ||
class="mx_BaseAvatar_image" | ||
data-testid="avatar-img" | ||
src="data:image/png;base64,00" | ||
style="width: 36px; height: 36px;" | ||
/> | ||
</span> | ||
</div> | ||
`; |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this does not assert the rendered colour. But at least the text content is different per test:
D
,L
andT
.