forked from Github/ocrcc-chatbox
update tests
This commit is contained in:
parent
20a90f2d97
commit
c5b15034eb
@ -10,7 +10,7 @@ Built on:
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```
|
```
|
||||||
<script src="./chatbox.js"></script>
|
<script src="https://unpkg.com/safesupport-chatbox" type="text/javascript"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
matrixServerUrl: 'https://matrix.rhok.space',
|
matrixServerUrl: 'https://matrix.rhok.space',
|
||||||
@ -66,11 +66,11 @@ This chatbox is meant to be used with a bot account that handles a number of fun
|
|||||||
* Keeps a transcript of the conversation
|
* Keeps a transcript of the conversation
|
||||||
* Notifies user if there are not facilitators available
|
* Notifies user if there are not facilitators available
|
||||||
|
|
||||||
The bot account is invited to the chatroom when a support request is initiated.
|
The bot account is invited to the chatroom when a support request is initiated.
|
||||||
|
|
||||||
You can find the code for the bot at [ocrcc-bot](https://github.com/nomadic-labs/ocrcc-bot).
|
You can find the code for the bot at [ocrcc-bot](https://github.com/nomadic-labs/ocrcc-bot).
|
||||||
|
|
||||||
## Bookmarklet
|
## Bookmarklet
|
||||||
|
|
||||||
The bookmarklet is a special link that runs a script on any website. The user saves the link by dragging it to their bookmarks bar. Then they can click on the bookmark on any page to run the script and load the chatbox.
|
The bookmarklet is a special link that runs a script on any website. The user saves the link by dragging it to their bookmarks bar. Then they can click on the bookmark on any page to run the script and load the chatbox.
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ export const mockGetRoom = jest.fn()
|
|||||||
export const mockDownloadKeys = jest.fn()
|
export const mockDownloadKeys = jest.fn()
|
||||||
export const mockSetDeviceVerified = jest.fn()
|
export const mockSetDeviceVerified = jest.fn()
|
||||||
export const mockIsCryptoEnabled = jest.fn()
|
export const mockIsCryptoEnabled = jest.fn()
|
||||||
|
export const mockIsRoomEncrypted = jest.fn()
|
||||||
export const mockCreateRoom = jest.fn().mockReturnValue({ room_id: 'room_id_1234' })
|
export const mockCreateRoom = jest.fn().mockReturnValue({ room_id: 'room_id_1234' })
|
||||||
export const mockSetPowerLevel = jest.fn()
|
export const mockSetPowerLevel = jest.fn()
|
||||||
export const mockSendTextMessage = jest.fn(() => {
|
export const mockSendTextMessage = jest.fn(() => {
|
||||||
@ -61,6 +62,7 @@ export const mockClient = {
|
|||||||
setDeviceVerified: mockSetDeviceVerified,
|
setDeviceVerified: mockSetDeviceVerified,
|
||||||
setDeviceKnown: mockSetDeviceKnown,
|
setDeviceKnown: mockSetDeviceKnown,
|
||||||
isCryptoEnabled: mockIsCryptoEnabled,
|
isCryptoEnabled: mockIsCryptoEnabled,
|
||||||
|
isRoomEncrypted: mockIsRoomEncrypted,
|
||||||
createRoom: mockCreateRoom,
|
createRoom: mockCreateRoom,
|
||||||
setPowerLevel: mockSetPowerLevel,
|
setPowerLevel: mockSetPowerLevel,
|
||||||
sendTextMessage: mockSendTextMessage,
|
sendTextMessage: mockSendTextMessage,
|
||||||
|
@ -75,12 +75,10 @@ class ChatBox extends React.Component {
|
|||||||
let isMobile = false;
|
let isMobile = false;
|
||||||
|
|
||||||
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
|
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
|
||||||
console.log('navigator.userAgent', navigator.userAgent)
|
|
||||||
isMobile = true;
|
isMobile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (screen.width < 767) {
|
if (screen.width < 767) {
|
||||||
console.log('screen.width', screen.width)
|
|
||||||
isMobile = true;
|
isMobile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@ import {
|
|||||||
mockClearStores,
|
mockClearStores,
|
||||||
mockOn,
|
mockOn,
|
||||||
mockOnce,
|
mockOnce,
|
||||||
mockSendTextMessage
|
mockSendTextMessage,
|
||||||
|
mockIsCryptoEnabled,
|
||||||
|
mockIsRoomEncrypted,
|
||||||
} from "matrix-js-sdk";
|
} from "matrix-js-sdk";
|
||||||
import { mount, shallow } from 'enzyme';
|
import { mount, shallow } from 'enzyme';
|
||||||
import { createWaitForElement } from 'enzyme-wait';
|
import { createWaitForElement } from 'enzyme-wait';
|
||||||
@ -53,6 +55,8 @@ describe('Chatbox', () => {
|
|||||||
mockOnce.mockClear()
|
mockOnce.mockClear()
|
||||||
mockOn.mockClear()
|
mockOn.mockClear()
|
||||||
mockSendTextMessage.mockClear()
|
mockSendTextMessage.mockClear()
|
||||||
|
mockIsCryptoEnabled.mockClear()
|
||||||
|
mockIsRoomEncrypted.mockClear()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('chat window should open and close', async () => {
|
test('chat window should open and close', async () => {
|
||||||
@ -113,9 +117,7 @@ describe('Chatbox', () => {
|
|||||||
expect(mockStartClient).toHaveBeenCalled()
|
expect(mockStartClient).toHaveBeenCalled()
|
||||||
expect(mockCreateRoom).toHaveBeenCalled()
|
expect(mockCreateRoom).toHaveBeenCalled()
|
||||||
expect(mockSetPowerLevel).toHaveBeenCalled()
|
expect(mockSetPowerLevel).toHaveBeenCalled()
|
||||||
expect(mockSetPowerLevel).toHaveBeenCalled()
|
|
||||||
expect(mockOn).toHaveBeenCalled()
|
expect(mockOn).toHaveBeenCalled()
|
||||||
expect(mockOnce).toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('rejecting terms should not start chat', async () => {
|
test('rejecting terms should not start chat', async () => {
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import EmbeddableChatbox from './embeddable-chatbox';
|
import EmbeddableChatbox from './embeddable-chatbox';
|
||||||
|
|
||||||
const config = {
|
var config = {
|
||||||
matrixServerUrl: 'https://matrix.rhok.space',
|
matrixServerUrl: 'https://matrix.rhok.space',
|
||||||
botId: '@help-bot:rhok.space',
|
botId: '@help-bot:rhok.space',
|
||||||
roomName: 'Support Chat',
|
roomName: 'Support Chat',
|
||||||
termsUrl: 'https://tosdr.org/',
|
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.',
|
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...',
|
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.',
|
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
||||||
anonymousDisplayName: 'Anonymous',
|
anonymousDisplayName: 'Anonymous',
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function bookmarklet() {
|
export default function bookmarklet() {
|
||||||
if (window.EmbeddableChatbox) {
|
if (window.EmbeddableChatbox) {
|
||||||
|
@ -2,13 +2,6 @@ import ReactDOM from 'react-dom';
|
|||||||
import bookmarklet from './bookmarklet';
|
import bookmarklet from './bookmarklet';
|
||||||
|
|
||||||
describe('bookmarklet', () => {
|
describe('bookmarklet', () => {
|
||||||
beforeAll(() => {
|
|
||||||
const el = document.querySelectorAll('body > div');
|
|
||||||
ReactDOM.unmountComponentAtNode(el[0]);
|
|
||||||
el[0].parentNode.removeChild(el[0]);
|
|
||||||
window.EmbeddableChatbox = null;
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
const el = document.querySelectorAll('body > div');
|
const el = document.querySelectorAll('body > div');
|
||||||
ReactDOM.unmountComponentAtNode(el[0]);
|
ReactDOM.unmountComponentAtNode(el[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user