Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -32,12 +32,7 @@ import {
|
|||
PollEndEvent,
|
||||
} from "matrix-events-sdk";
|
||||
|
||||
import {
|
||||
stubClient,
|
||||
mkStubRoom,
|
||||
mkEvent,
|
||||
mkMessage,
|
||||
} from "../../../test-utils";
|
||||
import { stubClient, mkStubRoom, mkEvent, mkMessage } from "../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import PinnedMessagesCard from "../../../../src/components/views/right_panel/PinnedMessagesCard";
|
||||
import PinnedEventTile from "../../../../src/components/views/rooms/PinnedEventTile";
|
||||
|
@ -53,31 +48,34 @@ describe("<PinnedMessagesCard />", () => {
|
|||
cli.relations.mockResolvedValue({ originalEvent: {} as unknown as MatrixEvent, events: [] });
|
||||
|
||||
const mkRoom = (localPins: MatrixEvent[], nonLocalPins: MatrixEvent[]): Room => {
|
||||
const room = mkStubRoom("!room:example.org", 'room', cli);
|
||||
const room = mkStubRoom("!room:example.org", "room", cli);
|
||||
// Deferred since we may be adding or removing pins later
|
||||
const pins = () => [...localPins, ...nonLocalPins];
|
||||
|
||||
// Insert pin IDs into room state
|
||||
mocked(room.currentState).getStateEvents.mockImplementation((): any => mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomPinnedEvents,
|
||||
content: {
|
||||
pinned: pins().map(e => e.getId()),
|
||||
},
|
||||
user: '@user:example.org',
|
||||
room: '!room:example.org',
|
||||
}));
|
||||
mocked(room.currentState).getStateEvents.mockImplementation((): any =>
|
||||
mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomPinnedEvents,
|
||||
content: {
|
||||
pinned: pins().map((e) => e.getId()),
|
||||
},
|
||||
user: "@user:example.org",
|
||||
room: "!room:example.org",
|
||||
}),
|
||||
);
|
||||
|
||||
// Insert local pins into local timeline set
|
||||
room.getUnfilteredTimelineSet = () => ({
|
||||
getTimelineForEvent: () => ({
|
||||
getEvents: () => localPins,
|
||||
}),
|
||||
} as unknown as EventTimelineSet);
|
||||
room.getUnfilteredTimelineSet = () =>
|
||||
({
|
||||
getTimelineForEvent: () => ({
|
||||
getEvents: () => localPins,
|
||||
}),
|
||||
} as unknown as EventTimelineSet);
|
||||
|
||||
// Return all pins over fetchRoomEvent
|
||||
cli.fetchRoomEvent.mockImplementation((roomId, eventId) => {
|
||||
const event = pins().find(e => e.getId() === eventId)?.event;
|
||||
const event = pins().find((e) => e.getId() === eventId)?.event;
|
||||
return Promise.resolve(event as IMinimalEvent);
|
||||
});
|
||||
|
||||
|
@ -87,16 +85,19 @@ describe("<PinnedMessagesCard />", () => {
|
|||
const mountPins = async (room: Room): Promise<ReactWrapper<ComponentProps<typeof PinnedMessagesCard>>> => {
|
||||
let pins;
|
||||
await act(async () => {
|
||||
pins = mount(<PinnedMessagesCard
|
||||
room={room}
|
||||
onClose={jest.fn()}
|
||||
permalinkCreator={new RoomPermalinkCreator(room, room.roomId)}
|
||||
/>, {
|
||||
wrappingComponent: MatrixClientContext.Provider,
|
||||
wrappingComponentProps: { value: cli },
|
||||
});
|
||||
pins = mount(
|
||||
<PinnedMessagesCard
|
||||
room={room}
|
||||
onClose={jest.fn()}
|
||||
permalinkCreator={new RoomPermalinkCreator(room, room.roomId)}
|
||||
/>,
|
||||
{
|
||||
wrappingComponent: MatrixClientContext.Provider,
|
||||
wrappingComponentProps: { value: cli },
|
||||
},
|
||||
);
|
||||
// Wait a tick for state updates
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
});
|
||||
pins.update();
|
||||
|
||||
|
@ -105,15 +106,16 @@ describe("<PinnedMessagesCard />", () => {
|
|||
|
||||
const emitPinUpdates = async (pins: ReactWrapper<ComponentProps<typeof PinnedMessagesCard>>) => {
|
||||
const room = pins.props().room;
|
||||
const pinListener = mocked(room.currentState).on.mock.calls
|
||||
.find(([eventName, listener]) => eventName === RoomStateEvent.Events)[1];
|
||||
const pinListener = mocked(room.currentState).on.mock.calls.find(
|
||||
([eventName, listener]) => eventName === RoomStateEvent.Events,
|
||||
)[1];
|
||||
|
||||
await act(async () => {
|
||||
// Emit the update
|
||||
// @ts-ignore what is going on here?
|
||||
pinListener(room.currentState.getStateEvents());
|
||||
// Wait a tick for state updates
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
});
|
||||
pins.update();
|
||||
};
|
||||
|
@ -240,12 +242,14 @@ describe("<PinnedMessagesCard />", () => {
|
|||
["@alice:example.org", 0],
|
||||
["@bob:example.org", 0],
|
||||
["@eve:example.org", 1],
|
||||
].map(([user, option], i) => mkEvent({
|
||||
...PollResponseEvent.from([answers[option].id], poll.getId()).serialize(),
|
||||
event: true,
|
||||
room: "!room:example.org",
|
||||
user: user as string,
|
||||
}));
|
||||
].map(([user, option], i) =>
|
||||
mkEvent({
|
||||
...PollResponseEvent.from([answers[option].id], poll.getId()).serialize(),
|
||||
event: true,
|
||||
room: "!room:example.org",
|
||||
user: user as string,
|
||||
}),
|
||||
);
|
||||
const end = mkEvent({
|
||||
...PollEndEvent.from(poll.getId(), "Closing the poll").serialize(),
|
||||
event: true,
|
||||
|
@ -259,9 +263,9 @@ describe("<PinnedMessagesCard />", () => {
|
|||
switch (eventType) {
|
||||
case M_POLL_RESPONSE.name:
|
||||
// Paginate the results, for added challenge
|
||||
return (from === "page2") ?
|
||||
{ originalEvent: poll, events: responses.slice(2) } :
|
||||
{ originalEvent: poll, events: responses.slice(0, 2), nextBatch: "page2" };
|
||||
return from === "page2"
|
||||
? { originalEvent: poll, events: responses.slice(2) }
|
||||
: { originalEvent: poll, events: responses.slice(0, 2), nextBatch: "page2" };
|
||||
case M_POLL_END.name:
|
||||
return { originalEvent: null, events: [end] };
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import { stubClient } from "../../../test-utils";
|
||||
|
||||
describe("RoomHeaderButtons-test.tsx", function() {
|
||||
describe("RoomHeaderButtons-test.tsx", function () {
|
||||
const ROOM_ID = "!roomId:example.org";
|
||||
let room: Room;
|
||||
let client: MatrixClient;
|
||||
|
@ -45,10 +45,7 @@ describe("RoomHeaderButtons-test.tsx", function() {
|
|||
});
|
||||
|
||||
function getComponent(room?: Room) {
|
||||
return render(<RoomHeaderButtons
|
||||
room={room}
|
||||
excludedRightPanelPhaseButtons={[]}
|
||||
/>);
|
||||
return render(<RoomHeaderButtons room={room} excludedRightPanelPhaseButtons={[]} />);
|
||||
}
|
||||
|
||||
function getThreadButton(container) {
|
||||
|
@ -56,9 +53,7 @@ describe("RoomHeaderButtons-test.tsx", function() {
|
|||
}
|
||||
|
||||
function isIndicatorOfType(container, type: "red" | "gray") {
|
||||
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")
|
||||
.className
|
||||
.includes(type);
|
||||
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator").className.includes(type);
|
||||
}
|
||||
|
||||
it("shows the thread button", () => {
|
||||
|
|
|
@ -14,24 +14,24 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React from "react";
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { mount } from 'enzyme';
|
||||
import { mocked } from 'jest-mock';
|
||||
import { mount } from "enzyme";
|
||||
import { mocked } from "jest-mock";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { Room, User, MatrixClient } from 'matrix-js-sdk/src/matrix';
|
||||
import { Phase, VerificationRequest } from 'matrix-js-sdk/src/crypto/verification/request/VerificationRequest';
|
||||
import { Room, User, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { Phase, VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||
|
||||
import UserInfo from '../../../../src/components/views/right_panel/UserInfo';
|
||||
import { RightPanelPhases } from '../../../../src/stores/right-panel/RightPanelStorePhases';
|
||||
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
|
||||
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
|
||||
import VerificationPanel from '../../../../src/components/views/right_panel/VerificationPanel';
|
||||
import EncryptionInfo from '../../../../src/components/views/right_panel/EncryptionInfo';
|
||||
import UserInfo from "../../../../src/components/views/right_panel/UserInfo";
|
||||
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
import VerificationPanel from "../../../../src/components/views/right_panel/VerificationPanel";
|
||||
import EncryptionInfo from "../../../../src/components/views/right_panel/EncryptionInfo";
|
||||
|
||||
const findByTestId = (component, id) => component.find(`[data-test-id="${id}"]`);
|
||||
|
||||
jest.mock('../../../../src/utils/DMRoomMap', () => {
|
||||
jest.mock("../../../../src/utils/DMRoomMap", () => {
|
||||
const mock = {
|
||||
getUserIdForRoomId: jest.fn(),
|
||||
getDMRoomsForUserId: jest.fn(),
|
||||
|
@ -43,8 +43,8 @@ jest.mock('../../../../src/utils/DMRoomMap', () => {
|
|||
};
|
||||
});
|
||||
|
||||
describe('<UserInfo />', () => {
|
||||
const defaultUserId = '@test:test';
|
||||
describe("<UserInfo />", () => {
|
||||
const defaultUserId = "@test:test";
|
||||
const defaultUser = new User(defaultUserId);
|
||||
|
||||
const mockClient = mocked({
|
||||
|
@ -57,7 +57,7 @@ describe('<UserInfo />', () => {
|
|||
isSynapseAdministrator: jest.fn().mockResolvedValue(false),
|
||||
isRoomEncrypted: jest.fn().mockReturnValue(false),
|
||||
doesServerSupportUnstableFeature: jest.fn().mockReturnValue(false),
|
||||
mxcUrlToHttp: jest.fn().mockReturnValue('mock-mxcUrlToHttp'),
|
||||
mxcUrlToHttp: jest.fn().mockReturnValue("mock-mxcUrlToHttp"),
|
||||
removeListener: jest.fn(),
|
||||
currentState: {
|
||||
on: jest.fn(),
|
||||
|
@ -65,7 +65,9 @@ describe('<UserInfo />', () => {
|
|||
} as unknown as MatrixClient);
|
||||
|
||||
const verificationRequest = {
|
||||
pending: true, on: jest.fn(), phase: Phase.Ready,
|
||||
pending: true,
|
||||
on: jest.fn(),
|
||||
phase: Phase.Ready,
|
||||
channel: { transactionId: 1 },
|
||||
otherPartySupportsMethod: jest.fn(),
|
||||
} as unknown as VerificationRequest;
|
||||
|
@ -77,51 +79,49 @@ describe('<UserInfo />', () => {
|
|||
onClose: jest.fn(),
|
||||
};
|
||||
|
||||
const getComponent = (props = {}) => mount(
|
||||
<UserInfo {...defaultProps} {...props} />,
|
||||
{
|
||||
const getComponent = (props = {}) =>
|
||||
mount(<UserInfo {...defaultProps} {...props} />, {
|
||||
wrappingComponent: MatrixClientContext.Provider,
|
||||
wrappingComponentProps: { value: mockClient },
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient);
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mockClient.getUser.mockClear().mockReturnValue({} as unknown as User);
|
||||
});
|
||||
|
||||
it('closes on close button click', () => {
|
||||
it("closes on close button click", () => {
|
||||
const onClose = jest.fn();
|
||||
const component = getComponent({ onClose });
|
||||
act(() => {
|
||||
findByTestId(component, 'base-card-close-button').at(0).simulate('click');
|
||||
findByTestId(component, "base-card-close-button").at(0).simulate("click");
|
||||
});
|
||||
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('without a room', () => {
|
||||
it('does not render space header', () => {
|
||||
describe("without a room", () => {
|
||||
it("does not render space header", () => {
|
||||
const component = getComponent();
|
||||
expect(findByTestId(component, 'space-header').length).toBeFalsy();
|
||||
expect(findByTestId(component, "space-header").length).toBeFalsy();
|
||||
});
|
||||
|
||||
it('renders user info', () => {
|
||||
it("renders user info", () => {
|
||||
const component = getComponent();
|
||||
expect(component.find("BasicUserInfo").length).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders encryption info panel without pending verification', () => {
|
||||
it("renders encryption info panel without pending verification", () => {
|
||||
const phase = RightPanelPhases.EncryptionPanel;
|
||||
const component = getComponent({ phase });
|
||||
|
||||
expect(component.find(EncryptionInfo).length).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders encryption verification panel with pending verification', () => {
|
||||
it("renders encryption verification panel with pending verification", () => {
|
||||
const phase = RightPanelPhases.EncryptionPanel;
|
||||
const component = getComponent({ phase, verificationRequest });
|
||||
|
||||
|
@ -129,22 +129,22 @@ describe('<UserInfo />', () => {
|
|||
expect(component.find(VerificationPanel).length).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders close button correctly when encryption panel with a pending verification request', () => {
|
||||
it("renders close button correctly when encryption panel with a pending verification request", () => {
|
||||
const phase = RightPanelPhases.EncryptionPanel;
|
||||
const component = getComponent({ phase, verificationRequest });
|
||||
|
||||
expect(findByTestId(component, 'base-card-close-button').at(0).props().title).toEqual('Cancel');
|
||||
expect(findByTestId(component, "base-card-close-button").at(0).props().title).toEqual("Cancel");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a room', () => {
|
||||
describe("with a room", () => {
|
||||
const room = {
|
||||
roomId: '!fkfk',
|
||||
roomId: "!fkfk",
|
||||
getType: jest.fn().mockReturnValue(undefined),
|
||||
isSpaceRoom: jest.fn().mockReturnValue(false),
|
||||
getMember: jest.fn().mockReturnValue(undefined),
|
||||
getMxcAvatarUrl: jest.fn().mockReturnValue('mock-avatar-url'),
|
||||
name: 'test room',
|
||||
getMxcAvatarUrl: jest.fn().mockReturnValue("mock-avatar-url"),
|
||||
name: "test room",
|
||||
on: jest.fn(),
|
||||
currentState: {
|
||||
getStateEvents: jest.fn(),
|
||||
|
@ -152,32 +152,33 @@ describe('<UserInfo />', () => {
|
|||
},
|
||||
} as unknown as Room;
|
||||
|
||||
it('renders user info', () => {
|
||||
it("renders user info", () => {
|
||||
const component = getComponent();
|
||||
expect(component.find("BasicUserInfo").length).toBeTruthy();
|
||||
});
|
||||
|
||||
it('does not render space header when room is not a space room', () => {
|
||||
it("does not render space header when room is not a space room", () => {
|
||||
const component = getComponent({ room });
|
||||
expect(findByTestId(component, 'space-header').length).toBeFalsy();
|
||||
expect(findByTestId(component, "space-header").length).toBeFalsy();
|
||||
});
|
||||
|
||||
it('renders space header when room is a space room', () => {
|
||||
it("renders space header when room is a space room", () => {
|
||||
const spaceRoom = {
|
||||
...room, isSpaceRoom: jest.fn().mockReturnValue(true),
|
||||
...room,
|
||||
isSpaceRoom: jest.fn().mockReturnValue(true),
|
||||
};
|
||||
const component = getComponent({ room: spaceRoom });
|
||||
expect(findByTestId(component, 'space-header').length).toBeTruthy();
|
||||
expect(findByTestId(component, "space-header").length).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders encryption info panel without pending verification', () => {
|
||||
it("renders encryption info panel without pending verification", () => {
|
||||
const phase = RightPanelPhases.EncryptionPanel;
|
||||
const component = getComponent({ phase, room });
|
||||
|
||||
expect(component.find(EncryptionInfo).length).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders encryption verification panel with pending verification', () => {
|
||||
it("renders encryption verification panel with pending verification", () => {
|
||||
const phase = RightPanelPhases.EncryptionPanel;
|
||||
const component = getComponent({ phase, verificationRequest, room });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue