Add user status on user profile icon (#33653)
* Add user status on user profile icon Currently unstyled & no tests * Style the user status icon * Update snapshot for avatar wrapper * More snapshot updates * add if braces * Split out user status functions to avoid circular dep which has the weird effect of just breaking jest's mocking. * type imports * Update imports * Update snapshot * Tests * baseline image * Just snapshot the component itself --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
co-authored by
Michael Telatynski
parent
f65a53a174
commit
bb07f84e41
@@ -359,6 +359,7 @@ export function createTestClient(): MatrixClient {
|
||||
sendTextMessage: jest.fn(),
|
||||
deleteRoomTag: jest.fn().mockResolvedValue({}),
|
||||
setRoomTag: jest.fn().mockResolvedValue({}),
|
||||
getExtendedProfileProperty: jest.fn(),
|
||||
} as unknown as MatrixClient;
|
||||
|
||||
client.reEmitter = new ReEmitter(client);
|
||||
|
||||
+15
-11
@@ -7,27 +7,31 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
|
||||
class="mx_SpacePanel collapsed newUi"
|
||||
>
|
||||
<div
|
||||
class="_wrapper_1yvpq_8 mx_UserMenu"
|
||||
class="_wrapper_gc5p4_8 mx_UserMenu"
|
||||
>
|
||||
<button
|
||||
aria-expanded="false"
|
||||
aria-haspopup="menu"
|
||||
aria-label="User menu"
|
||||
class="_triggerButton_1yvpq_57"
|
||||
class="_triggerButton_gc5p4_80"
|
||||
data-state="closed"
|
||||
id="radix-react-use-id-1"
|
||||
type="button"
|
||||
>
|
||||
<span
|
||||
aria-label="@test:test"
|
||||
class="_avatar_va14e_8 _avatar-imageless_va14e_55"
|
||||
data-color="5"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 36px;"
|
||||
<div
|
||||
class="_avatarWrapper_gc5p4_57"
|
||||
>
|
||||
t
|
||||
</span>
|
||||
<span
|
||||
aria-label="@test:test"
|
||||
class="_avatar_va14e_8 _avatar-imageless_va14e_55"
|
||||
data-color="5"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 36px;"
|
||||
>
|
||||
t
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -9,10 +9,11 @@ import React from "react";
|
||||
import { renderHook, waitFor } from "jest-matrix-react";
|
||||
import { ClientEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { useUserStatus, userStatusTextWithinMaxLength } from "../../../src/hooks/useUserStatus";
|
||||
import { useUserStatus } from "../../../src/hooks/useUserStatus";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser, mockClientMethodsServer } from "../../test-utils";
|
||||
import { MatrixClientContextProvider } from "../../../src/components/structures/MatrixClientContextProvider";
|
||||
import SettingsStore from "../../../src/settings/SettingsStore";
|
||||
import { userStatusTextWithinMaxLength } from "../../../src/utils/userStatus";
|
||||
|
||||
const userId = "@alice:example.com";
|
||||
|
||||
|
||||
@@ -6,12 +6,13 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { type MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
import { ClientEvent, type MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
import { type MockedObject, mocked } from "jest-mock";
|
||||
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { OwnProfileStore } from "../../../src/stores/OwnProfileStore";
|
||||
import { UPDATE_EVENT } from "../../../src/stores/AsyncStore";
|
||||
import SettingsStore from "../../../src/settings/SettingsStore";
|
||||
|
||||
describe("OwnProfileStore", () => {
|
||||
let client: MockedObject<MatrixClient>;
|
||||
@@ -76,4 +77,61 @@ describe("OwnProfileStore", () => {
|
||||
expect(ownProfileStore.displayName).toBe(client.getSafeUserId());
|
||||
expect(ownProfileStore.avatarMxc).toBeNull();
|
||||
});
|
||||
|
||||
describe("userStatus", () => {
|
||||
beforeEach(() => {
|
||||
client.getProfileInfo.mockResolvedValue({});
|
||||
});
|
||||
|
||||
it("should be undefined if the feature is disabled", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
|
||||
await ownProfileStore.start();
|
||||
|
||||
expect(ownProfileStore.userStatus).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should be undefined if no status is set", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(true);
|
||||
client.getExtendedProfileProperty.mockResolvedValue(undefined);
|
||||
await ownProfileStore.start();
|
||||
|
||||
expect(ownProfileStore.userStatus).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should fetch and expose the user status on start", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(true);
|
||||
client.getExtendedProfileProperty.mockResolvedValue({ emoji: "🏝️", text: "On a tropical holiday" });
|
||||
await ownProfileStore.start();
|
||||
|
||||
expect(client.getExtendedProfileProperty).toHaveBeenCalledWith(
|
||||
client.getSafeUserId(),
|
||||
"org.matrix.msc4426.status",
|
||||
);
|
||||
expect(ownProfileStore.userStatus).toEqual({ emoji: "🏝️", text: "On a tropical holiday" });
|
||||
});
|
||||
|
||||
it("should update the user status when a UserProfileUpdate event is received for the current user", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(true);
|
||||
client.getExtendedProfileProperty.mockResolvedValue({ emoji: "🏝️", text: "On a tropical holiday" });
|
||||
await ownProfileStore.start();
|
||||
|
||||
client.getExtendedProfileProperty.mockResolvedValue({ emoji: "🏡", text: "Back home" });
|
||||
client.emit(ClientEvent.UserProfileUpdate, client.getSafeUserId(), null);
|
||||
await new Promise(process.nextTick);
|
||||
|
||||
expect(ownProfileStore.userStatus).toEqual({ emoji: "🏡", text: "Back home" });
|
||||
});
|
||||
|
||||
it("should not update the user status when a UserProfileUpdate event is received for another user", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(true);
|
||||
client.getExtendedProfileProperty.mockResolvedValue({ emoji: "🏝️", text: "On a tropical holiday" });
|
||||
await ownProfileStore.start();
|
||||
|
||||
client.getExtendedProfileProperty.mockResolvedValue({ emoji: "🐭", text: "Is a mouse" });
|
||||
client.emit(ClientEvent.UserProfileUpdate, "@other:example.com", null);
|
||||
await new Promise(process.nextTick);
|
||||
|
||||
expect(ownProfileStore.userStatus).toEqual({ emoji: "🏝️", text: "On a tropical holiday" });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,7 @@ exports[`UserMenuViewModel should generate a menu options for a guest 1`] = `
|
||||
"manageAccountHref": undefined,
|
||||
"open": true,
|
||||
"showAvatar": false,
|
||||
"statusEmoji": undefined,
|
||||
"userId": "@alice:domain",
|
||||
}
|
||||
`;
|
||||
@@ -38,6 +39,7 @@ exports[`UserMenuViewModel should generate a menu options for a logged in client
|
||||
"manageAccountHref": undefined,
|
||||
"open": true,
|
||||
"showAvatar": true,
|
||||
"statusEmoji": undefined,
|
||||
"userId": "@alice:domain",
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user