Trying to fix timing/heisenbugs on Travis

This commit is contained in:
JC Brand 2017-08-09 14:07:46 +02:00
parent 5a67d985dc
commit eed936ff64
2 changed files with 45 additions and 44 deletions

View File

@ -409,21 +409,21 @@
expect(view.insertEmoji).toHaveBeenCalled();
test_utils.waitUntil(function () {
return !view.el.querySelector('.toggle-smiley .toolbar-menu').offsetHeight;
}, 300).then(function () {
$toolbar.children('li.toggle-smiley').click();
expect(view.toggleEmojiMenu).toHaveBeenCalled();
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
}, 300)
.then(function () {
$toolbar.children('li.toggle-smiley').click();
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();
expect(view.insertEmoji).toHaveBeenCalled();
done();
});
});
});
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();
expect(view.$el.find('textarea.chat-textarea').val()).toBe(':grinning: ');
expect(view.insertEmoji).toHaveBeenCalled();
done();
}); }); });
}));
it("contains a button for starting an encrypted chat session",
@ -744,23 +744,22 @@
});
it("will cause the chat area to be scrolled down only if it was at the bottom already",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.openContactsPanel(_converse);
var message = 'This message is received while the chat area is scrolled up';
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, sender_jid);
var chatboxview = _converse.chatboxviews.get(sender_jid);
spyOn(chatboxview, 'scrollDown').and.callThrough();
var $chat_content = chatboxview.$el.find('.chat-content');
/* Create enough messages so that there's a
* scrollbar.
*/
// Create enough messages so that there's a scrollbar.
var message = 'This message is received while the chat area is scrolled up';
for (var i=0; i<20; i++) {
_converse.chatboxes.onMessage($msg({
from: sender_jid,
@ -773,11 +772,11 @@
test_utils.waitUntil(function () {
return chatboxview.$content.scrollTop();
}, 300)
}, 500)
.then(function () {
return test_utils.waitUntil(function () {
return !chatboxview.model.get('auto_scrolled');
}, 300);
}, 500);
}).then(function () {
chatboxview.$content.scrollTop(0);
return test_utils.waitUntil(function () {
@ -798,7 +797,7 @@
expect(msg_txt).toEqual(message);
return test_utils.waitUntil(function () {
return chatboxview.$('.new-msgs-indicator').is(':visible');
}, 300);
}, 500);
}).then(function () {
expect(chatboxview.model.get('scrolled')).toBe(true);
expect(chatboxview.$content.scrollTop()).toBe(0);
@ -807,15 +806,14 @@
chatboxview.$content.scrollTop(chatboxview.$content[0].scrollHeight);
return test_utils.waitUntil(function () {
return !chatboxview.$('.new-msgs-indicator').is(':visible');
}, 300);
}, 500);
}).then(done);
}));
it("is ignored if it's intended for a different resource and filter_by_resource is set to true",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
@ -1461,7 +1459,7 @@
test_utils.waitUntil(function () {
return _converse.rosterview.$el.find('dt').length;
}, 300).then(function () {
}, 500).then(function () {
test_utils.openChatBoxFor(_converse, contact_jid);
var view = _converse.chatboxviews.get(contact_jid);
view.model.minimize();
@ -1470,7 +1468,7 @@
view.model.maximize();
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'active';
}, 300);
}, 500);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
@ -1491,9 +1489,9 @@
describe("A composing notification", function () {
it("is sent as soon as the user starts typing a message which is not a command",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
@ -1748,9 +1746,9 @@
describe("An inactive notifciation", function () {
it("is sent if the user has stopped typing since 2 minutes",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
var view, contact_jid;
test_utils.createContacts(_converse, 'current');
@ -1777,11 +1775,11 @@
return true;
}
return false;
}, 250);
}, 300);
}).then(function () {
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'inactive';
}, 250);
}, 300);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {

View File

@ -137,7 +137,7 @@
initialize () {
this.model.on('change:current_skintone', this.render, this);
this.model.on('change:current_category', this.render, this);
this.setScrollPosition = _.debounce(this.setScrollPosition, 50).bind(this);
this.setScrollPosition = _.debounce(this.setScrollPosition, 50);
},
render () {
@ -153,7 +153,7 @@
));
this.el.innerHTML = emojis_html;
_.forEach(this.el.querySelectorAll('.emoji-picker'), (el) => {
el.addEventListener('scroll', this.setScrollPosition);
el.addEventListener('scroll', this.setScrollPosition.bind(this));
});
this.restoreScrollPosition();
return this;
@ -234,6 +234,8 @@
},
initialize () {
this.markScrolled = _.debounce(this.markScrolled, 100);
this.createEmojiPicker();
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('show', this.show, this);
@ -955,7 +957,7 @@
}
},
markScrolled: _.debounce(function (ev) {
markScrolled: function (ev) {
/* Called when the chat content is scrolled up or down.
* We want to record when the user has scrolled away from
* the bottom, so that we don't automatically scroll away
@ -974,12 +976,13 @@
const is_at_bottom =
(this.$content.scrollTop() + this.$content.innerHeight()) >=
this.$content[0].scrollHeight-10;
if (is_at_bottom) {
scrolled = false;
this.onScrolledDown();
}
utils.safeSave(this.model, {'scrolled': scrolled});
}, 150),
},
viewUnreadMessages () {
this.model.save('scrolled', false);