You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Stop using the js-sdk's compare function (#12782)
* Stop using the js-sdk's compare function The file is supposed to be a js-sdk internal module so we shouldn't have been using it, and now it uses the native collator, it's completely trivial. It was also causing Intl.Collator to be accessed at the module scope which risked it beating the modernizr check. * add test * Fix tests Move the restoreAllMocks to prevent mock leakage and also add some custom themes to test the ordering of those. * Move spy to the right place * Add ANOTHER test * Add test for integration manager ordering
This commit is contained in:
@ -19,7 +19,6 @@ import React from "react";
|
||||
import { act, fireEvent, render, RenderResult, screen } from "@testing-library/react";
|
||||
import { Room, MatrixClient, RoomState, RoomMember, User, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { compare } from "matrix-js-sdk/src/utils";
|
||||
import { mocked, MockedObject } from "jest-mock";
|
||||
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
@ -145,7 +144,8 @@ describe("MemberList", () => {
|
||||
if (!groupChange) {
|
||||
const nameA = memberA.name[0] === "@" ? memberA.name.slice(1) : memberA.name;
|
||||
const nameB = memberB.name[0] === "@" ? memberB.name.slice(1) : memberB.name;
|
||||
const nameCompare = compare(nameB, nameA);
|
||||
const collator = new Intl.Collator();
|
||||
const nameCompare = collator.compare(nameB, nameA);
|
||||
console.log("Comparing name");
|
||||
expect(nameCompare).toBeGreaterThanOrEqual(0);
|
||||
} else {
|
||||
|
70
test/integrations/IntegrationManagers-test.ts
Normal file
70
test/integrations/IntegrationManagers-test.ts
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright 2024 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 { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { IntegrationManagers } from "../../src/integrations/IntegrationManagers";
|
||||
import { stubClient } from "../test-utils";
|
||||
|
||||
describe("IntegrationManagers", () => {
|
||||
let client: MatrixClient;
|
||||
let intMgrs: IntegrationManagers;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
mocked(client).getAccountData.mockReturnValue({
|
||||
getContent: jest.fn().mockReturnValue({
|
||||
foo: {
|
||||
id: "foo",
|
||||
content: {
|
||||
type: "m.integration_manager",
|
||||
url: "http://foo/ui",
|
||||
data: {
|
||||
api_url: "http://foo/api",
|
||||
},
|
||||
},
|
||||
},
|
||||
bar: {
|
||||
id: "bar",
|
||||
content: {
|
||||
type: "m.integration_manager",
|
||||
url: "http://bar/ui",
|
||||
data: {
|
||||
api_url: "http://bar/api",
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
} as unknown as MatrixEvent);
|
||||
|
||||
intMgrs = new IntegrationManagers();
|
||||
intMgrs.startWatching();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
intMgrs.stopWatching();
|
||||
});
|
||||
|
||||
describe("getOrderedManagers", () => {
|
||||
it("should return integration managers in alphabetical order", () => {
|
||||
const orderedManagers = intMgrs.getOrderedManagers();
|
||||
|
||||
expect(orderedManagers[0].id).toBe("bar");
|
||||
expect(orderedManagers[1].id).toBe("foo");
|
||||
});
|
||||
});
|
||||
});
|
@ -25,25 +25,29 @@ import SettingsStore from "../../src/settings/SettingsStore";
|
||||
|
||||
// setup test env values
|
||||
const roomId = "!room:server";
|
||||
const mockRoom = <Room>{
|
||||
roomId: roomId,
|
||||
currentState: {
|
||||
getStateEvents: (_l, _x) => {
|
||||
return {
|
||||
getId: () => "$layoutEventId",
|
||||
getContent: () => null,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe("WidgetLayoutStore", () => {
|
||||
let client: MatrixClient;
|
||||
let store: WidgetLayoutStore;
|
||||
let roomUpdateListener: (event: string) => void;
|
||||
let mockApps: IApp[];
|
||||
let mockRoom: Room;
|
||||
let layoutEventContent: Record<string, any> | null;
|
||||
|
||||
beforeEach(() => {
|
||||
layoutEventContent = null;
|
||||
mockRoom = <Room>{
|
||||
roomId: roomId,
|
||||
currentState: {
|
||||
getStateEvents: (_l, _x) => {
|
||||
return {
|
||||
getId: () => "$layoutEventId",
|
||||
getContent: () => layoutEventContent,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
mockApps = [
|
||||
<IApp>{ roomId: roomId, id: "1" },
|
||||
<IApp>{ roomId: roomId, id: "2" },
|
||||
@ -87,6 +91,22 @@ describe("WidgetLayoutStore", () => {
|
||||
expect(store.getContainerHeight(mockRoom, Container.Top)).toBeNull();
|
||||
});
|
||||
|
||||
it("ordering of top container widgets should be consistent even if no index specified", async () => {
|
||||
layoutEventContent = {
|
||||
widgets: {
|
||||
"1": {
|
||||
container: "top",
|
||||
},
|
||||
"2": {
|
||||
container: "top",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
store.recalculateRoom(mockRoom);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toStrictEqual([mockApps[0], mockApps[1]]);
|
||||
});
|
||||
|
||||
it("add three widgets to top container", async () => {
|
||||
store.recalculateRoom(mockRoom);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Top);
|
||||
|
@ -15,9 +15,13 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import SettingsStore from "../src/settings/SettingsStore";
|
||||
import { enumerateThemes, setTheme } from "../src/theme";
|
||||
import { enumerateThemes, getOrderedThemes, setTheme } from "../src/theme";
|
||||
|
||||
describe("theme", () => {
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("setTheme", () => {
|
||||
let lightTheme: HTMLStyleElement;
|
||||
let darkTheme: HTMLStyleElement;
|
||||
@ -48,7 +52,6 @@ describe("theme", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
@ -162,4 +165,16 @@ describe("theme", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getOrderedThemes", () => {
|
||||
it("should return a list of themes in the correct order", () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue([{ name: "Zebra Striped" }, { name: "Apple Green" }]);
|
||||
expect(getOrderedThemes()).toEqual([
|
||||
{ id: "light", name: "Light" },
|
||||
{ id: "dark", name: "Dark" },
|
||||
{ id: "custom-Apple Green", name: "Apple Green" },
|
||||
{ id: "custom-Zebra Striped", name: "Zebra Striped" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user