Move timeline set creation logic to the JS SDK (#8070)
This commit is contained in:
parent
da097d42ef
commit
12d26555af
3 changed files with 22 additions and 204 deletions
|
@ -16,24 +16,16 @@ limitations under the License.
|
|||
|
||||
import React from 'react';
|
||||
import { shallow, mount } from "enzyme";
|
||||
import {
|
||||
MatrixClient,
|
||||
Room,
|
||||
} from 'matrix-js-sdk/src/matrix';
|
||||
import { mocked } from 'jest-mock';
|
||||
import '../../skinned-sdk';
|
||||
import { Thread } from 'matrix-js-sdk/src/models/thread';
|
||||
|
||||
import {
|
||||
ThreadFilterType,
|
||||
ThreadPanelHeader,
|
||||
ThreadPanelHeaderFilterOptionItem,
|
||||
getThreadTimelineSet,
|
||||
} from '../../../src/components/structures/ThreadPanel';
|
||||
import { ContextMenuButton } from '../../../src/accessibility/context_menu/ContextMenuButton';
|
||||
import ContextMenu from '../../../src/components/structures/ContextMenu';
|
||||
import { _t } from '../../../src/languageHandler';
|
||||
import { makeThread } from '../../test-utils/threads';
|
||||
|
||||
describe('ThreadPanel', () => {
|
||||
describe('Header', () => {
|
||||
|
@ -87,109 +79,4 @@ describe('ThreadPanel', () => {
|
|||
expect(foundButton).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getThreadTimelineSet()', () => {
|
||||
const filterId = '123';
|
||||
const client = {
|
||||
getUserId: jest.fn(),
|
||||
doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(false),
|
||||
decryptEventIfNeeded: jest.fn().mockResolvedValue(undefined),
|
||||
getOrCreateFilter: jest.fn().mockResolvedValue(filterId),
|
||||
paginateEventTimeline: jest.fn().mockResolvedValue(undefined),
|
||||
} as unknown as MatrixClient;
|
||||
|
||||
const aliceId = '@alice:server.org';
|
||||
const bobId = '@bob:server.org';
|
||||
const charlieId = '@charlie:server.org';
|
||||
const room = new Room('!room1:server.org', client, aliceId);
|
||||
|
||||
const roomWithThreads = new Room('!room2:server.org', client, aliceId);
|
||||
const aliceAndBobThread = makeThread(client, roomWithThreads, {
|
||||
authorId: aliceId,
|
||||
participantUserIds: [aliceId, bobId],
|
||||
roomId: roomWithThreads.roomId,
|
||||
});
|
||||
const justBobThread = makeThread(client, roomWithThreads, {
|
||||
authorId: bobId,
|
||||
participantUserIds: [bobId],
|
||||
roomId: roomWithThreads.roomId,
|
||||
});
|
||||
const everyoneThread = makeThread(client, roomWithThreads, {
|
||||
authorId: charlieId,
|
||||
participantUserIds: [aliceId, bobId, charlieId],
|
||||
length: 5,
|
||||
roomId: roomWithThreads.roomId,
|
||||
});
|
||||
roomWithThreads.threads.set(aliceAndBobThread.id, aliceAndBobThread);
|
||||
roomWithThreads.threads.set(justBobThread.id, justBobThread);
|
||||
roomWithThreads.threads.set(everyoneThread.id, everyoneThread);
|
||||
|
||||
beforeEach(() => {
|
||||
mocked(client.getUserId).mockReturnValue(aliceId);
|
||||
mocked(client.doesServerSupportUnstableFeature).mockResolvedValue(false);
|
||||
});
|
||||
|
||||
describe('when extra capabilities are not enabled on server', () => {
|
||||
it('returns an empty timelineset when room has no threads', async () => {
|
||||
const result = await getThreadTimelineSet(client, room);
|
||||
|
||||
expect(result.getLiveTimeline().getEvents()).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns a timelineset with thread root events for room when filter is All', async () => {
|
||||
const result = await getThreadTimelineSet(client, roomWithThreads);
|
||||
|
||||
const resultEvents = result.getLiveTimeline().getEvents();
|
||||
expect(resultEvents.length).toEqual(3);
|
||||
expect(resultEvents).toEqual(expect.arrayContaining([
|
||||
justBobThread.rootEvent,
|
||||
aliceAndBobThread.rootEvent,
|
||||
everyoneThread.rootEvent,
|
||||
]));
|
||||
});
|
||||
|
||||
it('returns a timelineset with threads user has participated in when filter is My', async () => {
|
||||
// current user is alice
|
||||
mocked(client).getUserId.mockReturnValue(aliceId);
|
||||
|
||||
const result = await getThreadTimelineSet(client, roomWithThreads, ThreadFilterType.My);
|
||||
const resultEvents = result.getLiveTimeline().getEvents();
|
||||
expect(resultEvents).toEqual(expect.arrayContaining([
|
||||
// alice authored root event
|
||||
aliceAndBobThread.rootEvent,
|
||||
// alive replied to this thread
|
||||
everyoneThread.rootEvent,
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when extra capabilities are enabled on server', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
Thread.hasServerSideSupport = true;
|
||||
mocked(client.doesServerSupportUnstableFeature).mockResolvedValue(true);
|
||||
});
|
||||
|
||||
it('creates a filter with correct definition when filterType is All', async () => {
|
||||
await getThreadTimelineSet(client, room);
|
||||
|
||||
const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0];
|
||||
expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.All}`);
|
||||
expect(filter.getDefinition().room.timeline).toEqual({
|
||||
related_by_rel_types: ["m.thread"],
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a filter with correct definition when filterType is My', async () => {
|
||||
await getThreadTimelineSet(client, room, ThreadFilterType.My);
|
||||
|
||||
const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0];
|
||||
expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.My}`);
|
||||
expect(filter.getDefinition().room.timeline).toEqual({
|
||||
related_by_rel_types: ["m.thread"],
|
||||
related_by_senders: [aliceId],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue