Commit 53b3f2d0 authored by JC Brand's avatar JC Brand

Fix failing tests and rewrite to use async/await

parent 65190834
This diff is collapsed.
This diff is collapsed.
...@@ -2329,35 +2329,34 @@ ...@@ -2329,35 +2329,34 @@
})); }));
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy') await test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
.then(() => { const view = _converse.chatboxviews.get('lounge@localhost'),
const view = _converse.chatboxviews.get('lounge@localhost'), trimmed_chatboxes = _converse.minimized_chats;
trimmed_chatboxes = _converse.minimized_chats;
spyOn(view, 'minimize').and.callThrough(); spyOn(view, 'minimize').and.callThrough();
spyOn(view, 'maximize').and.callThrough(); spyOn(view, 'maximize').and.callThrough();
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
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
view.el.querySelector('.toggle-chatbox-button').click(); view.el.querySelector('.toggle-chatbox-button').click();
expect(view.minimize).toHaveBeenCalled(); expect(view.minimize).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object)); expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
expect(u.isVisible(view.el)).toBeFalsy(); expect(u.isVisible(view.el)).toBeFalsy();
expect(view.model.get('minimized')).toBeTruthy(); expect(view.model.get('minimized')).toBeTruthy();
expect(view.minimize).toHaveBeenCalled(); expect(view.minimize).toHaveBeenCalled();
var trimmedview = trimmed_chatboxes.get(view.model.get('id')); await test_utils.waitUntil(() => trimmed_chatboxes.get(view.model.get('id')));
trimmedview.el.querySelector("a.restore-chat").click(); const trimmedview = trimmed_chatboxes.get(view.model.get('id'));
expect(view.maximize).toHaveBeenCalled(); trimmedview.el.querySelector("a.restore-chat").click();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object)); expect(view.maximize).toHaveBeenCalled();
expect(view.model.get('minimized')).toBeFalsy(); expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
expect(_converse.emit.calls.count(), 3); expect(view.model.get('minimized')).toBeFalsy();
done(); expect(_converse.emit.calls.count(), 3);
done();
});
})); }));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", it("can be closed again by clicking a DOM element with class 'close-chatbox-button'",
......
This diff is collapsed.
...@@ -159,47 +159,50 @@ ...@@ -159,47 +159,50 @@
it("is played when the current user is mentioned in a chat room", it("is played when the current user is mentioned in a chat room",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () { await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
_converse.play_sounds = true; _converse.play_sounds = true;
spyOn(_converse, 'playSoundNotification'); spyOn(_converse, 'playSoundNotification');
var view = _converse.chatboxviews.get('lounge@localhost'); const view = _converse.chatboxviews.get('lounge@localhost');
if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); } if (!view.el.querySelectorAll('.chat-area').length) {
var text = 'This message will play a sound because it mentions dummy'; view.renderChatArea();
var message = $msg({ }
from: 'lounge@localhost/otheruser', let text = 'This message will play a sound because it mentions dummy';
id: '1', let message = $msg({
to: 'dummy@localhost', from: 'lounge@localhost/otheruser',
type: 'groupchat' id: '1',
}).c('body').t(text); to: 'dummy@localhost',
view.model.onMessage(message.nodeTree); type: 'groupchat'
expect(_converse.playSoundNotification).toHaveBeenCalled(); }).c('body').t(text);
view.model.onMessage(message.nodeTree);
text = "This message won't play a sound";
message = $msg({ await test_utils.waitUntil(() => _converse.playSoundNotification.calls.count());
from: 'lounge@localhost/otheruser', expect(_converse.playSoundNotification).toHaveBeenCalled();
id: '2',
to: 'dummy@localhost', text = "This message won't play a sound";
type: 'groupchat' message = $msg({
}).c('body').t(text); from: 'lounge@localhost/otheruser',
view.model.onMessage(message.nodeTree); id: '2',
expect(_converse.playSoundNotification, 1); to: 'dummy@localhost',
_converse.play_sounds = false; type: 'groupchat'
}).c('body').t(text);
text = "This message won't play a sound because it is sent by dummy"; view.model.onMessage(message.nodeTree);
message = $msg({ expect(_converse.playSoundNotification, 1);
from: 'lounge@localhost/dummy', _converse.play_sounds = false;
id: '3',
to: 'dummy@localhost', text = "This message won't play a sound because it is sent by dummy";
type: 'groupchat' message = $msg({
}).c('body').t(text); from: 'lounge@localhost/dummy',
view.model.onMessage(message.nodeTree); id: '3',
expect(_converse.playSoundNotification, 1); to: 'dummy@localhost',
_converse.play_sounds = false; type: 'groupchat'
done(); }).c('body').t(text);
}); view.model.onMessage(message.nodeTree);
expect(_converse.playSoundNotification, 1);
_converse.play_sounds = false;
done();
})); }));
}); });
}); });
......
...@@ -10,28 +10,21 @@ ...@@ -10,28 +10,21 @@
const u = converse.env.utils; const u = converse.env.utils;
const checkHeaderToggling = function (group) { const checkHeaderToggling = async function (group) {
var $group = $(group);
var toggle = group.querySelector('a.group-toggle'); var toggle = group.querySelector('a.group-toggle');
expect(u.isVisible($group[0])).toBeTruthy(); expect(u.isVisible(group)).toBeTruthy();
expect($group.find('ul.collapsed').length).toBe(0); expect(group.querySelectorAll('ul.collapsed').length).toBe(0);
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy(); expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy(); expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
toggle.click(); toggle.click();
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => group.querySelectorAll('ul.collapsed').length === 1);
return $group.find('ul.collapsed').length === 1; expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeTruthy();
}, 500).then(function () { expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeFalsy();
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeTruthy(); toggle.click();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeFalsy(); await test_utils.waitUntil(() => group.querySelectorAll('li').length === $(group).find('li:visible').length);
toggle.click(); expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
return test_utils.waitUntil(function () { expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
return $group.find('li').length === $group.find('li:visible').length
}, 500);
}).then(function () {
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
});
}; };
...@@ -501,7 +494,7 @@ ...@@ -501,7 +494,7 @@
it("remembers whether it is closed or opened", it("remembers whether it is closed or opened",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.roster_groups = true; _converse.roster_groups = true;
test_utils.openControlBox(); test_utils.openControlBox();
...@@ -524,20 +517,14 @@ ...@@ -524,20 +517,14 @@
}); });
} }
}); });
var view = _converse.rosterview.get('colleagues'); const view = _converse.rosterview.get('colleagues');
var $toggle = $(view.el).find('a.group-toggle'); const toggle = view.el.querySelector('a.group-toggle');
expect(view.model.get('state')).toBe('opened'); expect(view.model.get('state')).toBe('opened');
$toggle[0].click(); toggle.click();
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => view.model.get('state') === 'closed');
return view.model.get('state') === 'closed'; toggle.click();
}, 500).then(function () { await test_utils.waitUntil(() => view.model.get('state') === 'opened');
$toggle[0].click(); done();
return test_utils.waitUntil(function () {
return view.model.get('state') === 'opened';
}, 500)
}).then(function () {
done();
});
})); }));
}); });
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
spyOn(view, 'onMessageSubmitted').and.callThrough(); spyOn(view, 'onMessageSubmitted').and.callThrough();
spyOn(_converse.connection, 'send'); spyOn(_converse.connection, 'send');
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler'); let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
spoiler_toggle.click(); spoiler_toggle.click();
...@@ -178,6 +179,8 @@ ...@@ -178,6 +179,8 @@
await test_utils.openChatBoxFor(_converse, contact_jid); await test_utils.openChatBoxFor(_converse, contact_jid);
await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]); await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
const view = _converse.chatboxviews.get(contact_jid); const view = _converse.chatboxviews.get(contact_jid);
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler'); let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
spoiler_toggle.click(); spoiler_toggle.click();
......
...@@ -179,7 +179,6 @@ require.config(config); ...@@ -179,7 +179,6 @@ require.config(config);
var specs = [ var specs = [
"jasmine", "jasmine",
//"spec/transcripts", //"spec/transcripts",
//"spec/otr",
"spec/spoilers", "spec/spoilers",
"spec/profiling", "spec/profiling",
"spec/utils", "spec/utils",
......
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