This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Honour feature toggles in guest mode (#10651)
* Honour feature toggles in guest mode * Suppress TS warning about returning null MatrixClient * Revert "Suppress TS warning about returning null MatrixClient" Don't ts-ignore this - we will eventually fix it via the strict work. This reverts commit 0c657e6.
- Loading branch information
1 parent
8c81177
commit aa8c0f5
Showing
2 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2023 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 { mocked } from "jest-mock"; | ||
import { MatrixClient } from "matrix-js-sdk/src/client"; | ||
|
||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg"; | ||
import DeviceSettingsHandler from "../../../src/settings/handlers/DeviceSettingsHandler"; | ||
import { CallbackFn, WatchManager } from "../../../src/settings/WatchManager"; | ||
import { stubClient } from "../../test-utils/test-utils"; | ||
|
||
describe("DeviceSettingsHandler", () => { | ||
const ROOM_ID_IS_UNUSED = ""; | ||
|
||
const unknownSettingKey = "unknown_setting"; | ||
const featureKey = "my_feature"; | ||
|
||
let watchers: WatchManager; | ||
let handler: DeviceSettingsHandler; | ||
let settingListener: CallbackFn; | ||
|
||
beforeEach(() => { | ||
watchers = new WatchManager(); | ||
handler = new DeviceSettingsHandler([featureKey], watchers); | ||
settingListener = jest.fn(); | ||
}); | ||
|
||
afterEach(() => { | ||
watchers.unwatchSetting(settingListener); | ||
}); | ||
|
||
it("Returns undefined for an unknown setting", () => { | ||
expect(handler.getValue(unknownSettingKey, ROOM_ID_IS_UNUSED)).toBeUndefined(); | ||
}); | ||
|
||
it("Returns the value for a disabled feature", () => { | ||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, false); | ||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(false); | ||
}); | ||
|
||
it("Returns the value for an enabled feature", () => { | ||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, true); | ||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(true); | ||
}); | ||
|
||
describe("If I am a guest", () => { | ||
let client: MatrixClient; | ||
|
||
beforeEach(() => { | ||
client = stubClient(); | ||
mocked(client.isGuest).mockReturnValue(true); | ||
}); | ||
|
||
afterEach(() => { | ||
MatrixClientPeg.get = () => null; | ||
}); | ||
|
||
it("Returns the value for a disabled feature", () => { | ||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, false); | ||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(false); | ||
}); | ||
|
||
it("Returns the value for an enabled feature", () => { | ||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, true); | ||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(true); | ||
}); | ||
}); | ||
}); |