From 54d4980e84e8d0cdf316c20a07428a6f2959f69a Mon Sep 17 00:00:00 2001 From: Sharon Kennedy Date: Fri, 13 Mar 2020 13:35:07 -0400 Subject: [PATCH] initial test suite done --- src/components/chatbox.test.js | 68 ++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/src/components/chatbox.test.js b/src/components/chatbox.test.js index 1deb6e9..d706033 100644 --- a/src/components/chatbox.test.js +++ b/src/components/chatbox.test.js @@ -132,10 +132,6 @@ describe('Chatbox', () => { expect(createClient.mock.calls.length).toEqual(0) }) - test('notification should appear when facilitator joins chat', () => { - // - }) - test('submitted messages should be sent to matrix', async () => { const chatbox = mount() const dock = chatbox.find('button.dock') @@ -169,12 +165,59 @@ describe('Chatbox', () => { }); }) - test('received messages should appear in chat window', () => { - // + + test('decryption failure should lead to a new unencrypted chat', async () => { + const chatbox = mount() + const dock = chatbox.find('button.dock') + const instance = chatbox.instance() + + dock.simulate('click') + + const openChatWindow = await createWaitForElement('.widget-entered')(chatbox) + let acceptButton = await createWaitForElement('button#accept')(chatbox) + acceptButton = chatbox.find('button#accept') + + acceptButton.simulate('click') + + await waitForExpect(() => { + expect(mockCreateRoom).toHaveBeenCalled() + }); + + jest.spyOn(instance, 'initializeUnencryptedChat') + instance.handleDecryptionError() + + await waitForExpect(() => { + expect(mockLeave).toHaveBeenCalled() + }); + + await waitForExpect(() => { + expect(mockStopClient).toHaveBeenCalled() + }); + + await waitForExpect(() => { + expect(mockClearStores).toHaveBeenCalled() + }); + + expect(instance.initializeUnencryptedChat).toHaveBeenCalled() }) - test('decryption failure should lead to a new unencrypted chat', () => { - // + test('creating an unencrypted chat', async () => { + const chatbox = mount() + const instance = chatbox.instance() + + instance.initializeUnencryptedChat() + + await waitForExpect(() => { + expect(createClient).toHaveBeenCalled() + }) + + await waitForExpect(() => { + expect(mockStartClient).toHaveBeenCalled() + }) + + await waitForExpect(() => { + expect(mockInitCrypto).not.toHaveBeenCalled() + }) }) test('exiting the chat should leave the room and destroy client', async () => { @@ -216,4 +259,13 @@ describe('Chatbox', () => { expect(mockClearStores).toHaveBeenCalled() }); }) + + test('notification should appear when facilitator joins chat', () => { + // + }) + + test('received messages should appear in chat window', () => { + // + }) + });