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
|
@ -24,6 +24,7 @@ import SettingsStore from "../../../src/settings/SettingsStore";
|
|||
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
import Modal from "../../../src/Modal";
|
||||
import { SETTINGS } from "../../../src/settings/Settings";
|
||||
|
||||
describe("<LoggedInView />", () => {
|
||||
const userId = "@alice:domain.org";
|
||||
|
@ -37,6 +38,9 @@ describe("<LoggedInView />", () => {
|
|||
setPushRuleEnabled: jest.fn(),
|
||||
setPushRuleActions: jest.fn(),
|
||||
getCrypto: jest.fn().mockReturnValue(undefined),
|
||||
setExtendedProfileProperty: jest.fn().mockResolvedValue(undefined),
|
||||
deleteExtendedProfileProperty: jest.fn().mockResolvedValue(undefined),
|
||||
doesServerSupportExtendedProfiles: jest.fn().mockResolvedValue(true),
|
||||
});
|
||||
const mediaHandler = new MediaHandler(mockClient);
|
||||
const mockSdkContext = new TestSdkContext();
|
||||
|
@ -409,4 +413,48 @@ describe("<LoggedInView />", () => {
|
|||
await userEvent.keyboard("{Control>}{Alt>}h</Alt>{/Control}");
|
||||
expect(defaultDispatcher.dispatch).not.toHaveBeenCalledWith({ action: Action.ViewHomePage });
|
||||
});
|
||||
|
||||
describe("timezone updates", () => {
|
||||
const userTimezone = "Europe/London";
|
||||
const originalController = SETTINGS["userTimezonePublish"].controller;
|
||||
|
||||
beforeEach(async () => {
|
||||
SETTINGS["userTimezonePublish"].controller = undefined;
|
||||
await SettingsStore.setValue("userTimezonePublish", null, SettingLevel.DEVICE, false);
|
||||
await SettingsStore.setValue("userTimezone", null, SettingLevel.DEVICE, userTimezone);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
SETTINGS["userTimezonePublish"].controller = originalController;
|
||||
});
|
||||
|
||||
it("does not update the timezone when userTimezonePublish is off", async () => {
|
||||
getComponent();
|
||||
await SettingsStore.setValue("userTimezonePublish", null, SettingLevel.DEVICE, false);
|
||||
expect(mockClient.deleteExtendedProfileProperty).toHaveBeenCalledWith("us.cloke.msc4175.tz");
|
||||
expect(mockClient.setExtendedProfileProperty).not.toHaveBeenCalled();
|
||||
});
|
||||
it("should set the user timezone when userTimezonePublish is enabled", async () => {
|
||||
getComponent();
|
||||
await SettingsStore.setValue("userTimezonePublish", null, SettingLevel.DEVICE, true);
|
||||
expect(mockClient.setExtendedProfileProperty).toHaveBeenCalledWith("us.cloke.msc4175.tz", userTimezone);
|
||||
});
|
||||
|
||||
it("should set the user timezone when the timezone is changed", async () => {
|
||||
const newTimezone = "Europe/Paris";
|
||||
getComponent();
|
||||
await SettingsStore.setValue("userTimezonePublish", null, SettingLevel.DEVICE, true);
|
||||
expect(mockClient.setExtendedProfileProperty).toHaveBeenCalledWith("us.cloke.msc4175.tz", userTimezone);
|
||||
await SettingsStore.setValue("userTimezone", null, SettingLevel.DEVICE, newTimezone);
|
||||
expect(mockClient.setExtendedProfileProperty).toHaveBeenCalledWith("us.cloke.msc4175.tz", newTimezone);
|
||||
});
|
||||
|
||||
it("should clear the timezone when the publish feature is turned off", async () => {
|
||||
getComponent();
|
||||
await SettingsStore.setValue("userTimezonePublish", null, SettingLevel.DEVICE, true);
|
||||
expect(mockClient.setExtendedProfileProperty).toHaveBeenCalledWith("us.cloke.msc4175.tz", userTimezone);
|
||||
await SettingsStore.setValue("userTimezonePublish", null, SettingLevel.DEVICE, false);
|
||||
expect(mockClient.deleteExtendedProfileProperty).toHaveBeenCalledWith("us.cloke.msc4175.tz");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue