2022-06-13 08:03:16 +02:00
|
|
|
/*
|
|
|
|
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 BasePlatform from "../../src/BasePlatform";
|
2024-06-14 13:00:30 +02:00
|
|
|
import SdkConfig from "../../src/SdkConfig";
|
2022-06-13 08:03:16 +02:00
|
|
|
import { SettingLevel } from "../../src/settings/SettingLevel";
|
|
|
|
import SettingsStore from "../../src/settings/SettingsStore";
|
|
|
|
import { mockPlatformPeg } from "../test-utils";
|
|
|
|
|
|
|
|
const TEST_DATA = [
|
|
|
|
{
|
|
|
|
name: "Electron.showTrayIcon",
|
|
|
|
level: SettingLevel.PLATFORM,
|
|
|
|
value: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-06-14 13:00:30 +02:00
|
|
|
/**
|
|
|
|
* An existing setting that has {@link IBaseSetting#supportedLevelsAreOrdered} set to true.
|
|
|
|
*/
|
2024-07-09 11:45:48 +02:00
|
|
|
const SETTING_NAME_WITH_CONFIG_OVERRIDE = "feature_msc3531_hide_messages_pending_moderation";
|
2024-06-14 13:00:30 +02:00
|
|
|
|
2022-06-13 08:03:16 +02:00
|
|
|
describe("SettingsStore", () => {
|
2023-02-13 12:39:16 +01:00
|
|
|
let platformSettings: Record<string, any>;
|
2022-06-13 08:03:16 +02:00
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
platformSettings = {};
|
|
|
|
mockPlatformPeg({
|
|
|
|
isLevelSupported: jest.fn().mockReturnValue(true),
|
|
|
|
supportsSetting: jest.fn().mockReturnValue(true),
|
|
|
|
setSettingValue: jest.fn().mockImplementation((settingName: string, value: any) => {
|
|
|
|
platformSettings[settingName] = value;
|
|
|
|
}),
|
|
|
|
getSettingValue: jest.fn().mockImplementation((settingName: string) => {
|
|
|
|
return platformSettings[settingName];
|
|
|
|
}),
|
2024-06-14 13:00:30 +02:00
|
|
|
reload: jest.fn(),
|
2022-06-13 08:03:16 +02:00
|
|
|
} as unknown as BasePlatform);
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
TEST_DATA.forEach((d) => {
|
2022-06-13 08:03:16 +02:00
|
|
|
SettingsStore.setValue(d.name, null, d.level, d.value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-06-14 13:00:30 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
SdkConfig.reset();
|
|
|
|
});
|
|
|
|
|
2022-06-13 08:03:16 +02:00
|
|
|
describe("getValueAt", () => {
|
2022-12-12 12:24:14 +01:00
|
|
|
TEST_DATA.forEach((d) => {
|
2022-06-13 08:03:16 +02:00
|
|
|
it(`should return the value "${d.level}"."${d.name}"`, () => {
|
|
|
|
expect(SettingsStore.getValueAt(d.level, d.name)).toBe(d.value);
|
|
|
|
// regression test #22545
|
|
|
|
expect(SettingsStore.getValueAt(d.level, d.name)).toBe(d.value);
|
|
|
|
});
|
|
|
|
});
|
2024-06-14 13:00:30 +02:00
|
|
|
|
|
|
|
it(`supportedLevelsAreOrdered correctly overrides setting`, async () => {
|
|
|
|
SdkConfig.put({
|
|
|
|
features: {
|
|
|
|
[SETTING_NAME_WITH_CONFIG_OVERRIDE]: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await SettingsStore.setValue(SETTING_NAME_WITH_CONFIG_OVERRIDE, null, SettingLevel.DEVICE, true);
|
|
|
|
expect(SettingsStore.getValue(SETTING_NAME_WITH_CONFIG_OVERRIDE)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`supportedLevelsAreOrdered doesn't incorrectly override setting`, async () => {
|
|
|
|
await SettingsStore.setValue(SETTING_NAME_WITH_CONFIG_OVERRIDE, null, SettingLevel.DEVICE, true);
|
|
|
|
expect(SettingsStore.getValueAt(SettingLevel.DEVICE, SETTING_NAME_WITH_CONFIG_OVERRIDE)).toBe(true);
|
|
|
|
});
|
2022-06-13 08:03:16 +02:00
|
|
|
});
|
|
|
|
});
|