added test suite for chatbox, use accept/reject buttons for ToS instead of typing answer

This commit is contained in:
Sharon Kennedy
2020-03-12 13:08:57 -04:00
parent 1c96d11443
commit a97696f687
11 changed files with 324 additions and 262 deletions

View File

@@ -6,12 +6,20 @@ export default function bookmarklet() {
}
window.EmbeddableChatbox = EmbeddableChatbox;
EmbeddableChatbox.mount({
termsUrl: 'https://tosdr.org/',
privacyStatement: 'This chat application does not collect any of your personal data or any data from your use of this service.',
var config = {
matrixServerUrl: 'https://matrix.rhok.space',
botUsername: '@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.',
confirmationMessage: 'Waiting for a facilitator to join the chat...',
exitMessage: 'The chat was not started.',
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
anonymousDisplayName: 'Anonymous',
}
EmbeddableChatbox.mount(config);
}
bookmarklet();

View File

@@ -6,11 +6,11 @@ describe('bookmarklet', () => {
const el = document.querySelectorAll('body > div');
ReactDOM.unmountComponentAtNode(el[0]);
el[0].parentNode.removeChild(el[0]);
window.EmbeddableWidget = null;
window.EmbeddableChatbox = null;
});
test('#mount document becomes ready', async () => {
expect(window.EmbeddableWidget).not.toBeNull();
expect(window.EmbeddableChatbox).not.toBeNull();
bookmarklet();
const el = document.querySelectorAll('body > div');
expect(el).toHaveLength(1);

View File

@@ -1,23 +1,24 @@
import EmbeddableWidget from './embeddable-widget';
import EmbeddableChatbox from './embeddable-chatbox';
import { waitForSelection } from '../test-helpers';
describe('EmbeddableWidget', () => {
describe('EmbeddableChatbox', () => {
afterEach(() => {
document.readyState = 'complete';
if (EmbeddableWidget.el) {
EmbeddableWidget.unmount();
if (EmbeddableChatbox.el) {
EmbeddableChatbox.unmount();
}
});
test('#mount document becomes ready', async () => {
document.readyState = 'loading';
EmbeddableWidget.mount();
EmbeddableChatbox.mount();
window.dispatchEvent(new Event('load', {}));
await waitForSelection(document, 'div');
});
test('#mount document complete', async () => {
EmbeddableWidget.mount();
EmbeddableChatbox.mount();
await waitForSelection(document, 'div');
});
@@ -26,7 +27,7 @@ describe('EmbeddableWidget', () => {
newElement.setAttribute('id', 'widget-mount');
document.body.appendChild(newElement);
EmbeddableWidget.mount({
EmbeddableChatbox.mount({
parentElement: '#widget-mount',
});
@@ -36,8 +37,8 @@ describe('EmbeddableWidget', () => {
});
test('#mount twice', async () => {
EmbeddableWidget.mount();
expect(() => EmbeddableWidget.mount()).toThrow('already mounted');
EmbeddableChatbox.mount();
expect(() => EmbeddableChatbox.mount()).toThrow('already mounted');
});
test('#unmount', async () => {
@@ -45,13 +46,13 @@ describe('EmbeddableWidget', () => {
document.body.appendChild(el);
expect(document.querySelectorAll('div')).toHaveLength(1);
EmbeddableWidget.el = el;
EmbeddableWidget.unmount();
EmbeddableChatbox.el = el;
EmbeddableChatbox.unmount();
expect(document.querySelectorAll('div')).toHaveLength(0);
});
test('#unmount without mounting', async () => {
expect(() => EmbeddableWidget.unmount()).toThrow('not mounted');
expect(() => EmbeddableChatbox.unmount()).toThrow('not mounted');
});
});