Skip to content

Commit

Permalink
Implment ExpiredAccountHandler-test
Browse files Browse the repository at this point in the history
  • Loading branch information
estellecomment committed Apr 11, 2024
1 parent 15e2fb9 commit 105ba3f
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions test/unit-tests/tchap/lib/ExpiredAccountHandler-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
import { mocked, MockedObject } from "jest-mock";

import ExpiredAccountDialog from "~tchap-web/src/tchap/components/views/dialogs/ExpiredAccountDialog";
import ExpiredAccountHandler from "~tchap-web/src/tchap/lib/ExpiredAccountHandler";
import { HttpApiEvent, MatrixClient } from "~tchap-web/yarn-linked-dependencies/matrix-js-sdk/src/matrix";
import Modal from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/Modal";
import defaultDispatcher from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/dispatcher/dispatcher";
import { getMockClientWithEventEmitter } from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/test/test-utils";

describe("ExpiredAccountHandler", () => {
let mockClient: MockedObject<MatrixClient>;

beforeEach(() => {
Modal.createDialog = jest.fn();
// @ts-ignore mock (type error because empty return)
mocked(Modal.createDialog).mockReturnValue({});

mockClient = getMockClientWithEventEmitter({
stopClient: jest.fn(),
removeAllListeners: jest.fn(),
});
});

afterEach(() => {
jest.clearAllMocks();
});

it("displays dialog when account is expired", () => {
// Modal.createDialog
// create handler
// dispatch action : will_start_client
// handler instance is created when import ExpiredAccountHandler is run.
ExpiredAccountHandler.register();

// Simulate start of app, for handler to initialise
defaultDispatcher.dispatch({ action: "will_start_client" }, true);

// Simulate expired error
// cli.on(HttpApiEvent.ORG_MATRIX_EXPIRED_ACCOUNT)
// expect Modal.createDialog to have been called, with ExpiredAccountDialog class
// this.eventEmitter.emit(HttpApiEvent.ORG_MATRIX_EXPIRED_ACCOUNT, err);
mockClient.emit(HttpApiEvent.ORG_MATRIX_EXPIRED_ACCOUNT);

expect(Modal.createDialog).toHaveBeenCalledWith(
ExpiredAccountDialog,
{
onRequestNewEmail: expect.any(Function),
onFinished: expect.any(Function),
},
undefined /* className */,
false /* isPriorityModal */,
true /* isStaticModal */,
{ onBeforeClose: expect.any(Function) },
);
});
});

0 comments on commit 105ba3f

Please sign in to comment.