Skip to content

Commit

Permalink
fix invite dialog tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tore Simonsen committed Aug 23, 2024
1 parent f969c2a commit 128f0be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,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
42 changes: 33 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,21 @@ 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 +306,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 +319,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 +349,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 +370,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 +397,21 @@ 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 +433,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

0 comments on commit 128f0be

Please sign in to comment.