-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15e2fb9
commit 105ba3f
Showing
1 changed file
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }, | ||
); | ||
}); | ||
}); |