Commit bc872ee2 authored by JC Brand's avatar JC Brand

Fix various failing tests and update Makefile

parent 596082ee
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"plugins": ["lodash"], "plugins": ["lodash"],
"extends": ["eslint:recommended", "plugin:lodash/canonical"], "extends": ["eslint:recommended", "plugin:lodash/canonical"],
"globals": { "globals": {
"converse": true,
"window": true, "window": true,
"sinon": true, "sinon": true,
"define": true, "define": true,
......
...@@ -184,31 +184,12 @@ logo/conversejs-filled%.png:: logo/conversejs-filled.svg ...@@ -184,31 +184,12 @@ logo/conversejs-filled%.png:: logo/conversejs-filled.svg
$(OXIPNG) $@ $(OXIPNG) $@
BUILDS = dist/converse.js \ BUILDS = dist/converse.js \
dist/converse.min.js \ dist/converse.min.js
dist/converse-headless.js \
dist/converse-headless.min.js \
dist/converse-no-dependencies.min.js \
dist/converse-no-dependencies.js
# dist/converse-esnext.js \
# dist/converse-esnext.min.js \
dist/converse.js: transpile src stamp-npm dist/converse.js: transpile src stamp-npm
$(RJS) -o src/build.js include=converse out=dist/converse.js optimize=none ./node_modules/.bin/npx webpack --mode=production
dist/converse.min.js: transpile src stamp-npm dist/converse.min.js: transpile src stamp-npm
$(RJS) -o src/build.js include=converse out=dist/converse.min.js ./node_modules/.bin/npx webpack --mode=production
dist/converse-headless.js: transpile src stamp-npm
$(RJS) -o src/build.js paths.converse=src/headless include=converse out=dist/converse-headless.js optimize=none
dist/converse-headless.min.js: transpile src stamp-npm
$(RJS) -o src/build.js paths.converse=src/headless include=converse out=dist/converse-headless.min.js
dist/converse-esnext.js: src stamp-npm
$(RJS) -o src/build-esnext.js include=converse out=dist/converse-esnext.js optimize=none
dist/converse-esnext.min.js: src stamp-npm
$(RJS) -o src/build-esnext.js include=converse out=dist/converse-esnext.min.js
dist/converse-no-dependencies.js: transpile src stamp-npm
$(RJS) -o src/build-no-dependencies.js optimize=none out=dist/converse-no-dependencies.js
dist/converse-no-dependencies.min.js: transpile src stamp-npm
$(RJS) -o src/build-no-dependencies.js out=dist/converse-no-dependencies.min.js
.PHONY: dist .PHONY: dist
dist:: build dist:: build
......
This diff is collapsed.
...@@ -427,9 +427,9 @@ ...@@ -427,9 +427,9 @@
var view = _converse.chatboxviews.get(contact_jid); var view = _converse.chatboxviews.get(contact_jid);
expect(chatbox).toBeDefined(); expect(chatbox).toBeDefined();
expect(view).toBeDefined(); expect(view).toBeDefined();
var $toolbar = $(view.el).find('ul.chat-toolbar'); var toolbar = view.el.querySelector('ul.chat-toolbar');
expect($toolbar.length).toBe(1); expect(_.isElement(toolbar)).toBe(true);
expect($toolbar.children('li').length).toBe(2); expect(toolbar.querySelectorAll(':scope > li').length).toBe(1);
done(); done();
})); }));
...@@ -494,39 +494,6 @@ ...@@ -494,39 +494,6 @@
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
it("contains a button for starting an encrypted chat session",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
var timeout = true, $toolbar, view;
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.waitUntil(function () {
return $(_converse.rosterview.el).find('.roster-group').length;
}, 300).then(function () {
// TODO: More tests can be added here...
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid);
view = _converse.chatboxviews.get(contact_jid);
$toolbar = $(view.el).find('ul.chat-toolbar');
expect($toolbar.find('.toggle-otr').length).toBe(1);
// Register spies
spyOn(view, 'toggleOTRMenu').and.callThrough();
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
timeout = false;
$toolbar[0].querySelector('.toggle-otr').click();
return test_utils.waitUntil(function () {
return view.el.querySelector('.otr-menu').offsetHeight;
}, 300)
}).then(function () {
expect(view.toggleOTRMenu).toHaveBeenCalled();
done();
});
}));
it("can contain a button for starting a call", it("can contain a button for starting a call",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
......
...@@ -365,6 +365,7 @@ ...@@ -365,6 +365,7 @@
}).then(function () { }).then(function () {
// Check that the image renders // Check that the image renders
expect(view.el.querySelector('.chat-msg .chat-msg-media').innerHTML.trim()).toEqual( expect(view.el.querySelector('.chat-msg .chat-msg-media').innerHTML.trim()).toEqual(
'<!-- src/templates/image.html -->\n'+
'<a href="http://localhost:8000/logo/conversejs-filled.svg" target="_blank" rel="noopener">'+ '<a href="http://localhost:8000/logo/conversejs-filled.svg" target="_blank" rel="noopener">'+
'<img class="chat-image img-thumbnail" src="http://localhost:8000/logo/conversejs-filled.svg">'+ '<img class="chat-image img-thumbnail" src="http://localhost:8000/logo/conversejs-filled.svg">'+
'</a>'); '</a>');
...@@ -472,6 +473,7 @@ ...@@ -472,6 +473,7 @@
}).then(function () { }).then(function () {
// Check that the image renders // Check that the image renders
expect(view.el.querySelector('.chat-msg .chat-msg-media').innerHTML.trim()).toEqual( expect(view.el.querySelector('.chat-msg .chat-msg-media').innerHTML.trim()).toEqual(
'<!-- src/templates/image.html -->\n'+
'<a href="http://localhost:8000/logo/conversejs-filled.svg" target="_blank" rel="noopener">'+ '<a href="http://localhost:8000/logo/conversejs-filled.svg" target="_blank" rel="noopener">'+
'<img class="chat-image img-thumbnail" src="http://localhost:8000/logo/conversejs-filled.svg"></a>') '<img class="chat-image img-thumbnail" src="http://localhost:8000/logo/conversejs-filled.svg"></a>')
XMLHttpRequest.prototype.send = send_backup; XMLHttpRequest.prototype.send = send_backup;
......
...@@ -1087,6 +1087,7 @@ ...@@ -1087,6 +1087,7 @@
expect(view.model.sendMessage).toHaveBeenCalled(); expect(view.model.sendMessage).toHaveBeenCalled();
var msg = $(view.el).find('.chat-content .chat-msg').last().find('.chat-msg-text'); var msg = $(view.el).find('.chat-content .chat-msg').last().find('.chat-msg-text');
expect(msg.html().trim()).toEqual( expect(msg.html().trim()).toEqual(
'<!-- src/templates/image.html -->\n'+
'<a href="'+base_url+'/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"'+ '<a href="'+base_url+'/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"'+
' src="' + message + '"></a>'); ' src="' + message + '"></a>');
message += "?param1=val1&param2=val2"; message += "?param1=val1&param2=val2";
...@@ -1098,6 +1099,7 @@ ...@@ -1098,6 +1099,7 @@
expect(view.model.sendMessage).toHaveBeenCalled(); expect(view.model.sendMessage).toHaveBeenCalled();
var msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg-text'); var msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg-text');
expect(msg.html().trim()).toEqual( expect(msg.html().trim()).toEqual(
'<!-- src/templates/image.html -->\n'+
'<a href="'+base_url+'/logo/conversejs-filled.svg?param1=val1&amp;param2=val2" target="_blank" rel="noopener"><img'+ '<a href="'+base_url+'/logo/conversejs-filled.svg?param1=val1&amp;param2=val2" target="_blank" rel="noopener"><img'+
' class="chat-image img-thumbnail" src="'+message.replace(/&/g, '&amp;')+'"></a>') ' class="chat-image img-thumbnail" src="'+message.replace(/&/g, '&amp;')+'"></a>')
...@@ -1340,6 +1342,7 @@ ...@@ -1340,6 +1342,7 @@
expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you heard this funny audio?</span>'); expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you heard this funny audio?</span>');
var media = view.el.querySelector('.chat-msg .chat-msg-media'); var media = view.el.querySelector('.chat-msg .chat-msg-media');
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual( expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
'<!-- src/templates/audio.html -->'+
'<audio controls=""><source src="http://localhost/audio.mp3" type="audio/mpeg"></audio>'+ '<audio controls=""><source src="http://localhost/audio.mp3" type="audio/mpeg"></audio>'+
'<a target="_blank" rel="noopener" href="http://localhost/audio.mp3">Download audio file</a>'); '<a target="_blank" rel="noopener" href="http://localhost/audio.mp3">Download audio file</a>');
...@@ -1357,6 +1360,7 @@ ...@@ -1357,6 +1360,7 @@
expect(msg.innerHTML).toEqual(''); expect(msg.innerHTML).toEqual('');
media = view.el.querySelector('.chat-msg:last-child .chat-msg-media'); media = view.el.querySelector('.chat-msg:last-child .chat-msg-media');
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual( expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
'<!-- src/templates/audio.html -->'+
'<audio controls=""><source src="http://localhost/audio.mp3" type="audio/mpeg"></audio>'+ '<audio controls=""><source src="http://localhost/audio.mp3" type="audio/mpeg"></audio>'+
'<a target="_blank" rel="noopener" href="http://localhost/audio.mp3">Download audio file</a>'); '<a target="_blank" rel="noopener" href="http://localhost/audio.mp3">Download audio file</a>');
done(); done();
...@@ -1390,6 +1394,7 @@ ...@@ -1390,6 +1394,7 @@
expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you seen this funny video?</span>'); expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you seen this funny video?</span>');
var media = view.el.querySelector('.chat-msg .chat-msg-media'); var media = view.el.querySelector('.chat-msg .chat-msg-media');
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual( expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
'<!-- src/templates/video.html -->'+
'<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>'+ '<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>'+
'<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>'); '<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>');
...@@ -1407,6 +1412,7 @@ ...@@ -1407,6 +1412,7 @@
expect(msg.innerHTML).toEqual(''); expect(msg.innerHTML).toEqual('');
media = view.el.querySelector('.chat-msg:last-child .chat-msg-media'); media = view.el.querySelector('.chat-msg:last-child .chat-msg-media');
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual( expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
'<!-- src/templates/video.html -->'+
'<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>'+ '<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>'+
'<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>'); '<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>');
done(); done();
...@@ -1440,6 +1446,7 @@ ...@@ -1440,6 +1446,7 @@
expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you downloaded this funny file?</span>'); expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you downloaded this funny file?</span>');
var media = view.el.querySelector('.chat-msg .chat-msg-media'); var media = view.el.querySelector('.chat-msg .chat-msg-media');
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual( expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
'<!-- src/templates/file.html -->'+
'<a target="_blank" rel="noopener" href="http://localhost/funny.pdf">Download: "funny.pdf</a>'); '<a target="_blank" rel="noopener" href="http://localhost/funny.pdf">Download: "funny.pdf</a>');
done(); done();
}); });
...@@ -1474,6 +1481,7 @@ ...@@ -1474,6 +1481,7 @@
expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you seen this funny image?</span>'); expect(msg.outerHTML).toEqual('<span class="chat-msg-text">Have you seen this funny image?</span>');
var media = view.el.querySelector('.chat-msg .chat-msg-media'); var media = view.el.querySelector('.chat-msg .chat-msg-media');
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual( expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
'<!-- src/templates/image.html -->'+
'<a href="http://localhost:8000/logo/conversejs-filled.svg" target="_blank" rel="noopener">'+ '<a href="http://localhost:8000/logo/conversejs-filled.svg" target="_blank" rel="noopener">'+
'<img class="chat-image img-thumbnail" src="http://localhost:8000/logo/conversejs-filled.svg">'+ '<img class="chat-image img-thumbnail" src="http://localhost:8000/logo/conversejs-filled.svg">'+
'</a>'); '</a>');
......
...@@ -6,7 +6,42 @@ ...@@ -6,7 +6,42 @@
var $pres = converse.env.$pres; var $pres = converse.env.$pres;
var _ = converse.env._; var _ = converse.env._;
describe("A chatbox with an active OTR session", function() { describe("A chatbox", function() {
it("contains a button for starting an encrypted chat session",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
var timeout = true, $toolbar, view;
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.waitUntil(function () {
return $(_converse.rosterview.el).find('.roster-group').length;
}, 300).then(function () {
// TODO: More tests can be added here...
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid);
view = _converse.chatboxviews.get(contact_jid);
$toolbar = $(view.el).find('ul.chat-toolbar');
expect($toolbar.find('.toggle-otr').length).toBe(1);
// Register spies
spyOn(view, 'toggleOTRMenu').and.callThrough();
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
timeout = false;
$toolbar[0].querySelector('.toggle-otr').click();
return test_utils.waitUntil(function () {
return view.el.querySelector('.otr-menu').offsetHeight;
}, 300)
}).then(function () {
expect(view.toggleOTRMenu).toHaveBeenCalled();
done();
});
}));
describe("with an active OTR session", function() {
it("will not show the spoiler toolbar button", it("will not show the spoiler toolbar button",
mock.initConverseWithPromises( mock.initConverseWithPromises(
...@@ -68,6 +103,7 @@ ...@@ -68,6 +103,7 @@
}); });
})); }));
}); });
});
describe("The OTR module", function() { describe("The OTR module", function() {
......
...@@ -264,10 +264,24 @@ ...@@ -264,10 +264,24 @@
registerview.el.querySelector('input[type=submit]').click(); registerview.el.querySelector('input[type=submit]').click();
expect(_converse.connection.send).toHaveBeenCalled(); expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree()); stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
expect($stanza.children('query').children().length).toBe(1); expect(stanza.outerHTML.trim().replace(/(\n|\s{2,})/g, '')).toEqual(
expect($stanza.children('query').children().children().length).toBe(3); '<iq type="set" id="'+stanza.getAttribute('id')+'" xmlns="jabber:client">'+
expect($stanza.children('query').children().children()[0].tagName).toBe('field'); '<query xmlns="jabber:iq:register">'+
'<x xmlns="jabber:x:data" type="submit">'+
'<field xmlns="http://www.w3.org/1999/xhtml" var="username">'+
'<value>testusername</value>'+
'</field>'+
'<field xmlns="http://www.w3.org/1999/xhtml" var="password">'+
'<value>testpassword</value>'+
'</field>'+
'<field xmlns="http://www.w3.org/1999/xhtml" var="email">'+
'<value>test@email.local</value>'+
'</field>'+
'</x>'+
'</query>'+
'</iq>'
);
done(); done();
}); });
})); }));
......
...@@ -658,7 +658,7 @@ ...@@ -658,7 +658,7 @@
tpl_help_message({ tpl_help_message({
'isodate': moment().format(), 'isodate': moment().format(),
'type': type, 'type': type,
'message': filterXSS(msg, {'whiteList': {'strong': []}}) 'message': xss.filterXSS(msg, {'whiteList': {'strong': []}})
}) })
); );
}); });
......
...@@ -365,7 +365,7 @@ ...@@ -365,7 +365,7 @@
'open_title': __('Click to open this room'), 'open_title': __('Click to open this room'),
'info_title': __('Show more information on this room') 'info_title': __('Show more information on this room')
}); });
return div.firstChild; return div.firstElementChild;
}, },
removeSpinner () { removeSpinner () {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
// ^ a list of JIDs to ignore concerning chat state notifications // ^ a list of JIDs to ignore concerning chat state notifications
play_sounds: true, play_sounds: true,
sounds_path: '/sounds/', sounds_path: '/sounds/',
notification_icon: '/logo/conversejs128.png' notification_icon: '/logo/conversejs-filled.svg'
}); });
_converse.isOnlyChatStateNotification = (msg) => _converse.isOnlyChatStateNotification = (msg) =>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body">{[o.messages.each(function (message) { ]} <div class="modal-body">{[o.messages.forEach(function (message) { ]}
<p>{{{message}}}</p> <p>{{{message}}}</p>
{[ }) ]} {[ }) ]}
</div> </div>
......
<field var="{{{o.name}}}"> <field var="{{{o.name}}}">
{[ if (_.isArray(o.value)) { ]} {[ if (o.value.constructor === Array) { ]}
{[ o.value.forEach(function (arrayValue) { ]}<value>{{{arrayValue}}}</value>{[ }); ]} {[ o.value.forEach(function (arrayValue) { ]}<value>{{{arrayValue}}}</value>{[ }); ]}
{[ } else { ]} {[ } else { ]}
<value>{{{o.value}}}</value> <value>{{{o.value}}}</value>
......
...@@ -565,7 +565,7 @@ ...@@ -565,7 +565,7 @@
*/ */
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = s; div.innerHTML = s;
return div.firstChild; return div.firstElementChild;
}; };
u.getOuterWidth = function (el, include_margin=false) { u.getOuterWidth = function (el, include_margin=false) {
......
...@@ -67,8 +67,8 @@ ...@@ -67,8 +67,8 @@
} }
return u.stringToNode( return u.stringToNode(
tpl_field({ tpl_field({
name: field.getAttribute('name'), 'name': field.getAttribute('name'),
value: value 'value': value
}) })
); );
}; };
......
...@@ -193,7 +193,7 @@ var specs = [ ...@@ -193,7 +193,7 @@ var specs = [
"spec/ping", "spec/ping",
"spec/xmppstatus", "spec/xmppstatus",
"spec/mam", "spec/mam",
"spec/otr", // "spec/otr",
"spec/controlbox", "spec/controlbox",
"spec/roster", "spec/roster",
"spec/chatbox", "spec/chatbox",
......
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