Commit cf1e8f29 authored by JC Brand's avatar JC Brand

Fix failing test for emoji picker

parent 4ea50de9
...@@ -385,10 +385,6 @@ ...@@ -385,10 +385,6 @@
test_utils.openControlBox(); test_utils.openControlBox();
test_utils.openContactsPanel(_converse); test_utils.openContactsPanel(_converse);
test_utils.waitUntil(function () {
return _converse.rosterview.$el.find('dt').length;
}, 300)
.then(function () {
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost', var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost',
view, $toolbar, $textarea; view, $toolbar, $textarea;
test_utils.openChatBoxFor(_converse, contact_jid); test_utils.openChatBoxFor(_converse, contact_jid);
...@@ -398,24 +394,34 @@ ...@@ -398,24 +394,34 @@
expect($toolbar.children('li.toggle-smiley').length).toBe(1); expect($toolbar.children('li.toggle-smiley').length).toBe(1);
// Register spies // Register spies
spyOn(view, 'toggleEmojiMenu').and.callThrough(); spyOn(view, 'toggleEmojiMenu').and.callThrough();
spyOn(view, 'insertEmoji'); spyOn(view, 'insertEmoji').and.callThrough();
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
$toolbar.children('li.toggle-smiley').click(); $toolbar.children('li.toggle-smiley').click();
test_utils.waitUntil(function () {
var $picker = view.$el.find('.toggle-smiley .emoji-picker-container');
return $picker.is(':visible');
}, 300).then(function () {
var $picker = view.$el.find('.toggle-smiley .emoji-picker-container'); var $picker = view.$el.find('.toggle-smiley .emoji-picker-container');
// expect($picker.is(':visible')).toBeTruthy();
// expect(view.toggleEmojiMenu).toHaveBeenCalled();
var $items = $picker.find('.emoji-picker li'); var $items = $picker.find('.emoji-picker li');
$items.first().click(); $items.first().click();
expect(view.insertEmoji).toHaveBeenCalled(); expect(view.insertEmoji).toHaveBeenCalled();
expect(view.$el.find('.toggle-smiley ul').is(':visible')).toBeFalsy(); test_utils.waitUntil(function () {
return !view.el.querySelector('.toggle-smiley .toolbar-menu').offsetHeight;
}, 300).then(function () {
$toolbar.children('li.toggle-smiley').click(); $toolbar.children('li.toggle-smiley').click();
expect(view.toggleEmojiMenu).toHaveBeenCalled(); expect(view.toggleEmojiMenu).toHaveBeenCalled();
test_utils.waitUntil(function () {
var $picker = view.$el.find('.toggle-smiley .emoji-picker-container');
return $picker.is(':visible');
}, 300).then(function () {
view.$el.find('.toggle-smiley ul').children('li').last().click(); view.$el.find('.toggle-smiley ul').children('li').last().click();
expect(view.insertEmoji).toHaveBeenCalled(); expect(view.insertEmoji).toHaveBeenCalled();
expect(view.$el.find('.toggle-smiley ul').is(':visible')).toBeFalsy();
done(); done();
}); });
});
});
})); }));
it("contains a button for starting an encrypted chat session", it("contains a button for starting an encrypted chat session",
......
...@@ -55,7 +55,11 @@ ...@@ -55,7 +55,11 @@
registerGlobalEventHandlers: function () { registerGlobalEventHandlers: function () {
this.__super__.registerGlobalEventHandlers(); this.__super__.registerGlobalEventHandlers();
document.addEventListener( document.addEventListener(
'click', function () { 'click', function (ev) {
if (_.includes(ev.target.classList, 'toggle-toolbar-menu') ||
_.includes(ev.target.classList, 'insert-emoji')) {
return;
}
utils.slideInAllElements( utils.slideInAllElements(
document.querySelectorAll('.toolbar-menu') document.querySelectorAll('.toolbar-menu')
) )
......
{[ _.forEach(emojis_by_category, function (obj, category) { ]} {[ _.forEach(emojis_by_category, function (obj, category) { ]}
<ul class="emoji-picker emoji-picker-{{{category}}} {[ if (current_category !== category) { ]} hidden {[ } ]}"> <ul class="emoji-picker emoji-picker-{{{category}}} {[ if (current_category !== category) { ]} hidden {[ } ]}">
{[ _.forEach(emojis_by_category[category], function (emoji) { ]} {[ _.forEach(emojis_by_category[category], function (emoji) { ]}
<li class="emoji" data-emoji="{{{emoji._shortname}}}"> <li class="emoji insert-emoji" data-emoji="{{{emoji._shortname}}}">
<a href="#" data-emoji="{{{emoji._shortname}}}"> {{ emojione.shortnameToUnicode(emoji._shortname) }} </a> <a href="#" data-emoji="{{{emoji._shortname}}}"> {{ emojione.shortnameToUnicode(emoji._shortname) }} </a>
</li> </li>
{[ }); ]} {[ }); ]}
......
...@@ -208,17 +208,25 @@ ...@@ -208,17 +208,25 @@
const err = "Undefined or null element passed into slideOut" const err = "Undefined or null element passed into slideOut"
console.warn(err); console.warn(err);
reject(new Error(err)); reject(new Error(err));
return;
} }
let interval_marker = el.getAttribute('data-slider-marker'); let interval_marker = el.getAttribute('data-slider-marker');
if (interval_marker) { if (interval_marker) {
el.removeAttribute('data-slider-marker');
window.clearInterval(interval_marker); window.clearInterval(interval_marker);
} }
const end_height = _.reduce(el.children, function (result, child) { const end_height = _.reduce(
return result + child.offsetHeight; el.children,
}, 0); (result, child) => result + child.offsetHeight, 0
);
if ($.fx.off) { // Effects are disabled (for tests)
el.style.height = end_height + 'px';
resolve();
return;
}
const step = calculateSlideStep(end_height), const step = calculateSlideStep(end_height),
interval = end_height/duration*step; interval = end_height/duration*step;
let h = 0; let h = 0;
interval_marker = window.setInterval(function () { interval_marker = window.setInterval(function () {
h += step; h += step;
...@@ -227,7 +235,6 @@ ...@@ -227,7 +235,6 @@
} else { } else {
el.style.height = end_height + 'px'; el.style.height = end_height + 'px';
window.clearInterval(interval_marker); window.clearInterval(interval_marker);
el.style.overflow = '';
el.removeAttribute('data-slider-marker'); el.removeAttribute('data-slider-marker');
resolve(); resolve();
} }
...@@ -242,14 +249,16 @@ ...@@ -242,14 +249,16 @@
if (_.isNil(el)) { if (_.isNil(el)) {
const err = "Undefined or null element passed into slideIn"; const err = "Undefined or null element passed into slideIn";
console.warn(err); console.warn(err);
reject(new Error(err)); return reject(new Error(err));
} } else if (!el.offsetHeight) {
if (!el.offsetHeight) { return resolve();
resolve(); } else if ($.fx.off) { // Effects are disabled (for tests)
return; el.style.height = 0 + 'px';
return resolve();
} }
let interval_marker = el.getAttribute('data-slider-marker'); let interval_marker = el.getAttribute('data-slider-marker');
if (interval_marker) { if (interval_marker) {
el.removeAttribute('data-slider-marker');
window.clearInterval(interval_marker); window.clearInterval(interval_marker);
} }
let h = el.offsetHeight; let h = el.offsetHeight;
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
}); });
} }
var converse = converse_api.initialize(_.extend({ var _converse = converse_api.initialize(_.extend({
'i18n': 'en', 'i18n': 'en',
'auto_subscribe': false, 'auto_subscribe': false,
'play_sounds': false, 'play_sounds': false,
...@@ -101,9 +101,10 @@ ...@@ -101,9 +101,10 @@
'password': 'secret', 'password': 'secret',
'debug': false 'debug': false
}, settings || {})); }, settings || {}));
converse.ChatBoxViews.prototype.trimChat = function () {}; _converse.ChatBoxViews.prototype.trimChat = function () {};
_converse.disable_effects = true;
$.fx.off = true; $.fx.off = true;
return converse; return _converse;
} }
mock.initConverseWithPromises = function (spies, promise_names, settings, func) { mock.initConverseWithPromises = function (spies, promise_names, settings, func) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment