Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing tests part one 1 #81

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
private spaceMemberIds = [] as string[];
// Verji End


public constructor(props: Props) {
super(props);
// Verji Start - generate a list of userId's which are members in currently active space
Expand Down Expand Up @@ -733,7 +732,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial

let _externals = this.state.targetEmails;
if (_externals == null) _externals = [];
if (Email.looksValid(this.state.filterText)) {
if (Email.looksValid(this.state.filterText) && !_externals.includes(this.state.filterText)) {
_externals.push(this.state.filterText);
}

Expand Down
10 changes: 4 additions & 6 deletions src/components/views/messages/ReactionsRowButtonTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
CustomComponentLifecycle,
CustomComponentOpts,
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/CustomComponentLifecycle";

import { Tooltip } from "@vector-im/compound-web";

import { unicodeToShortcode } from "../../../HtmlUtils";
Expand Down Expand Up @@ -64,7 +63,7 @@ export default class ReactionsRowButtonTooltip extends React.PureComponent<Props

// Line 👇is Verji specific. If we wish to use upstream only we must implement CustomComponentLifecycle.ReactionsRowButtonTooltip
const formattedSenders = formatList(senders, 50);

const caption = shortName ? _t("timeline|reactions|tooltip_caption", { shortName }) : undefined;

const customReactionButtonTooltip = { CustomComponent: React.Fragment };
Expand All @@ -75,14 +74,13 @@ export default class ReactionsRowButtonTooltip extends React.PureComponent<Props

return (
<customReactionButtonTooltip.CustomComponent>

<Tooltip label={formattedSenders} caption={caption} placement="right">
{children}
{children}
</Tooltip>
</customReactionButtonTooltip.CustomComponent>
</customReactionButtonTooltip.CustomComponent>
);
}

return children;
}
}
}
12 changes: 6 additions & 6 deletions test/components/structures/ReactionsRowButtonTooltip-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import {
CustomComponentLifecycle,
CustomComponentOpts,
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/CustomComponentLifecycle";
import { Tooltip } from "@vector-im/compound-web";

import ReactionsRowButtonTooltip from "../../../src/components/views/messages/ReactionsRowButtonTooltip";
import { getMockClientWithEventEmitter } from "../../test-utils";
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
import { ModuleRunner } from "../../../src/modules/ModuleRunner";

import { Tooltip } from "@vector-im/compound-web";


describe("ReactionsRowButtonTooltip", () => {
const content = "Hello world!";
const reactionEvents = [] as any;
Expand Down Expand Up @@ -50,7 +48,9 @@ describe("ReactionsRowButtonTooltip", () => {
content={content}
reactionEvents={reactionEvents}
customReactionImagesEnabled={customReactionImagesEnabled}
/>
>
<div>Test tooltip</div>
</ReactionsRowButtonTooltip>
</MatrixClientContext.Provider>,
);

Expand All @@ -70,7 +70,7 @@ describe("ReactionsRowButtonTooltip", () => {
if (lifecycleEvent === CustomComponentLifecycle.ReactionsRowButtonTooltip) {
(opts as CustomComponentOpts).CustomComponent = ({ children }) => {
return (
<Tooltip label={"r1, r2"} caption={"caption"} placement="right">
<Tooltip label="r1, r2" caption="caption" placement="right">
<React.Fragment>
<div data-testid="test-header">Header</div>
</React.Fragment>
Expand All @@ -84,4 +84,4 @@ describe("ReactionsRowButtonTooltip", () => {
expect(screen.getByTestId("test-header")).toBeDefined();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`ReactionsRowButtonTooltip should render 1`] = `
<DocumentFragment>
<div />
<div>
Test tooltip
</div>
</DocumentFragment>
`;
40 changes: 31 additions & 9 deletions test/components/views/dialogs/InviteDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,20 @@ describe("InviteDialog", () => {
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server");
mockClient.lookupThreePid.mockResolvedValue({});

render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
// VERJI modify invite kind, due to heavy modifications in invitation flow
// render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);

const input = screen.getByTestId("invite-dialog-input");
input.focus();
await userEvent.paste(`${bobId} ${aliceEmail}`);

// VERJI modify test, by pasting individually and separating values with enter key
//await userEvent.paste(`${bobId} ${aliceEmail}`);
await userEvent.paste(`${bobId}`);
await userEvent.keyboard("[Enter]");

await userEvent.paste(`${aliceEmail}`);
await userEvent.keyboard("[Enter]");

await screen.findAllByText(bobId);
await screen.findByText(aliceEmail);
Expand All @@ -296,7 +305,9 @@ describe("InviteDialog", () => {
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server");
mockClient.lookupThreePid.mockResolvedValue({});

render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
// VERJI modify invite kind, due to heavy modifications in invitation flow
// render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);

const input = screen.getByTestId("invite-dialog-input");
input.focus();
Expand All @@ -307,7 +318,9 @@ describe("InviteDialog", () => {
});

it("should allow to invite multiple emails to a room", async () => {
render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
// VERJI modify invite kind, due to heavy modifications in invitation flow
// render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);

await enterIntoSearchField(aliceEmail);
expectPill(aliceEmail);
Expand Down Expand Up @@ -335,8 +348,8 @@ describe("InviteDialog", () => {
expectPill(bobEmail);
});
});

it("should not allow to invite more than one email to a DM", async () => {
// VERJI - skip this test, we do allow multiple email invites to dm.
it.skip("should not allow to invite more than one email to a DM", async () => {
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);

// Start with an email → should convert to a pill
Expand All @@ -356,7 +369,8 @@ describe("InviteDialog", () => {
expectNoPill(bobEmail);
});

it("should not allow to invite a MXID and an email to a DM", async () => {
// VERJI - skip this test, we do allow mxId and email invites to dm.
it.skip("should not allow to invite a MXID and an email to a DM", async () => {
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);

// Start with a MXID → should convert to a pill
Expand All @@ -382,13 +396,20 @@ describe("InviteDialog", () => {
});

it("should not allow pasting the same user multiple times", async () => {
render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
// VERJI modify invite kind, due to heavy modifications in invitation flow
// render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);

const input = screen.getByTestId("invite-dialog-input");
input.focus();
await userEvent.paste(`${bobId}`);
await userEvent.keyboard("[Enter]"); // Verji: Add this line to register input

await userEvent.paste(`${bobId}`);
await userEvent.keyboard("[Enter]"); // Verji: Add this line to register input

await userEvent.paste(`${bobId}`);
await userEvent.keyboard("[Enter]"); // Verji: Add this line to register input

expect(input).toHaveValue("");
await expect(screen.findAllByText(bobId, { selector: "a" })).resolves.toHaveLength(1);
Expand All @@ -410,7 +431,8 @@ describe("InviteDialog", () => {
expect(tile).toBeInTheDocument();
});

describe("when inviting a user with an unknown profile", () => {
// VERJI - skip these tests, because we prevent the "invite anyway modal"
describe.skip("when inviting a user with an unknown profile", () => {
beforeEach(async () => {
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);
await enterIntoSearchField(carolId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ exports[`AppTile preserves non-persisted widget on container move 1`] = `
>
<div
class="mx_AppsDrawer_resizer"
style="position: relative; user-select: auto; width: auto; height: 280px; max-height: 576px; min-height: 100px; box-sizing: border-box; flex-shrink: 0;"
style="position: relative; user-select: auto; width: auto; height: 380px; max-height: 576px; min-height: 100px; box-sizing: border-box; flex-shrink: 0;"
>
<div
class="mx_AppsContainer"
Expand Down
122 changes: 74 additions & 48 deletions test/components/views/rooms/RoomList-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,80 @@ const getDMRoomsForUserId = jest.fn();
// @ts-ignore
DMRoomMap.sharedInstance = { getUserIdForRoomId, getDMRoomsForUserId };

describe("UIFeature tests", () => {
stubClient();
//const client = MatrixClientPeg.safeGet();
const store = SpaceStore.instance;

function getComponent(props: Partial<ComponentProps<typeof RoomList>> = {}): JSX.Element {
return (
<RoomList
onKeyDown={jest.fn()}
onFocus={jest.fn()}
onBlur={jest.fn()}
onResize={jest.fn()}
resizeNotifier={new ResizeNotifier()}
isMinimized={false}
activeSpace={MetaSpace.Home}
{...props}
/>
);
}
beforeEach(() => {
store.setActiveSpace(MetaSpace.Home);
mocked(shouldShowComponent).mockImplementation((feature) => true);
});
describe("UIFeature.showStartChatPlusMenuForMetaSpace", () => {
it("UIFeature.showStartChatPlusMenuForMetaSpace = true: renders 'Start Chat' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
if (name == UIFeature.ShowStartChatPlusMenuForMetaSpace) return true;
return false;
});
render(getComponent());

expect(screen.getByLabelText("Start chat")).toBeInTheDocument();
});

it("UIFeature.showStartChatPlusMenuForMetaSpace = false: does not render 'Start Chat' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
if (name == UIFeature.ShowStartChatPlusMenuForMetaSpace) return false;
return false;
});
render(getComponent());
expect(screen.queryByLabelText("Start chat")).not.toBeInTheDocument();
});
});

describe("UIFeature.showAddRoomPlusMenuForMetaSpace", () => {
beforeEach(() => {
store.setActiveSpace(MetaSpace.Home);
});

it("UIFeature.showAddRoomPlusMenuForMetaSpace = true: renders 'Add room' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
if (name == UIFeature.ShowAddRoomPlusMenuForMetaSpace) return true;
return false;
});
render(getComponent());
expect(screen.getByLabelText("Add room")).toBeInTheDocument();
});

it("UIFeature.showAddRoomPlusMenuForMetaSpace = false: does not render 'Add room' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
if (name == UIFeature.ShowAddRoomPlusMenuForMetaSpace) return false;
return false;
});

render(getComponent());

expect(screen.queryByLabelText("Add room")).not.toBeInTheDocument();
});
});
afterEach(() => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => true);
});
});

describe("RoomList", () => {
stubClient();
const client = MatrixClientPeg.safeGet();
Expand Down Expand Up @@ -308,52 +382,4 @@ describe("RoomList", () => {
});
});
});

describe("UIFeature.showStartChatPlusMenuForMetaSpace", () => {
beforeEach(() => {
store.setActiveSpace(MetaSpace.Home);
});

it("UIFeature.showStartChatPlusMenuForMetaSpace = true: renders 'Start Chat' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((val) => {
return val === UIFeature.ShowStartChatPlusMenuForMetaSpace ? true : "default";
});
render(getComponent());

expect(screen.getByLabelText("Start chat")).toBeInTheDocument();
});

it("UIFeature.showStartChatPlusMenuForMetaSpace = false: does not render 'Start Chat' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((val) => {
return val === UIFeature.ShowStartChatPlusMenuForMetaSpace ? false : "default";
});
render(getComponent());

expect(screen.queryByLabelText("Start chat")).not.toBeInTheDocument();
});
});

describe("UIFeature.showAddRoomPlusMenuForMetaSpace", () => {
beforeEach(() => {
store.setActiveSpace(MetaSpace.Home);
});

it("UIFeature.showAddRoomPlusMenuForMetaSpace = true: renders 'Add room' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((val) => {
return val === UIFeature.ShowAddRoomPlusMenuForMetaSpace ? true : "default";
});
render(getComponent());

expect(screen.getByLabelText("Add room")).toBeInTheDocument();
});

it("UIFeature.showAddRoomPlusMenuForMetaSpace = false: does not render 'Add room' plus-button", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((val) => {
return val === UIFeature.ShowAddRoomPlusMenuForMetaSpace ? false : "default";
});
render(getComponent());

expect(screen.queryByLabelText("Add room")).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ exports[`PowerLevelSelector should display only the current user 1`] = `
>
Moderator
</option>
<option
data-testid="power-level-option-95"
value="95"
>
VerjiAdmin
</option>
<option
data-testid="power-level-option-100"
value="100"
Expand Down Expand Up @@ -109,6 +115,12 @@ exports[`PowerLevelSelector should render 1`] = `
>
Moderator
</option>
<option
data-testid="power-level-option-95"
value="95"
>
VerjiAdmin
</option>
<option
data-testid="power-level-option-100"
value="100"
Expand Down Expand Up @@ -154,6 +166,12 @@ exports[`PowerLevelSelector should render 1`] = `
>
Moderator
</option>
<option
data-testid="power-level-option-95"
value="95"
>
VerjiAdmin
</option>
<option
data-testid="power-level-option-100"
value="100"
Expand Down Expand Up @@ -199,6 +217,12 @@ exports[`PowerLevelSelector should render 1`] = `
>
Moderator
</option>
<option
data-testid="power-level-option-95"
value="95"
>
VerjiAdmin
</option>
<option
data-testid="power-level-option-100"
value="100"
Expand Down
Loading
Loading