1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

Make more code conform to strict null checks (#10219

* Make more code conform to strict null checks

* Fix types

* Fix tests

* Fix remaining test assertions

* Iterate PR
This commit is contained in:
Michael Telatynski
2023-02-24 15:28:40 +00:00
committed by GitHub
parent 4c79ecf141
commit 76b82b4b2b
130 changed files with 603 additions and 603 deletions

View File

@ -35,9 +35,9 @@ describe("parseGeoUri", () => {
longitude: 16.3695,
altitude: 183,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -45,11 +45,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:48.198634,16.371648;crs=wgs84;u=40")).toEqual({
latitude: 48.198634,
longitude: 16.371648,
altitude: undefined,
altitude: null,
accuracy: 40,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -57,11 +57,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:90,-22.43;crs=WGS84")).toEqual({
latitude: 90,
longitude: -22.43,
altitude: undefined,
altitude: null,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -69,11 +69,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:90,46")).toEqual({
latitude: 90,
longitude: 46,
altitude: undefined,
altitude: null,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -81,11 +81,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:66,30;u=6.500;FOo=this%2dthat")).toEqual({
latitude: 66,
longitude: 30,
altitude: undefined,
altitude: null,
accuracy: 6.5,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -93,11 +93,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:66.0,30;u=6.5;foo=this-that>")).toEqual({
latitude: 66.0,
longitude: 30,
altitude: undefined,
altitude: null,
accuracy: 6.5,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -105,11 +105,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:70,20;foo=1.00;bar=white")).toEqual({
latitude: 70,
longitude: 20,
altitude: undefined,
altitude: null,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -117,11 +117,11 @@ describe("parseGeoUri", () => {
expect(parseGeoUri("geo:-7.5,20")).toEqual({
latitude: -7.5,
longitude: 20,
altitude: undefined,
altitude: null,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
@ -131,9 +131,9 @@ describe("parseGeoUri", () => {
longitude: -20,
altitude: 0,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
altitudeAccuracy: null,
heading: null,
speed: null,
});
});
});

View File

@ -91,7 +91,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should gracefully handle invalid MXIDs", () => {
@ -112,8 +112,8 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(3);
expect(creator.serverCandidates[0]).toBe("pl_95");
expect(creator.serverCandidates!.length).toBe(3);
expect(creator.serverCandidates![0]).toBe("pl_95");
// we don't check the 2nd and 3rd servers because that is done by the next test
});
@ -128,15 +128,15 @@ describe("Permalinks", function () {
]);
const creator = new RoomPermalinkCreator(room, null);
creator.load();
expect(creator.serverCandidates[0]).toBe("pl_95");
expect(creator.serverCandidates![0]).toBe("pl_95");
member95.membership = "left";
// @ts-ignore illegal private property
creator.onRoomStateUpdate();
expect(creator.serverCandidates[0]).toBe("pl_75");
expect(creator.serverCandidates![0]).toBe("pl_75");
member95.membership = "join";
// @ts-ignore illegal private property
creator.onRoomStateUpdate();
expect(creator.serverCandidates[0]).toBe("pl_95");
expect(creator.serverCandidates![0]).toBe("pl_95");
});
it("should pick candidate servers based on user population", function () {
@ -152,10 +152,10 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(3);
expect(creator.serverCandidates[0]).toBe("first");
expect(creator.serverCandidates[1]).toBe("second");
expect(creator.serverCandidates[2]).toBe("third");
expect(creator.serverCandidates!.length).toBe(3);
expect(creator.serverCandidates![0]).toBe("first");
expect(creator.serverCandidates![1]).toBe("second");
expect(creator.serverCandidates![2]).toBe("third");
});
it("should pick prefer candidate servers with higher power levels", function () {
@ -168,10 +168,10 @@ describe("Permalinks", function () {
]);
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates.length).toBe(3);
expect(creator.serverCandidates[0]).toBe("first");
expect(creator.serverCandidates[1]).toBe("second");
expect(creator.serverCandidates[2]).toBe("third");
expect(creator.serverCandidates!.length).toBe(3);
expect(creator.serverCandidates![0]).toBe("first");
expect(creator.serverCandidates![1]).toBe("second");
expect(creator.serverCandidates![2]).toBe("third");
});
it("should pick a maximum of 3 candidate servers", function () {
@ -186,7 +186,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(3);
expect(creator.serverCandidates!.length).toBe(3);
});
it("should not consider IPv4 hosts", function () {
@ -195,7 +195,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should not consider IPv6 hosts", function () {
@ -204,7 +204,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should not consider IPv4 hostnames with ports", function () {
@ -213,7 +213,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should not consider IPv6 hostnames with ports", function () {
@ -222,7 +222,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should work with hostnames with ports", function () {
@ -232,8 +232,8 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(1);
expect(creator.serverCandidates[0]).toBe("example.org:8448");
expect(creator.serverCandidates!.length).toBe(1);
expect(creator.serverCandidates![0]).toBe("example.org:8448");
});
it("should not consider servers explicitly denied by ACLs", function () {
@ -252,7 +252,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should not consider servers not allowed by ACLs", function () {
@ -271,7 +271,7 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(0);
expect(creator.serverCandidates!.length).toBe(0);
});
it("should consider servers not explicitly banned by ACLs", function () {
@ -290,8 +290,8 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(1);
expect(creator.serverCandidates[0]).toEqual("evilcorp.com");
expect(creator.serverCandidates!.length).toBe(1);
expect(creator.serverCandidates![0]).toEqual("evilcorp.com");
});
it("should consider servers not disallowed by ACLs", function () {
@ -310,8 +310,8 @@ describe("Permalinks", function () {
const creator = new RoomPermalinkCreator(room);
creator.load();
expect(creator.serverCandidates).toBeTruthy();
expect(creator.serverCandidates.length).toBe(1);
expect(creator.serverCandidates[0]).toEqual("evilcorp.com");
expect(creator.serverCandidates!.length).toBe(1);
expect(creator.serverCandidates![0]).toEqual("evilcorp.com");
});
it("should generate an event permalink for room IDs with no candidate servers", function () {