1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00
This commit is contained in:
Travis Ralston
2021-06-09 22:09:26 -06:00
parent 1f6ba31a3f
commit e41a2beb65
7 changed files with 112 additions and 95 deletions

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {NamespacedValue, UnstableValue} from "../../src/NamespacedValue";
import { NamespacedValue, UnstableValue } from "../../src/NamespacedValue";
describe("NamespacedValue", () => {
it("should prefer stable over unstable", () => {

View File

@ -1,16 +1,17 @@
import { logger } from "../../src/logger";
import { MatrixClient } from "../../src/client";
import { Filter } from "../../src/filter";
import {DEFAULT_TREE_POWER_LEVELS_TEMPLATE} from "../../src/models/MSC3089TreeSpace";
import { DEFAULT_TREE_POWER_LEVELS_TEMPLATE } from "../../src/models/MSC3089TreeSpace";
import {
EventType,
RoomCreateTypeField, RoomType,
RoomCreateTypeField,
RoomType,
UNSTABLE_MSC3088_ENABLED,
UNSTABLE_MSC3088_PURPOSE,
UNSTABLE_MSC3089_TREE_SUBTYPE
UNSTABLE_MSC3089_TREE_SUBTYPE,
} from "../../src/@types/event";
import {MEGOLM_ALGORITHM} from "../../src/crypto/olmlib";
import {MatrixEvent} from "../../src/models/event";
import { MEGOLM_ALGORITHM } from "../../src/crypto/olmlib";
import { MatrixEvent } from "../../src/models/event";
jest.useFakeTimers();
@ -217,7 +218,7 @@ describe("MatrixClient", function() {
},
],
});
return {room_id: roomId};
return { room_id: roomId };
});
client.getUserId = () => userId;
client.createRoom = fn;

View File

@ -70,7 +70,8 @@ describe("MSC3089Branch", () => {
});
it('should be able to delete the file', async () => {
const stateFn = jest.fn().mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
const stateFn = jest.fn()
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
expect(roomId).toEqual(branchRoomId);
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
expect(content).toMatchObject({});
@ -107,7 +108,8 @@ describe("MSC3089Branch", () => {
it('should be able to change its name', async () => {
const name = "My File.txt";
indexEvent.getContent = () => ({ active: true, retained: true });
const stateFn = jest.fn().mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
const stateFn = jest.fn()
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
expect(roomId).toEqual(branchRoomId);
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
expect(content).toMatchObject({

View File

@ -83,7 +83,8 @@ describe("MSC3089TreeSpace", () => {
it('should support setting the name of the space', async () => {
const newName = "NEW NAME";
const fn = jest.fn().mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
const fn = jest.fn()
.mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
expect(stateRoomId).toEqual(roomId);
expect(eventType).toEqual(EventType.RoomName);
expect(stateKey).toEqual("");
@ -109,7 +110,8 @@ describe("MSC3089TreeSpace", () => {
async function evaluatePowerLevels(pls: any, role: TreePermissions, expectedPl: number) {
makePowerLevels(pls);
const fn = jest.fn().mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
const fn = jest.fn()
.mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
expect(stateRoomId).toEqual(roomId);
expect(eventType).toEqual(EventType.RoomPowerLevels);
expect(stateKey).toEqual("");
@ -155,7 +157,7 @@ describe("MSC3089TreeSpace", () => {
users_default: 1024,
users: {
[targetUser]: 2222,
}
},
}, TreePermissions.Viewer, 1024);
});
@ -165,7 +167,7 @@ describe("MSC3089TreeSpace", () => {
events_default: 1024,
users: {
[targetUser]: 5,
}
},
}, TreePermissions.Editor, 1024);
});
@ -199,7 +201,8 @@ describe("MSC3089TreeSpace", () => {
expect(name).toEqual(subspaceName);
return new MSC3089TreeSpace(client, subspaceId);
});
const sendStateFn = jest.fn().mockImplementation(async (roomId: string, eventType: EventType, content: any, stateKey: string) => {
const sendStateFn = jest.fn()
.mockImplementation(async (roomId: string, eventType: EventType, content: any, stateKey: string) => {
expect([tree.roomId, subspaceId]).toContain(roomId);
if (roomId === subspaceId) {
expect(eventType).toEqual(EventType.SpaceParent);
@ -311,7 +314,7 @@ describe("MSC3089TreeSpace", () => {
// ensure we don't kick ourselves
{ getContent: () => ({ membership: "join" }), getStateKey: () => selfUserId },
]
];
},
};
@ -361,7 +364,7 @@ describe("MSC3089TreeSpace", () => {
getType: () => EventType.SpaceParent,
getStateKey: () => tree.roomId,
getContent: () => ({
via: [staticDomain]
via: [staticDomain],
}),
},
];
@ -408,7 +411,12 @@ describe("MSC3089TreeSpace", () => {
roomId: tree.roomId,
currentState: {
getStateEvents: (eventType: EventType, stateKey?: string) => {
expect([EventType.SpaceChild, EventType.RoomCreate, EventType.SpaceParent]).toContain(eventType);
expect([
EventType.SpaceChild,
EventType.RoomCreate,
EventType.SpaceParent,
]).toContain(eventType);
if (eventType === EventType.RoomCreate) {
expect(stateKey).toEqual("");
return parentState.filter(e => e.getType() === EventType.RoomCreate)[0];
@ -429,7 +437,8 @@ describe("MSC3089TreeSpace", () => {
(<any>tree).room = parentRoom; // override readonly
client.getRoom = (r) => rooms[r];
clientSendStateFn = jest.fn().mockImplementation((roomId: string, eventType: EventType, content: any, stateKey: string) => {
clientSendStateFn = jest.fn()
.mockImplementation((roomId: string, eventType: EventType, content: any, stateKey: string) => {
expect(roomId).toEqual(tree.roomId);
expect(eventType).toEqual(EventType.SpaceChild);
expect(content).toMatchObject(expect.objectContaining({
@ -652,7 +661,7 @@ describe("MSC3089TreeSpace", () => {
const d = "!d:example.org";
// Add in reverse order to make sure it gets ordered correctly
addSubspace(d, 4, "Z")
addSubspace(d, 4, "Z");
addSubspace(c, 3, "X");
addSubspace(b, 2, "V");
addSubspace(a, 1, "T");
@ -681,7 +690,7 @@ describe("MSC3089TreeSpace", () => {
const d = "!d:example.org";
// Add in reverse order to make sure it gets ordered correctly
addSubspace(d, 4, "Z")
addSubspace(d, 4, "Z");
addSubspace(c, 3, "X");
addSubspace(b, 2, "V");
addSubspace(a, 1, "T");
@ -710,7 +719,7 @@ describe("MSC3089TreeSpace", () => {
const d = "!d:example.org";
// Add in reverse order to make sure it gets ordered correctly
addSubspace(d, 4)
addSubspace(d, 4);
addSubspace(c, 3);
addSubspace(b, 2, "V");
addSubspace(a, 1, "T");
@ -775,7 +784,8 @@ describe("MSC3089TreeSpace", () => {
});
client.sendMessage = sendMsgFn;
const sendStateFn = jest.fn().mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
const sendStateFn = jest.fn()
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
expect(roomId).toEqual(tree.roomId);
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable
expect(stateKey).toEqual(fileEventId);

View File

@ -4,8 +4,9 @@ import {
averageBetweenStrings,
baseToString,
DEFAULT_ALPHABET,
nextString, prevString,
stringToBase
nextString,
prevString,
stringToBase,
} from "../../src/utils";
describe("utils", function() {
@ -270,7 +271,9 @@ describe("utils", function() {
describe('DEFAULT_ALPHABET', () => {
it('should be usefully printable ASCII in order', () => {
expect(DEFAULT_ALPHABET).toEqual(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
expect(DEFAULT_ALPHABET).toEqual(
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
);
});
});

View File

@ -74,9 +74,9 @@ export interface ICreateRoomOpts {
name?: string;
topic?: string;
preset?: string;
power_level_content_override?: any;
creation_content?: any;
initial_state?: {type: string, state_key: string, content: any}[];
power_level_content_override?: any;// eslint-disable-line camelcase
creation_content?: any;// eslint-disable-line camelcase
initial_state?: {type: string, state_key: string, content: any}[]; // eslint-disable-line camelcase
// TODO: Types (next line)
invite_3pid?: any[]; // eslint-disable-line camelcase
}

View File

@ -104,7 +104,8 @@ import {
RoomCreateTypeField,
RoomType,
UNSTABLE_MSC3088_ENABLED,
UNSTABLE_MSC3088_PURPOSE, UNSTABLE_MSC3089_TREE_SUBTYPE
UNSTABLE_MSC3088_PURPOSE,
UNSTABLE_MSC3089_TREE_SUBTYPE,
} from "./@types/event";
import { IImageInfo } from "./@types/partials";
import { EventMapper, eventMapperFor, MapperOpts } from "./event-mapper";