mirror of https://github.com/vector-im/riot-web
Clean up some unit test logs (#7857)
* kill some unit test logs in arrays-test Signed-off-by: Kerry Archibald <kerrya@element.io> * remove mock logs that are asserted against anyway * remove more logs Signed-off-by: Kerry Archibald <kerrya@element.io> * fix safeCOunterpartTranslate warnings in tests Signed-off-by: Kerry Archibald <kerrya@element.io> * more safeCounterpartTranslate warnings Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * remove more logs Signed-off-by: Kerry Archibald <kerrya@element.io> * add helper Signed-off-by: Kerry Archibald <kerrya@element.io> * naming Signed-off-by: Kerry Archibald <kerrya@element.io>pull/21833/head
parent
e2827b4082
commit
8b9263c808
|
@ -53,7 +53,6 @@ describe('Terms', function() {
|
||||||
});
|
});
|
||||||
const interactionCallback = jest.fn().mockResolvedValue([]);
|
const interactionCallback = jest.fn().mockResolvedValue([]);
|
||||||
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
|
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
|
||||||
console.log("interaction callback calls", interactionCallback.mock.calls[0]);
|
|
||||||
|
|
||||||
expect(interactionCallback).toBeCalledWith([
|
expect(interactionCallback).toBeCalledWith([
|
||||||
{
|
{
|
||||||
|
@ -80,7 +79,6 @@ describe('Terms', function() {
|
||||||
|
|
||||||
const interactionCallback = jest.fn();
|
const interactionCallback = jest.fn();
|
||||||
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
|
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
|
||||||
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.mock.calls[0]);
|
|
||||||
|
|
||||||
expect(interactionCallback).not.toHaveBeenCalled();
|
expect(interactionCallback).not.toHaveBeenCalled();
|
||||||
expect(MatrixClientPeg.get().agreeToTerms).toBeCalledWith(
|
expect(MatrixClientPeg.get().agreeToTerms).toBeCalledWith(
|
||||||
|
@ -107,8 +105,6 @@ describe('Terms', function() {
|
||||||
|
|
||||||
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
|
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
|
||||||
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
|
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
|
||||||
console.log("interactionCallback call", interactionCallback.mock.calls[0]);
|
|
||||||
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.mock.calls[0]);
|
|
||||||
|
|
||||||
expect(interactionCallback).toBeCalledWith([
|
expect(interactionCallback).toBeCalledWith([
|
||||||
{
|
{
|
||||||
|
@ -154,10 +150,6 @@ describe('Terms', function() {
|
||||||
|
|
||||||
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
|
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
|
||||||
await startTermsFlow([IM_SERVICE_ONE, IM_SERVICE_TWO], interactionCallback);
|
await startTermsFlow([IM_SERVICE_ONE, IM_SERVICE_TWO], interactionCallback);
|
||||||
console.log("getTerms call 0", MatrixClientPeg.get().getTerms.mock.calls[0]);
|
|
||||||
console.log("getTerms call 1", MatrixClientPeg.get().getTerms.mock.calls[1]);
|
|
||||||
console.log("interactionCallback call", interactionCallback.mock.calls[0]);
|
|
||||||
console.log("agreeToTerms call", MatrixClientPeg.get().agreeToTerms.mock.calls[0]);
|
|
||||||
|
|
||||||
expect(interactionCallback).toBeCalledWith([
|
expect(interactionCallback).toBeCalledWith([
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@ import SettingsStore from "../../../src/settings/SettingsStore";
|
||||||
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
||||||
import RoomContext from "../../../src/contexts/RoomContext";
|
import RoomContext from "../../../src/contexts/RoomContext";
|
||||||
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
||||||
|
import { upsertRoomStateEvents } from '../../utils/test-utils';
|
||||||
|
|
||||||
const TestUtils = require('react-dom/test-utils');
|
const TestUtils = require('react-dom/test-utils');
|
||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
|
@ -199,6 +200,7 @@ describe('MessagePanel', function() {
|
||||||
mkEvent({
|
mkEvent({
|
||||||
event: true,
|
event: true,
|
||||||
type: "m.room.create",
|
type: "m.room.create",
|
||||||
|
sender: '@test:example.org',
|
||||||
room: roomId,
|
room: roomId,
|
||||||
user: alice,
|
user: alice,
|
||||||
content: {
|
content: {
|
||||||
|
@ -435,6 +437,7 @@ describe('MessagePanel', function() {
|
||||||
|
|
||||||
it('should collapse creation events', function() {
|
it('should collapse creation events', function() {
|
||||||
const events = mkCreationEvents();
|
const events = mkCreationEvents();
|
||||||
|
upsertRoomStateEvents(room, events);
|
||||||
const res = mount(
|
const res = mount(
|
||||||
<WrappedMessagePanel className="cls" events={events} />,
|
<WrappedMessagePanel className="cls" events={events} />,
|
||||||
);
|
);
|
||||||
|
@ -460,6 +463,7 @@ describe('MessagePanel', function() {
|
||||||
|
|
||||||
it('should hide read-marker at the end of creation event summary', function() {
|
it('should hide read-marker at the end of creation event summary', function() {
|
||||||
const events = mkCreationEvents();
|
const events = mkCreationEvents();
|
||||||
|
upsertRoomStateEvents(room, events);
|
||||||
const res = mount(
|
const res = mount(
|
||||||
<WrappedMessagePanel
|
<WrappedMessagePanel
|
||||||
className="cls"
|
className="cls"
|
||||||
|
|
|
@ -124,7 +124,7 @@ describe("RightPanel", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Switch to room 2");
|
// Switch to room 2
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: Action.ViewRoom,
|
action: Action.ViewRoom,
|
||||||
room_id: "r2",
|
room_id: "r2",
|
||||||
|
|
|
@ -41,6 +41,10 @@ describe('Login', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
||||||
|
disable_custom_urls: true,
|
||||||
|
brand: 'test-brand',
|
||||||
|
});
|
||||||
mockClient.login.mockClear().mockResolvedValue({});
|
mockClient.login.mockClear().mockResolvedValue({});
|
||||||
mockClient.loginFlows.mockClear().mockResolvedValue({ flows: [{ type: "m.login.password" }] });
|
mockClient.loginFlows.mockClear().mockResolvedValue({ flows: [{ type: "m.login.password" }] });
|
||||||
createClient.mockReturnValue(mockClient);
|
createClient.mockReturnValue(mockClient);
|
||||||
|
@ -64,6 +68,10 @@ describe('Login', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should show form with change server link', async () => {
|
it('should show form with change server link', async () => {
|
||||||
|
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
||||||
|
disable_custom_urls: false,
|
||||||
|
brand: 'test',
|
||||||
|
});
|
||||||
const root = render();
|
const root = render();
|
||||||
|
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
@ -79,10 +87,6 @@ describe('Login', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show form without change server link when custom URLs disabled', async () => {
|
it('should show form without change server link when custom URLs disabled', async () => {
|
||||||
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
|
||||||
disable_custom_urls: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const root = render();
|
const root = render();
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
|
@ -97,10 +101,6 @@ describe('Login', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show SSO button if that flow is available", async () => {
|
it("should show SSO button if that flow is available", async () => {
|
||||||
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
|
||||||
disable_custom_urls: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
mockClient.loginFlows.mockReturnValue({ flows: [{ type: "m.login.sso" }] });
|
mockClient.loginFlows.mockReturnValue({ flows: [{ type: "m.login.sso" }] });
|
||||||
|
|
||||||
const root = render();
|
const root = render();
|
||||||
|
@ -111,10 +111,6 @@ describe('Login', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show both SSO button and username+password if both are available", async () => {
|
it("should show both SSO button and username+password if both are available", async () => {
|
||||||
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
|
||||||
disable_custom_urls: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
mockClient.loginFlows.mockReturnValue({ flows: [{ type: "m.login.password" }, { type: "m.login.sso" }] });
|
mockClient.loginFlows.mockReturnValue({ flows: [{ type: "m.login.password" }, { type: "m.login.sso" }] });
|
||||||
|
|
||||||
const root = render();
|
const root = render();
|
||||||
|
@ -128,10 +124,6 @@ describe('Login', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show multiple SSO buttons if multiple identity_providers are available", async () => {
|
it("should show multiple SSO buttons if multiple identity_providers are available", async () => {
|
||||||
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
|
||||||
disable_custom_urls: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
mockClient.loginFlows.mockReturnValue({
|
mockClient.loginFlows.mockReturnValue({
|
||||||
flows: [{
|
flows: [{
|
||||||
"type": "m.login.sso",
|
"type": "m.login.sso",
|
||||||
|
|
|
@ -20,7 +20,7 @@ import ReactTestUtils from 'react-dom/test-utils';
|
||||||
import { createClient } from 'matrix-js-sdk/src/matrix';
|
import { createClient } from 'matrix-js-sdk/src/matrix';
|
||||||
|
|
||||||
import sdk from '../../../skinned-sdk';
|
import sdk from '../../../skinned-sdk';
|
||||||
import SdkConfig from '../../../../src/SdkConfig';
|
import SdkConfig, { DEFAULTS } from '../../../../src/SdkConfig';
|
||||||
import { createTestClient, mkServerConfig } from "../../../test-utils";
|
import { createTestClient, mkServerConfig } from "../../../test-utils";
|
||||||
|
|
||||||
jest.mock('matrix-js-sdk/src/matrix');
|
jest.mock('matrix-js-sdk/src/matrix');
|
||||||
|
@ -34,6 +34,10 @@ describe('Registration', function() {
|
||||||
let parentDiv;
|
let parentDiv;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
||||||
|
...DEFAULTS,
|
||||||
|
disable_custom_urls: true,
|
||||||
|
});
|
||||||
parentDiv = document.createElement('div');
|
parentDiv = document.createElement('div');
|
||||||
document.body.appendChild(parentDiv);
|
document.body.appendChild(parentDiv);
|
||||||
createClient.mockImplementation(() => createTestClient());
|
createClient.mockImplementation(() => createTestClient());
|
||||||
|
@ -61,10 +65,6 @@ describe('Registration', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show form when custom URLs disabled', async function() {
|
it('should show form when custom URLs disabled', async function() {
|
||||||
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
|
||||||
disable_custom_urls: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const root = render();
|
const root = render();
|
||||||
|
|
||||||
// Set non-empty flows & matrixClient to get past the loading spinner
|
// Set non-empty flows & matrixClient to get past the loading spinner
|
||||||
|
@ -84,10 +84,6 @@ describe('Registration', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show SSO options if those are available", async () => {
|
it("should show SSO options if those are available", async () => {
|
||||||
jest.spyOn(SdkConfig, "get").mockReturnValue({
|
|
||||||
disable_custom_urls: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const root = render();
|
const root = render();
|
||||||
|
|
||||||
// Set non-empty flows & matrixClient to get past the loading spinner
|
// Set non-empty flows & matrixClient to get past the loading spinner
|
||||||
|
|
|
@ -139,7 +139,7 @@ describe("AppTile", () => {
|
||||||
const instance = renderer.root.findByType(AppTile).instance;
|
const instance = renderer.root.findByType(AppTile).instance;
|
||||||
const endWidgetActions = jest.spyOn(instance, "endWidgetActions");
|
const endWidgetActions = jest.spyOn(instance, "endWidgetActions");
|
||||||
|
|
||||||
console.log("Switch to room 2");
|
// Switch to room 2
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: Action.ViewRoom,
|
action: Action.ViewRoom,
|
||||||
room_id: "r2",
|
room_id: "r2",
|
||||||
|
@ -194,7 +194,7 @@ describe("AppTile", () => {
|
||||||
const instance = renderer.root.findByType(AppTile).instance;
|
const instance = renderer.root.findByType(AppTile).instance;
|
||||||
const endWidgetActions = jest.spyOn(instance, "endWidgetActions");
|
const endWidgetActions = jest.spyOn(instance, "endWidgetActions");
|
||||||
|
|
||||||
console.log("Move widget to center");
|
// Move widget to center
|
||||||
|
|
||||||
// Stop mocking settings so that the widget move can take effect
|
// Stop mocking settings so that the widget move can take effect
|
||||||
mockSettings.mockRestore();
|
mockSettings.mockRestore();
|
||||||
|
|
|
@ -352,6 +352,7 @@ describe("<TextualBody />", () => {
|
||||||
},
|
},
|
||||||
event: true,
|
event: true,
|
||||||
});
|
});
|
||||||
|
jest.spyOn(ev, 'replacingEventDate').mockReturnValue(new Date(1993, 7, 3));
|
||||||
ev.makeReplaced(ev2);
|
ev.makeReplaced(ev2);
|
||||||
|
|
||||||
wrapper.setProps({
|
wrapper.setProps({
|
||||||
|
|
|
@ -106,7 +106,7 @@ exports[`<RoomPreviewBar /> with an invite with an invited email when client has
|
||||||
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
Share this email in Settings to receive invites directly in .
|
Share this email in Settings to receive invites directly in Element.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -119,7 +119,7 @@ exports[`<RoomPreviewBar /> with an invite with an invited email when client has
|
||||||
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
Share this email in Settings to receive invites directly in .
|
Share this email in Settings to receive invites directly in Element.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -132,7 +132,7 @@ exports[`<RoomPreviewBar /> with an invite with an invited email when client has
|
||||||
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
Use an identity server in Settings to receive invites directly in .
|
Use an identity server in Settings to receive invites directly in Element.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -145,7 +145,7 @@ exports[`<RoomPreviewBar /> with an invite with an invited email when invitedEma
|
||||||
This invite to RoomPreviewBar-test-room was sent to test@test.com which is not associated with your account
|
This invite to RoomPreviewBar-test-room was sent to test@test.com which is not associated with your account
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
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.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -101,7 +101,6 @@ describe('editor/model', function() {
|
||||||
pc.plain("world"),
|
pc.plain("world"),
|
||||||
], pc, renderer);
|
], pc, renderer);
|
||||||
model.update("hello\nwarm\nworld", "insertText", { offset: 10, atNodeEnd: true });
|
model.update("hello\nwarm\nworld", "insertText", { offset: 10, atNodeEnd: true });
|
||||||
console.log(model.serializeParts());
|
|
||||||
expect(renderer.count).toBe(1);
|
expect(renderer.count).toBe(1);
|
||||||
expect(renderer.caret.index).toBe(2);
|
expect(renderer.caret.index).toBe(2);
|
||||||
expect(renderer.caret.offset).toBe(4);
|
expect(renderer.caret.offset).toBe(4);
|
||||||
|
|
|
@ -176,7 +176,6 @@ describe('editor/operations: formatting operations', () => {
|
||||||
{ "text": "__new paragraph__", "type": "plain" },
|
{ "text": "__new paragraph__", "type": "plain" },
|
||||||
]);
|
]);
|
||||||
range = model.startRange(model.positionForOffset(0, true), model.getPositionAtEnd()); // select-all
|
range = model.startRange(model.positionForOffset(0, true), model.getPositionAtEnd()); // select-all
|
||||||
console.log("RANGE", range.parts);
|
|
||||||
toggleInlineFormat(range, "__");
|
toggleInlineFormat(range, "__");
|
||||||
expect(model.serializeParts()).toEqual([
|
expect(model.serializeParts()).toEqual([
|
||||||
{ "text": "hello world,", "type": "plain" },
|
{ "text": "hello world,", "type": "plain" },
|
||||||
|
|
|
@ -3,10 +3,15 @@ import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
|
||||||
import { configure } from "enzyme";
|
import { configure } from "enzyme";
|
||||||
|
|
||||||
import * as languageHandler from "../src/languageHandler";
|
import * as languageHandler from "../src/languageHandler";
|
||||||
|
import SdkConfig, { DEFAULTS } from '../src/SdkConfig';
|
||||||
|
|
||||||
languageHandler.setLanguage('en');
|
languageHandler.setLanguage('en');
|
||||||
languageHandler.setMissingEntryGenerator(key => key.split("|", 2)[1]);
|
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();
|
require('jest-fetch-mock').enableMocks();
|
||||||
|
|
||||||
// jest 27 removes setImmediate from jsdom
|
// jest 27 removes setImmediate from jsdom
|
||||||
|
|
|
@ -30,8 +30,10 @@ import {
|
||||||
GroupedArray,
|
GroupedArray,
|
||||||
} from "../../src/utils/arrays";
|
} from "../../src/utils/arrays";
|
||||||
|
|
||||||
function expectSample(i: number, input: number[], expected: number[], smooth = false) {
|
type TestParams = { input: number[], output: number[] };
|
||||||
console.log(`Resample case index: ${i}`); // for debugging test failures
|
type TestCase = [string, TestParams];
|
||||||
|
|
||||||
|
function expectSample(input: number[], expected: number[], smooth = false) {
|
||||||
const result = (smooth ? arraySmoothingResample : arrayFastResample)(input, expected.length);
|
const result = (smooth ? arraySmoothingResample : arrayFastResample)(input, expected.length);
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
expect(result).toHaveLength(expected.length);
|
expect(result).toHaveLength(expected.length);
|
||||||
|
@ -40,60 +42,68 @@ function expectSample(i: number, input: number[], expected: number[], smooth = f
|
||||||
|
|
||||||
describe('arrays', () => {
|
describe('arrays', () => {
|
||||||
describe('arrayFastResample', () => {
|
describe('arrayFastResample', () => {
|
||||||
it('should downsample', () => {
|
const downsampleCases: TestCase[] = [
|
||||||
[
|
['Odd -> Even', { input: [1, 2, 3, 4, 5], output: [1, 4] }],
|
||||||
{ input: [1, 2, 3, 4, 5], output: [1, 4] }, // Odd -> Even
|
['Odd -> Odd', { input: [1, 2, 3, 4, 5], output: [1, 3, 5] }],
|
||||||
{ input: [1, 2, 3, 4, 5], output: [1, 3, 5] }, // Odd -> Odd
|
['Even -> Odd', { input: [1, 2, 3, 4], output: [1, 2, 3] }],
|
||||||
{ input: [1, 2, 3, 4], output: [1, 2, 3] }, // Even -> Odd
|
['Even -> Even', { input: [1, 2, 3, 4], output: [1, 3] }],
|
||||||
{ input: [1, 2, 3, 4], output: [1, 3] }, // Even -> Even
|
];
|
||||||
].forEach((c, i) => expectSample(i, c.input, c.output));
|
it.each(downsampleCases)('downsamples correctly from %s', (_d, { input, output }) =>
|
||||||
});
|
expectSample(input, output),
|
||||||
|
);
|
||||||
|
|
||||||
it('should upsample', () => {
|
const upsampleCases: TestCase[] = [
|
||||||
[
|
['Odd -> Even', { input: [1, 2, 3], output: [1, 1, 2, 2, 3, 3] }],
|
||||||
{ input: [1, 2, 3], output: [1, 1, 2, 2, 3, 3] }, // Odd -> Even
|
['Odd -> Odd', { input: [1, 2, 3], output: [1, 1, 2, 2, 3] }],
|
||||||
{ input: [1, 2, 3], output: [1, 1, 2, 2, 3] }, // Odd -> Odd
|
['Even -> Odd', { input: [1, 2], output: [1, 1, 1, 2, 2] }],
|
||||||
{ input: [1, 2], output: [1, 1, 1, 2, 2] }, // Even -> Odd
|
['Even -> Even', { input: [1, 2], output: [1, 1, 1, 2, 2, 2] }],
|
||||||
{ input: [1, 2], output: [1, 1, 1, 2, 2, 2] }, // Even -> Even
|
];
|
||||||
].forEach((c, i) => expectSample(i, c.input, c.output));
|
it.each(upsampleCases)('upsamples correctly from %s', (_d, { input, output }) =>
|
||||||
});
|
expectSample(input, output),
|
||||||
|
);
|
||||||
|
|
||||||
it('should maintain sample', () => {
|
const maintainSampleCases: TestCase[] = [
|
||||||
[
|
['Odd', { input: [1, 2, 3], output: [1, 2, 3] }], // Odd
|
||||||
{ input: [1, 2, 3], output: [1, 2, 3] }, // Odd
|
['Even', { input: [1, 2], output: [1, 2] }], // Even
|
||||||
{ input: [1, 2], output: [1, 2] }, // Even
|
];
|
||||||
].forEach((c, i) => expectSample(i, c.input, c.output));
|
|
||||||
});
|
it.each(maintainSampleCases)('maintains samples for %s', (_d, { input, output }) =>
|
||||||
|
expectSample(input, output),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('arraySmoothingResample', () => {
|
describe('arraySmoothingResample', () => {
|
||||||
it('should downsample', () => {
|
|
||||||
// Dev note: these aren't great samples, but they demonstrate the bare minimum. Ideally
|
// 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,
|
// 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.
|
// but that's not really feasible to manually verify accuracy.
|
||||||
[
|
const downsampleCases: TestCase[] = [
|
||||||
{ input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3, 3] }, // Odd -> Even
|
['Odd -> Even', { input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3, 3] }],
|
||||||
{ input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3] }, // Odd -> Odd
|
['Odd -> Odd', { input: [4, 4, 1, 4, 4, 1, 4, 4, 1], output: [3, 3, 3] }],
|
||||||
{ input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3, 3] }, // Even -> Odd
|
['Even -> Odd', { input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3, 3] }],
|
||||||
{ input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3] }, // Even -> Even
|
['Even -> Even', { input: [4, 4, 1, 4, 4, 1, 4, 4], output: [3, 3] }],
|
||||||
].forEach((c, i) => expectSample(i, c.input, c.output, true));
|
];
|
||||||
});
|
|
||||||
|
|
||||||
it('should upsample', () => {
|
it.each(downsampleCases)('downsamples correctly from %s', (_d, { input, output }) =>
|
||||||
[
|
expectSample(input, output, true),
|
||||||
{ 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('should maintain sample', () => {
|
const upsampleCases: TestCase[] = [
|
||||||
[
|
['Odd -> Even', { input: [2, 0, 2], output: [2, 2, 0, 0, 2, 2] }],
|
||||||
{ input: [2, 0, 2], output: [2, 0, 2] }, // Odd
|
['Odd -> Odd', { input: [2, 0, 2], output: [2, 2, 0, 0, 2] }],
|
||||||
{ input: [2, 0], output: [2, 0] }, // Even
|
['Even -> Odd', { input: [2, 0], output: [2, 2, 2, 0, 0] }],
|
||||||
].forEach((c, i) => expectSample(i, c.input, c.output, true));
|
['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', () => {
|
describe('arrayRescale', () => {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import { ReactWrapper } from "enzyme";
|
import { ReactWrapper } from "enzyme";
|
||||||
|
import { Room } from "matrix-js-sdk";
|
||||||
|
|
||||||
import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient";
|
import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient";
|
||||||
import { mkEvent, mkStubRoom } from "../test-utils";
|
import { mkEvent, mkStubRoom } from "../test-utils";
|
||||||
|
@ -60,6 +61,24 @@ export const mkRoom = (client: MatrixClient, roomId: string, rooms?: ReturnType<
|
||||||
return room;
|
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<string, Map<string, MatrixEvent>>());
|
||||||
|
|
||||||
|
room.currentState.events = eventsMap;
|
||||||
|
};
|
||||||
|
|
||||||
export const mkSpace = (
|
export const mkSpace = (
|
||||||
client: MatrixClient,
|
client: MatrixClient,
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
|
|
Loading…
Reference in New Issue