Fix config override of other settings levels (#12593)
* Make config override other settings levels and add tests * fix documentation * lint * Use a const for finalLevel. * respect the explicit parameter * Use supportedLevelsAreOrdered for config overrides rather than a separate setting. * Fix typos * Fix mock in UserSetttingsDialog-test * Special case disabling of setting tos use config overrides. * remove logs
This commit is contained in:
parent
8e200dc4ac
commit
d6b9e2aa8a
5 changed files with 118 additions and 70 deletions
|
@ -54,6 +54,7 @@ jest.mock("../../../../src/settings/SettingsStore", () => ({
|
|||
getDescription: jest.fn(),
|
||||
shouldHaveWarning: jest.fn(),
|
||||
disabledMessage: jest.fn(),
|
||||
settingIsOveriddenAtConfigLevel: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock("../../../../src/SdkConfig", () => ({
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import BasePlatform from "../../src/BasePlatform";
|
||||
import SdkConfig from "../../src/SdkConfig";
|
||||
import { SettingLevel } from "../../src/settings/SettingLevel";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { mockPlatformPeg } from "../test-utils";
|
||||
|
@ -27,6 +28,11 @@ const TEST_DATA = [
|
|||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* An existing setting that has {@link IBaseSetting#supportedLevelsAreOrdered} set to true.
|
||||
*/
|
||||
const SETTING_NAME_WITH_CONFIG_OVERRIDE = "feature_new_room_decoration_ui";
|
||||
|
||||
describe("SettingsStore", () => {
|
||||
let platformSettings: Record<string, any>;
|
||||
|
||||
|
@ -42,6 +48,7 @@ describe("SettingsStore", () => {
|
|||
getSettingValue: jest.fn().mockImplementation((settingName: string) => {
|
||||
return platformSettings[settingName];
|
||||
}),
|
||||
reload: jest.fn(),
|
||||
} as unknown as BasePlatform);
|
||||
|
||||
TEST_DATA.forEach((d) => {
|
||||
|
@ -49,6 +56,10 @@ describe("SettingsStore", () => {
|
|||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
SdkConfig.reset();
|
||||
});
|
||||
|
||||
describe("getValueAt", () => {
|
||||
TEST_DATA.forEach((d) => {
|
||||
it(`should return the value "${d.level}"."${d.name}"`, () => {
|
||||
|
@ -57,5 +68,20 @@ describe("SettingsStore", () => {
|
|||
expect(SettingsStore.getValueAt(d.level, d.name)).toBe(d.value);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue