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

Conform more code to strict null checking (#10167)

* Conform more code to strict null checking

* Delint

* Iterate PR based on feedback
This commit is contained in:
Michael Telatynski
2023-02-16 17:21:44 +00:00
committed by GitHub
parent f7bea2cae5
commit 4574c665ea
103 changed files with 517 additions and 495 deletions

View File

@ -85,10 +85,6 @@ describe("MegolmExportEncryption", function () {
MegolmExportEncryption = require("../../src/utils/MegolmExportEncryption");
});
afterAll(() => {
window.crypto = undefined;
});
describe("decrypt", function () {
it("should handle missing header", function () {
const input = stringToArray(`-----`);

View File

@ -62,8 +62,6 @@ describe("geolocation utilities", () => {
const pos: GenericPosition = {
latitude: 43.2,
longitude: 12.4,
altitude: null,
accuracy: null,
timestamp: 12334,
};

View File

@ -45,6 +45,8 @@ interface ITestContent extends IContent {
}
describe("export", function () {
const setProgressText = jest.fn();
let mockExportOptions: IExportOptions;
let mockRoom: Room;
let ts0: number;
@ -63,7 +65,7 @@ describe("export", function () {
};
function createRoom() {
const room = new Room(generateRoomId(), null, client.getUserId());
const room = new Room(generateRoomId(), client, client.getUserId()!);
return room;
}
mockRoom = createRoom();
@ -146,7 +148,7 @@ describe("export", function () {
}
function mkEvents() {
const matrixEvents = [];
const matrixEvents: MatrixEvent[] = [];
let i: number;
// plain text
for (i = 0; i < 10; i++) {
@ -237,7 +239,7 @@ describe("export", function () {
});
it("checks if the icons' html corresponds to export regex", function () {
const exporter = new HTMLExporter(mockRoom, ExportType.Beginning, mockExportOptions, null);
const exporter = new HTMLExporter(mockRoom, ExportType.Beginning, mockExportOptions, setProgressText);
const fileRegex = /<span class="mx_MFileBody_info_icon">.*?<\/span>/;
expect(fileRegex.test(renderToString(exporter.getEventTile(mkFileEvent(), true)))).toBeTruthy();
});
@ -251,7 +253,7 @@ describe("export", function () {
maxSize: 100 * 1024 * 1024,
attachmentsIncluded: true,
},
null,
setProgressText,
);
const imageRegex = /<img.+ src="mxc:\/\/test.org" alt="image.png"\/>/;
expect(imageRegex.test(renderToString(exporter.getEventTile(mkImageEvent(), true)))).toBeTruthy();
@ -284,13 +286,13 @@ describe("export", function () {
],
];
it.each(invalidExportOptions)("%s", (_d, options) => {
expect(() => new PlainTextExporter(mockRoom, ExportType.Beginning, options, null)).toThrowError(
expect(() => new PlainTextExporter(mockRoom, ExportType.Beginning, options, setProgressText)).toThrowError(
"Invalid export options",
);
});
it("tests the file extension splitter", function () {
const exporter = new PlainTextExporter(mockRoom, ExportType.Beginning, mockExportOptions, null);
const exporter = new PlainTextExporter(mockRoom, ExportType.Beginning, mockExportOptions, setProgressText);
const fileNameWithExtensions: Record<string, [string, string]> = {
"": ["", ""],
"name": ["name", ""],
@ -327,14 +329,14 @@ describe("export", function () {
expectedText: '<@me:here "This"> Reply',
},
];
const exporter = new PlainTextExporter(mockRoom, ExportType.Beginning, mockExportOptions, null);
const exporter = new PlainTextExporter(mockRoom, ExportType.Beginning, mockExportOptions, setProgressText);
for (const content of eventContents) {
expect(exporter.textForReplyEvent(content)).toBe(content.expectedText);
}
});
it("checks if the render to string doesn't throw any error for different types of events", function () {
const exporter = new HTMLExporter(mockRoom, ExportType.Beginning, mockExportOptions, null);
const exporter = new HTMLExporter(mockRoom, ExportType.Beginning, mockExportOptions, setProgressText);
for (const event of events) {
expect(renderToString(exporter.getEventTile(event, false))).toBeTruthy();
}