diff --git a/__mocks__/emoji-picker-react.js b/__mocks__/emoji-picker-react.js new file mode 100644 index 0000000..81d39e0 --- /dev/null +++ b/__mocks__/emoji-picker-react.js @@ -0,0 +1,6 @@ +import React from "react"; +import { ReactElement } from "react"; + +const MockPicker = () =>
Emoji Picker
+ +export default MockPicker; \ No newline at end of file diff --git a/__mocks__/matrix-js-sdk.js b/__mocks__/matrix-js-sdk.js index 6565450..16a0094 100644 --- a/__mocks__/matrix-js-sdk.js +++ b/__mocks__/matrix-js-sdk.js @@ -45,6 +45,7 @@ export const mockDeactivateAccount = jest.fn(() => { return Promise.resolve('value'); }); export const mockOn = jest.fn() +export const mockSetDisplayName = jest.fn() export const mockClient = { registerRequest: mockRegisterRequest, @@ -64,6 +65,9 @@ export const mockClient = { setPowerLevel: mockSetPowerLevel, sendTextMessage: mockSendTextMessage, deactivateAccount: mockDeactivateAccount, + setDisplayName: mockSetDisplayName, } +export const WebStorageSessionStore = jest.fn() + export const createClient = jest.fn().mockReturnValue(mockClient) diff --git a/src/components/chatbox.jsx b/src/components/chatbox.jsx index d9634db..8178948 100644 --- a/src/components/chatbox.jsx +++ b/src/components/chatbox.jsx @@ -471,8 +471,6 @@ class ChatBox extends React.Component { handleSubmit = e => { e.preventDefault() const message = this.state.inputValue - console.log('event', e) - console.log('message', message) if (!Boolean(message)) return null; if (this.state.client && this.state.roomId) { diff --git a/src/components/chatbox.test.js b/src/components/chatbox.test.js index d706033..1d90028 100644 --- a/src/components/chatbox.test.js +++ b/src/components/chatbox.test.js @@ -21,24 +21,24 @@ import { createWaitForElement } from 'enzyme-wait'; import { config } from 'react-transition-group'; import waitForExpect from 'wait-for-expect' + config.disabled = true -const testConfig = { +var testConfig = { matrixServerUrl: 'https://matrix.rhok.space', - botUsername: '@help-bot:rhok.space', + botId: '@help-bot:rhok.space', roomName: 'Support Chat', termsUrl: 'https://tosdr.org/', introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.', - agreementMessage: '👉 Do you want to continue? Type yes or no.', + agreementMessage: 'Do you want to continue?', confirmationMessage: 'Waiting for a facilitator to join the chat...', - exitMessage: 'The chat was not started.', + exitMessage: 'The chat is closed. You may close this window.', chatUnavailableMessage: 'The chat service is not available right now. Please try again later.', anonymousDisplayName: 'Anonymous', } describe('Chatbox', () => { - beforeEach(() => { createClient.mockClear() mockInitCrypto.mockClear() @@ -52,6 +52,7 @@ describe('Chatbox', () => { mockClearStores.mockClear() mockOnce.mockClear() mockOn.mockClear() + mockSendTextMessage.mockClear() }) test('chat window should open and close', async () => { diff --git a/src/components/emoji-selector.jsx b/src/components/emoji-selector.jsx index 1727c6a..ad1b9e1 100644 --- a/src/components/emoji-selector.jsx +++ b/src/components/emoji-selector.jsx @@ -28,7 +28,10 @@ class EmojiSelector extends React.Component { status => { return(
- +
) } diff --git a/src/outputs/bookmarklet.test.js b/src/outputs/bookmarklet.test.js index 3f7f3e3..ca40031 100644 --- a/src/outputs/bookmarklet.test.js +++ b/src/outputs/bookmarklet.test.js @@ -2,6 +2,13 @@ import ReactDOM from 'react-dom'; import bookmarklet from './bookmarklet'; describe('bookmarklet', () => { + beforeAll(() => { + const el = document.querySelectorAll('body > div'); + ReactDOM.unmountComponentAtNode(el[0]); + el[0].parentNode.removeChild(el[0]); + window.EmbeddableChatbox = null; + }) + afterEach(() => { const el = document.querySelectorAll('body > div'); ReactDOM.unmountComponentAtNode(el[0]); diff --git a/src/outputs/embeddable-chatbox.test.js b/src/outputs/embeddable-chatbox.test.js index 3578a2d..bf10b81 100644 --- a/src/outputs/embeddable-chatbox.test.js +++ b/src/outputs/embeddable-chatbox.test.js @@ -1,8 +1,15 @@ import EmbeddableChatbox from './embeddable-chatbox'; -import { waitForSelection } from '../test-helpers'; +import { waitForSelection } from '../utils/test-helpers'; describe('EmbeddableChatbox', () => { + beforeAll(() => { + document.readyState = 'complete'; + if (EmbeddableChatbox.el) { + EmbeddableChatbox.unmount(); + } + }); + afterEach(() => { document.readyState = 'complete'; if (EmbeddableChatbox.el) { diff --git a/src/utils/test-helpers.js b/src/utils/test-helpers.js new file mode 100644 index 0000000..63ab46e --- /dev/null +++ b/src/utils/test-helpers.js @@ -0,0 +1,30 @@ +function checkFunc(dom, selector) { + if (typeof dom.update === 'function') { + const el = dom.update().find(selector); + if (el.exists()) { + return el; + } + return null; + } + const els = dom.querySelectorAll(selector); + if (els.length !== 0) { + return els; + } + return null; +} + + +export async function waitForSelection(dom, selector) { + let numSleep = 0; + for (;;) { + const el = checkFunc(dom, selector); + if (el) { + return el; + } + if (numSleep > 2) { + throw new Error(`could not find ${selector}`); + } + await new Promise(resolve => setTimeout(resolve, 250)); + numSleep += 1; + } +} \ No newline at end of file