177 lines
9.4 KiB
JavaScript
177 lines
9.4 KiB
JavaScript
(function (root, factory) {
|
|
define([
|
|
"jasmine",
|
|
"mock",
|
|
"test-utils"
|
|
], factory);
|
|
} (this, function (jasmine, mock, test_utils) {
|
|
"use strict";
|
|
const { Backbone, Promise, Strophe, $iq, $msg, $pres, b64_sha1, dayjs, sizzle, _ } = converse.env;
|
|
const u = converse.env.utils;
|
|
|
|
describe("Emojis", function () {
|
|
describe("The emoji picker", function () {
|
|
|
|
it("can be opened by clicking a button in the chat toolbar",
|
|
mock.initConverse(
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
async function (done, _converse) {
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
|
test_utils.openControlBox();
|
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
const toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
expect(toolbar.querySelectorAll('li.toggle-smiley').length).toBe(1);
|
|
spyOn(view, 'toggleEmojiMenu').and.callThrough();
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
toolbar.querySelector('li.toggle-smiley').click();
|
|
|
|
await u.waitUntil(() => u.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker__container')));
|
|
const picker = await u.waitUntil(() => view.el.querySelector('.toggle-smiley .emoji-picker__container'));
|
|
const item = await u.waitUntil(() => picker.querySelector('.emoji-picker li.insert-emoji'));
|
|
item.click()
|
|
expect(view.el.querySelector('textarea.chat-textarea').value).toBe(':grinning: ');
|
|
toolbar.querySelector('li.toggle-smiley').click(); // Close the panel again
|
|
done();
|
|
}));
|
|
|
|
it("is opened to autocomplete emojis in the textarea",
|
|
mock.initConverse(
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
async function (done, _converse) {
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
const view = _converse.chatboxviews.get(muc_jid);
|
|
const textarea = view.el.querySelector('textarea.chat-textarea');
|
|
textarea.value = ':gri';
|
|
|
|
// Press tab
|
|
const tab_event = {
|
|
'target': textarea,
|
|
'preventDefault': function preventDefault () {},
|
|
'stopPropagation': function stopPropagation () {},
|
|
'keyCode': 9,
|
|
'key': 'Tab'
|
|
}
|
|
view.onKeyDown(tab_event);
|
|
await u.waitUntil(() => u.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker__container')));
|
|
const picker = await u.waitUntil(() => view.el.querySelector('.toggle-smiley .emoji-picker__container'));
|
|
const input = picker.querySelector('.emoji-search');
|
|
expect(input.value).toBe(':gri');
|
|
let visible_emojis = sizzle('.insert-emoji:not(.hidden)', picker);
|
|
expect(visible_emojis.length).toBe(3);
|
|
expect(visible_emojis[0].getAttribute('data-emoji')).toBe(':grimacing:');
|
|
expect(visible_emojis[1].getAttribute('data-emoji')).toBe(':grin:');
|
|
expect(visible_emojis[2].getAttribute('data-emoji')).toBe(':grinning:');
|
|
|
|
// Test that TAB autocompletes the to first match
|
|
view.emoji_picker_view.onKeyDown(tab_event);
|
|
visible_emojis = sizzle('.insert-emoji:not(.hidden)', picker);
|
|
expect(visible_emojis.length).toBe(1);
|
|
expect(visible_emojis[0].getAttribute('data-emoji')).toBe(':grimacing:');
|
|
expect(input.value).toBe(':grimacing:');
|
|
|
|
// Check that ENTER now inserts the match
|
|
const enter_event = Object.assign({}, tab_event, {'keyCode': 13, 'key': 'Enter', 'target': input});
|
|
view.emoji_picker_view.onKeyDown(enter_event);
|
|
expect(input.value).toBe('');
|
|
expect(textarea.value).toBe(':grimacing: ');
|
|
done();
|
|
}));
|
|
|
|
|
|
it("allows you to search for particular emojis",
|
|
mock.initConverse(
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
async function (done, _converse) {
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
const view = _converse.chatboxviews.get(muc_jid);
|
|
const toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
expect(toolbar.querySelectorAll('li.toggle-smiley').length).toBe(1);
|
|
toolbar.querySelector('li.toggle-smiley').click();
|
|
await u.waitUntil(() => u.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker__container')));
|
|
const picker = await u.waitUntil(() => view.el.querySelector('.toggle-smiley .emoji-picker__container'));
|
|
const input = picker.querySelector('.emoji-search');
|
|
expect(sizzle('.insert-emoji:not(.hidden)', picker).length).toBe(1420);
|
|
|
|
expect(view.emoji_picker_view.model.get('query')).toBeUndefined();
|
|
input.value = 'smiley';
|
|
const event = {
|
|
'target': input,
|
|
'preventDefault': function preventDefault () {},
|
|
'stopPropagation': function stopPropagation () {}
|
|
};
|
|
view.emoji_picker_view.onKeyDown(event);
|
|
await u.waitUntil(() => view.emoji_picker_view.model.get('query') === 'smiley');
|
|
let visible_emojis = sizzle('.insert-emoji:not(.hidden)', picker);
|
|
expect(visible_emojis.length).toBe(2);
|
|
expect(visible_emojis[0].getAttribute('data-emoji')).toBe(':smiley:');
|
|
expect(visible_emojis[1].getAttribute('data-emoji')).toBe(':smiley_cat:');
|
|
|
|
// Check that pressing enter without an unambiguous match does nothing
|
|
const enter_event = Object.assign({}, event, {'keyCode': 13});
|
|
view.emoji_picker_view.onKeyDown(enter_event);
|
|
expect(input.value).toBe('smiley');
|
|
|
|
// Test that TAB autocompletes the to first match
|
|
const tab_event = Object.assign({}, event, {'keyCode': 9, 'key': 'Tab'});
|
|
view.emoji_picker_view.onKeyDown(tab_event);
|
|
expect(input.value).toBe(':smiley:');
|
|
visible_emojis = sizzle('.insert-emoji:not(.hidden)', picker);
|
|
expect(visible_emojis.length).toBe(1);
|
|
expect(visible_emojis[0].getAttribute('data-emoji')).toBe(':smiley:');
|
|
|
|
// Check that ENTER now inserts the match
|
|
view.emoji_picker_view.onKeyDown(enter_event);
|
|
expect(input.value).toBe('');
|
|
expect(view.el.querySelector('textarea.chat-textarea').value).toBe(':smiley: ');
|
|
done();
|
|
}));
|
|
});
|
|
|
|
describe("A Chat Message", function () {
|
|
it("will display larger if it's a single emoji",
|
|
mock.initConverse(
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {'use_system_emojis': false},
|
|
async function (done, _converse) {
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
_converse.chatboxes.onMessage($msg({
|
|
'from': sender_jid,
|
|
'to': _converse.connection.jid,
|
|
'type': 'chat',
|
|
'id': _converse.connection.getUniqueId()
|
|
}).c('body').t('😇').up()
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
await new Promise(resolve => _converse.on('chatBoxInitialized', resolve));
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
|
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
let message = chat_content.querySelector('.chat-msg__text');
|
|
expect(u.hasClass('chat-msg__text--larger', message)).toBe(true);
|
|
|
|
_converse.chatboxes.onMessage($msg({
|
|
'from': sender_jid,
|
|
'to': _converse.connection.jid,
|
|
'type': 'chat',
|
|
'id': _converse.connection.getUniqueId()
|
|
}).c('body').t('😇 Hello world! 😇 😇').up()
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
|
message = chat_content.querySelector('.message:last-child .chat-msg__text');
|
|
expect(u.hasClass('chat-msg__text--larger', message)).toBe(false);
|
|
done();
|
|
}));
|
|
});
|
|
});
|
|
}));
|