Add timezone to user profile (#20)
* [create-pull-request] automated change (#12966) Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com> * Add timezone to right panel profile. * Add setting to publish timezone * Add string for timezone publish * Automatically update timezone when setting changes. * Refactor to using a hook And automatically refresh the timezone every minute. * Check for feature support for extended profiles. * lint * Add timezone * Remove unintentional changes * Use browser default timezone. * lint * tweaks * Set timezone publish at the device level to prevent all devices writing to the timezone field. * Update hook to use external client. * Add test for user timezone. * Update snapshot for preferences tab. * Hide timezone info if not provided. * Stablize test * Fix date test types. * prettier * Add timezone tests * Add test for invalid timezone. * Update screenshot * Remove check for profile. --------- Co-authored-by: ElementRobot <releases@riot.im> Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com>
This commit is contained in:
parent
f31776378d
commit
eae9d9e248
11 changed files with 426 additions and 156 deletions
|
@ -92,6 +92,7 @@ let mockRoom: Mocked<Room>;
|
|||
let mockSpace: Mocked<Room>;
|
||||
let mockClient: Mocked<MatrixClient>;
|
||||
let mockCrypto: Mocked<CryptoApi>;
|
||||
const origDate = global.Date.prototype.toLocaleString;
|
||||
|
||||
beforeEach(() => {
|
||||
mockRoom = mocked({
|
||||
|
@ -150,6 +151,8 @@ beforeEach(() => {
|
|||
isSynapseAdministrator: jest.fn().mockResolvedValue(false),
|
||||
isRoomEncrypted: jest.fn().mockReturnValue(false),
|
||||
doesServerSupportUnstableFeature: jest.fn().mockReturnValue(false),
|
||||
doesServerSupportExtendedProfiles: jest.fn().mockResolvedValue(false),
|
||||
getExtendedProfileProperty: jest.fn().mockRejectedValue(new Error("Not supported")),
|
||||
mxcUrlToHttp: jest.fn().mockReturnValue("mock-mxcUrlToHttp"),
|
||||
removeListener: jest.fn(),
|
||||
currentState: {
|
||||
|
@ -229,6 +232,28 @@ describe("<UserInfo />", () => {
|
|||
expect(screen.getByRole("heading", { name: defaultUserId })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders user timezone if set", async () => {
|
||||
// For timezone, force a consistent locale.
|
||||
jest.spyOn(global.Date.prototype, "toLocaleString").mockImplementation(function (
|
||||
this: Date,
|
||||
_locale,
|
||||
opts,
|
||||
) {
|
||||
return origDate.call(this, "en-US", opts);
|
||||
});
|
||||
mockClient.doesServerSupportExtendedProfiles.mockResolvedValue(true);
|
||||
mockClient.getExtendedProfileProperty.mockResolvedValue("Europe/London");
|
||||
renderComponent();
|
||||
await expect(screen.findByText(/\d\d:\d\d (AM|PM)/)).resolves.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not renders user timezone if timezone is invalid", async () => {
|
||||
mockClient.doesServerSupportExtendedProfiles.mockResolvedValue(true);
|
||||
mockClient.getExtendedProfileProperty.mockResolvedValue("invalid-tz");
|
||||
renderComponent();
|
||||
expect(screen.queryByText(/\d\d:\d\d (AM|PM)/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders encryption info panel without pending verification", () => {
|
||||
renderComponent({ phase: RightPanelPhases.EncryptionPanel });
|
||||
expect(screen.getByRole("heading", { name: /encryption/i })).toBeInTheDocument();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue