- Share this email in Settings to receive invites directly in . + Share this email in Settings to receive invites directly in Element.
`; @@ -119,7 +119,7 @@ exports[`- Share this email in Settings to receive invites directly in . + Share this email in Settings to receive invites directly in Element.
`; @@ -132,7 +132,7 @@ exports[`- Use an identity server in Settings to receive invites directly in . + Use an identity server in Settings to receive invites directly in Element.
`; @@ -145,7 +145,7 @@ exports[`- Link this email with your account in Settings to receive invites directly in . + Link this email with your account in Settings to receive invites directly in Element.
`; diff --git a/test/editor/model-test.js b/test/editor/model-test.js index 15c5af5806..3d0aa5cf64 100644 --- a/test/editor/model-test.js +++ b/test/editor/model-test.js @@ -101,7 +101,6 @@ describe('editor/model', function() { pc.plain("world"), ], pc, renderer); model.update("hello\nwarm\nworld", "insertText", { offset: 10, atNodeEnd: true }); - console.log(model.serializeParts()); expect(renderer.count).toBe(1); expect(renderer.caret.index).toBe(2); expect(renderer.caret.offset).toBe(4); diff --git a/test/editor/operations-test.js b/test/editor/operations-test.js index 17a4c8ba11..cbf62d0717 100644 --- a/test/editor/operations-test.js +++ b/test/editor/operations-test.js @@ -176,7 +176,6 @@ describe('editor/operations: formatting operations', () => { { "text": "__new paragraph__", "type": "plain" }, ]); range = model.startRange(model.positionForOffset(0, true), model.getPositionAtEnd()); // select-all - console.log("RANGE", range.parts); toggleInlineFormat(range, "__"); expect(model.serializeParts()).toEqual([ { "text": "hello world,", "type": "plain" }, diff --git a/test/setupTests.js b/test/setupTests.js index 3ed4e8c390..6297ddbd8f 100644 --- a/test/setupTests.js +++ b/test/setupTests.js @@ -3,10 +3,15 @@ import Adapter from "@wojtekmaj/enzyme-adapter-react-17"; import { configure } from "enzyme"; import * as languageHandler from "../src/languageHandler"; +import SdkConfig, { DEFAULTS } from '../src/SdkConfig'; languageHandler.setLanguage('en'); languageHandler.setMissingEntryGenerator(key => key.split("|", 2)[1]); +// uninitialised SdkConfig causes lots of warnings in console +// init with defaults +SdkConfig.put(DEFAULTS); + require('jest-fetch-mock').enableMocks(); // jest 27 removes setImmediate from jsdom diff --git a/test/utils/arrays-test.ts b/test/utils/arrays-test.ts index d38120daaf..7dabbb2981 100644 --- a/test/utils/arrays-test.ts +++ b/test/utils/arrays-test.ts @@ -30,8 +30,10 @@ import { GroupedArray, } from "../../src/utils/arrays"; -function expectSample(i: number, input: number[], expected: number[], smooth = false) { - console.log(`Resample case index: ${i}`); // for debugging test failures +type TestParams = { input: number[], output: number[] }; +type TestCase = [string, TestParams]; + +function expectSample(input: number[], expected: number[], smooth = false) { const result = (smooth ? arraySmoothingResample : arrayFastResample)(input, expected.length); expect(result).toBeDefined(); expect(result).toHaveLength(expected.length); @@ -40,60 +42,68 @@ function expectSample(i: number, input: number[], expected: number[], smooth = f describe('arrays', () => { describe('arrayFastResample', () => { - it('should downsample', () => { - [ - { input: [1, 2, 3, 4, 5], output: [1, 4] }, // Odd -> Even - { input: [1, 2, 3, 4, 5], output: [1, 3, 5] }, // Odd -> Odd - { input: [1, 2, 3, 4], output: [1, 2, 3] }, // Even -> Odd - { input: [1, 2, 3, 4], output: [1, 3] }, // Even -> Even - ].forEach((c, i) => expectSample(i, c.input, c.output)); - }); + const downsampleCases: TestCase[] = [ + ['Odd -> Even', { input: [1, 2, 3, 4, 5], output: [1, 4] }], + ['Odd -> Odd', { input: [1, 2, 3, 4, 5], output: [1, 3, 5] }], + ['Even -> Odd', { input: [1, 2, 3, 4], output: [1, 2, 3] }], + ['Even -> Even', { input: [1, 2, 3, 4], output: [1, 3] }], + ]; + it.each(downsampleCases)('downsamples correctly from %s', (_d, { input, output }) => + expectSample(input, output), + ); - it('should upsample', () => { - [ - { input: [1, 2, 3], output: [1, 1, 2, 2, 3, 3] }, // Odd -> Even - { input: [1, 2, 3], output: [1, 1, 2, 2, 3] }, // Odd -> Odd - { input: [1, 2], output: [1, 1, 1, 2, 2] }, // Even -> Odd - { input: [1, 2], output: [1, 1, 1, 2, 2, 2] }, // Even -> Even - ].forEach((c, i) => expectSample(i, c.input, c.output)); - }); + const upsampleCases: TestCase[] = [ + ['Odd -> Even', { input: [1, 2, 3], output: [1, 1, 2, 2, 3, 3] }], + ['Odd -> Odd', { input: [1, 2, 3], output: [1, 1, 2, 2, 3] }], + ['Even -> Odd', { input: [1, 2], output: [1, 1, 1, 2, 2] }], + ['Even -> Even', { input: [1, 2], output: [1, 1, 1, 2, 2, 2] }], + ]; + it.each(upsampleCases)('upsamples correctly from %s', (_d, { input, output }) => + expectSample(input, output), + ); - it('should maintain sample', () => { - [ - { input: [1, 2, 3], output: [1, 2, 3] }, // Odd - { input: [1, 2], output: [1, 2] }, // Even - ].forEach((c, i) => expectSample(i, c.input, c.output)); - }); + const maintainSampleCases: TestCase[] = [ + ['Odd', { input: [1, 2, 3], output: [1, 2, 3] }], // Odd + ['Even', { input: [1, 2], output: [1, 2] }], // Even + ]; + + it.each(maintainSampleCases)('maintains samples for %s', (_d, { input, output }) => + expectSample(input, output), + ); }); describe('arraySmoothingResample', () => { - it('should downsample', () => { - // Dev note: these aren't great samples, but they demonstrate the bare minimum. Ideally - // we'd be feeding a thousand values in and seeing what a curve of 250 values looks like, - // but that's not really feasible to manually verify accuracy. - [ - { input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3, 3] }, // Odd -> Even - { input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3] }, // Odd -> Odd - { input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3, 3] }, // Even -> Odd - { input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3] }, // Even -> Even - ].forEach((c, i) => expectSample(i, c.input, c.output, true)); - }); + // Dev note: these aren't great samples, but they demonstrate the bare minimum. Ideally + // we'd be feeding a thousand values in and seeing what a curve of 250 values looks like, + // but that's not really feasible to manually verify accuracy. + const downsampleCases: TestCase[] = [ + ['Odd -> Even', { input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3, 3] }], + ['Odd -> Odd', { input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3] }], + ['Even -> Odd', { input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3, 3] }], + ['Even -> Even', { input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3] }], + ]; - it('should upsample', () => { - [ - { input: [2, 0, 2], output: [2, 2, 0, 0, 2, 2] }, // Odd -> Even - { input: [2, 0, 2], output: [2, 2, 0, 0, 2] }, // Odd -> Odd - { input: [2, 0], output: [2, 2, 2, 0, 0] }, // Even -> Odd - { input: [2, 0], output: [2, 2, 2, 0, 0, 0] }, // Even -> Even - ].forEach((c, i) => expectSample(i, c.input, c.output, true)); - }); + it.each(downsampleCases)('downsamples correctly from %s', (_d, { input, output }) => + expectSample(input, output, true), + ); - it('should maintain sample', () => { - [ - { input: [2, 0, 2], output: [2, 0, 2] }, // Odd - { input: [2, 0], output: [2, 0] }, // Even - ].forEach((c, i) => expectSample(i, c.input, c.output, true)); - }); + const upsampleCases: TestCase[] = [ + ['Odd -> Even', { input: [2, 0, 2], output: [2, 2, 0, 0, 2, 2] }], + ['Odd -> Odd', { input: [2, 0, 2], output: [2, 2, 0, 0, 2] }], + ['Even -> Odd', { input: [2, 0], output: [2, 2, 2, 0, 0] }], + ['Even -> Even', { input: [2, 0], output: [2, 2, 2, 0, 0, 0] }], + ]; + it.each(upsampleCases)('upsamples correctly from %s', (_d, { input, output }) => + expectSample(input, output, true), + ); + + const maintainCases: TestCase[] = [ + ['Odd', { input: [2, 0, 2], output: [2, 0, 2] }], + ['Even', { input: [2, 0], output: [2, 0] }], + ]; + it.each(maintainCases)('maintains samples for %s', (_d, { input, output }) => + expectSample(input, output), + ); }); describe('arrayRescale', () => { diff --git a/test/utils/test-utils.ts b/test/utils/test-utils.ts index e4bc3740fd..dd98483796 100644 --- a/test/utils/test-utils.ts +++ b/test/utils/test-utils.ts @@ -19,6 +19,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { EventType } from "matrix-js-sdk/src/@types/event"; import { EventEmitter } from "events"; import { ReactWrapper } from "enzyme"; +import { Room } from "matrix-js-sdk"; import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient"; import { mkEvent, mkStubRoom } from "../test-utils"; @@ -60,6 +61,24 @@ export const mkRoom = (client: MatrixClient, roomId: string, rooms?: ReturnType< return room; }; +/** + * Upserts given events into room.currentState + * @param room + * @param events + */ +export const upsertRoomStateEvents = (room: Room, events: MatrixEvent[]): void => { + const eventsMap = events.reduce((acc, event) => { + const eventType = event.getType(); + if (!acc.has(eventType)) { + acc.set(eventType, new Map()); + } + acc.get(eventType).set(event.getStateKey(), event); + return acc; + }, room.currentState.events || new Map