Make themed widgets reflect the effective theme (#28342)
* Make themed widgets reflect the effective theme So that widgets such as Element Call will show up in the right theme even if the app is set to match the system theme. * Remove debug log line
This commit is contained in:
@@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked, MockedFunction, MockedObject } from "jest-mock";
|
||||
import { last } from "lodash";
|
||||
import { findLast, last } from "lodash";
|
||||
import {
|
||||
MatrixEvent,
|
||||
MatrixClient,
|
||||
@@ -27,10 +27,15 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { StopGapWidget } from "../../../../src/stores/widgets/StopGapWidget";
|
||||
import ActiveWidgetStore from "../../../../src/stores/ActiveWidgetStore";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||
|
||||
jest.mock("matrix-widget-api/lib/ClientWidgetApi");
|
||||
jest.mock("matrix-widget-api", () => ({
|
||||
...jest.requireActual("matrix-widget-api"),
|
||||
ClientWidgetApi: (jest.createMockFromModule("matrix-widget-api") as any).ClientWidgetApi,
|
||||
}));
|
||||
|
||||
describe("StopGapWidget", () => {
|
||||
let client: MockedObject<MatrixClient>;
|
||||
@@ -104,6 +109,24 @@ describe("StopGapWidget", () => {
|
||||
expect(messaging.feedStateUpdate).toHaveBeenCalledWith(event.getEffectiveEvent());
|
||||
});
|
||||
|
||||
it("informs widget of theme changes", () => {
|
||||
let theme = "light";
|
||||
const settingsSpy = jest
|
||||
.spyOn(SettingsStore, "getValue")
|
||||
.mockImplementation((name) => (name === "theme" ? theme : null));
|
||||
try {
|
||||
// Indicate that the widget is ready
|
||||
findLast(messaging.once.mock.calls, ([eventName]) => eventName === "ready")![1]();
|
||||
|
||||
// Now change the theme
|
||||
theme = "dark";
|
||||
defaultDispatcher.dispatch({ action: Action.RecheckTheme }, true);
|
||||
expect(messaging.updateTheme).toHaveBeenLastCalledWith({ name: "dark" });
|
||||
} finally {
|
||||
settingsSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
describe("feed event", () => {
|
||||
let event1: MatrixEvent;
|
||||
let event2: MatrixEvent;
|
||||
|
||||
Reference in New Issue
Block a user