|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import BasePlatform from "../../src/BasePlatform"; |
| 18 | +import { SettingLevel } from "../../src/settings/SettingLevel"; |
| 19 | +import SettingsStore from "../../src/settings/SettingsStore"; |
| 20 | +import { mockPlatformPeg } from "../test-utils"; |
| 21 | + |
| 22 | +const TEST_DATA = [ |
| 23 | + { |
| 24 | + name: "Electron.showTrayIcon", |
| 25 | + level: SettingLevel.PLATFORM, |
| 26 | + value: true, |
| 27 | + }, |
| 28 | +]; |
| 29 | + |
| 30 | +describe("SettingsStore", () => { |
| 31 | + let platformSettings: object; |
| 32 | + |
| 33 | + beforeAll(() => { |
| 34 | + jest.clearAllMocks(); |
| 35 | + platformSettings = {}; |
| 36 | + mockPlatformPeg({ |
| 37 | + isLevelSupported: jest.fn().mockReturnValue(true), |
| 38 | + supportsSetting: jest.fn().mockReturnValue(true), |
| 39 | + setSettingValue: jest.fn().mockImplementation((settingName: string, value: any) => { |
| 40 | + platformSettings[settingName] = value; |
| 41 | + }), |
| 42 | + getSettingValue: jest.fn().mockImplementation((settingName: string) => { |
| 43 | + return platformSettings[settingName]; |
| 44 | + }), |
| 45 | + } as unknown as BasePlatform); |
| 46 | + |
| 47 | + TEST_DATA.forEach(d => { |
| 48 | + SettingsStore.setValue(d.name, null, d.level, d.value); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + describe("getValueAt", () => { |
| 53 | + TEST_DATA.forEach(d => { |
| 54 | + it(`should return the value "${d.level}"."${d.name}"`, () => { |
| 55 | + expect(SettingsStore.getValueAt(d.level, d.name)).toBe(d.value); |
| 56 | + // regression test #22545 |
| 57 | + expect(SettingsStore.getValueAt(d.level, d.name)).toBe(d.value); |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments