diff --git a/src/tchap/components/views/dialogs/ExpiredAccountDialog.tsx b/src/tchap/components/views/dialogs/ExpiredAccountDialog.tsx index a712570929..ad174e7f28 100644 --- a/src/tchap/components/views/dialogs/ExpiredAccountDialog.tsx +++ b/src/tchap/components/views/dialogs/ExpiredAccountDialog.tsx @@ -96,7 +96,7 @@ export default class ExpiredAccountDialog extends React.Component{_t("An email has been sent to you. Click on the link it contains, click below.")}

); let alertMessage = null; - let requestNewEmailButton = ; + let requestNewEmailButton = ; let okButtonText = _t("I renewed the validity of my account"); switch (this.state.ProcessState) { @@ -107,18 +107,18 @@ export default class ExpiredAccountDialog extends React.Component +

{_t("Wait for at least %(wait)s seconds between two emails", { wait: this.state.emailDelaySecs })}

); break; case ProcessState.EMAIL_FAILURE: alertMessage = ( -

{_t("The email was not sent sucessfully, please retry in a moment")}

+

{_t("The email was not sent sucessfully, please retry in a moment")}

); break; case ProcessState.EMAIL_SUCCESS: - alertMessage =

{_t("A new email has been sent")}

; + alertMessage =

{_t("A new email has been sent")}

; break; case ProcessState.ACCOUNT_STILL_EXPIRED: alertMessage = ( diff --git a/test/unit-tests/tchap/components/views/dialogs/ExpiredAccountDialog-test.tsx b/test/unit-tests/tchap/components/views/dialogs/ExpiredAccountDialog-test.tsx index 3bdec63389..ed592d46a2 100644 --- a/test/unit-tests/tchap/components/views/dialogs/ExpiredAccountDialog-test.tsx +++ b/test/unit-tests/tchap/components/views/dialogs/ExpiredAccountDialog-test.tsx @@ -1,5 +1,65 @@ +import * as React from "react"; +import { render, screen } from "@testing-library/react"; + +import ExpiredAccountDialog from "~tchap-web/src/tchap/components/views/dialogs/ExpiredAccountDialog"; +import { flushPromises } from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/test/test-utils"; + describe("ExpiredAccountDialog", () => { - it("sends email when 'Send email' button is clicked", () => {}); + describe("'Send email' button", () => { + it("sends email when button is clicked", async () => { + // true = email sent successfully + const onRequestNewEmailMock = jest.fn().mockResolvedValue(true); + + const component = render( + , + ); + const sendEmailButton = screen.getByTestId("dialog-send-email-button"); + sendEmailButton.click(); + + expect(onRequestNewEmailMock).toHaveBeenCalled(); + // wait spinner is displayed + expect(component.container.querySelector(".mx_InlineSpinner")).toBeTruthy(); + + await flushPromises(); + // confirmation message is displayed + screen.getByTestId("dialog-email-sent-message"); + }); + + it("tells user if sending email failed", async () => { + // false = email sending failed + const onRequestNewEmailMock = jest.fn().mockResolvedValue(false); + + const component = render( + , + ); + const sendEmailButton = screen.getByTestId("dialog-send-email-button"); + sendEmailButton.click(); + + expect(onRequestNewEmailMock).toHaveBeenCalled(); + // wait spinner is displayed + expect(component.container.querySelector(".mx_InlineSpinner")).toBeTruthy(); + + await flushPromises(); + // confirmation message is displayed + screen.getByTestId("dialog-email-failure-message"); + }); + + it("sends only one email when button is clicked twice", async () => { + // true = email sent successfully + const onRequestNewEmailMock = jest.fn().mockResolvedValue(true); + + render(); + const sendEmailButton = screen.getByTestId("dialog-send-email-button"); + + sendEmailButton.click(); + await flushPromises(); + sendEmailButton.click(); + await flushPromises(); + expect(onRequestNewEmailMock).toHaveBeenCalledTimes(1); // only 1 email sent + screen.getByTestId("dialog-email-wait-message"); // user notified that they must wait + }); + }); + it("when 'I renewed' is clicked, and the account is renewed, it displays 'cool' and unblocks user (todo)", () => {}); it("when 'I renewed' is clicked, and the account is not renewed, it displays 'not cool' and keeps dialog up (todo)", () => {}); });