2018-03-28 18:38:22 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"jasmine",
|
|
|
|
"mock",
|
|
|
|
"test-utils"], factory);
|
2018-06-03 16:40:20 +02:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-03-28 18:38:22 +02:00
|
|
|
"use strict";
|
2019-02-12 14:21:45 +01:00
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const $iq = converse.env.$iq;
|
|
|
|
const _ = converse.env._;
|
2019-05-19 22:11:26 +02:00
|
|
|
const sizzle = converse.env.sizzle;
|
2019-02-12 14:21:45 +01:00
|
|
|
const u = converse.env.utils;
|
2018-03-28 18:38:22 +02:00
|
|
|
|
|
|
|
describe("XEP-0363: HTTP File Upload", function () {
|
|
|
|
|
|
|
|
describe("Discovering support", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is done automatically", mock.initConverse(async (done, _converse) => {
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const IQ_ids = _converse.connection.IQ_ids;
|
2018-10-26 10:15:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []);
|
|
|
|
await test_utils.waitUntil(() => _.filter(
|
|
|
|
IQ_stanzas,
|
2019-06-03 07:58:51 +02:00
|
|
|
iq => iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]')).length
|
2018-10-26 10:15:01 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/* <iq type='result'
|
|
|
|
* from='plays.shakespeare.lit'
|
|
|
|
* to='romeo@montague.net/orchard'
|
|
|
|
* id='info1'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#info'>
|
|
|
|
* <identity
|
|
|
|
* category='server'
|
|
|
|
* type='im'/>
|
|
|
|
* <feature var='http://jabber.org/protocol/disco#info'/>
|
|
|
|
* <feature var='http://jabber.org/protocol/disco#items'/>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
let stanza = _.find(IQ_stanzas, function (iq) {
|
2019-05-20 12:38:33 +02:00
|
|
|
return iq.querySelector(
|
2019-06-03 07:58:51 +02:00
|
|
|
'iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
});
|
2019-02-12 14:21:45 +01:00
|
|
|
const info_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
2018-10-26 10:15:01 +02:00
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
2019-06-03 07:58:51 +02:00
|
|
|
'from': 'montague.lit',
|
|
|
|
'to': 'romeo@montague.lit/orchard',
|
2018-10-26 10:15:01 +02:00
|
|
|
'id': info_IQ_id
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'server',
|
|
|
|
'type': 'im'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'http://jabber.org/protocol/disco#info'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'http://jabber.org/protocol/disco#items'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
2019-05-07 09:53:36 +02:00
|
|
|
let entities = await _converse.api.disco.entities.get();
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(entities.length).toBe(2);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(_.includes(entities.pluck('jid'), 'montague.lit')).toBe(true);
|
|
|
|
expect(_.includes(entities.pluck('jid'), 'romeo@montague.lit')).toBe(true);
|
2018-10-26 10:15:01 +02:00
|
|
|
|
|
|
|
expect(entities.get(_converse.domain).features.length).toBe(2);
|
|
|
|
expect(entities.get(_converse.domain).identities.length).toBe(1);
|
|
|
|
|
|
|
|
// Converse.js sees that the entity has a disco#items feature,
|
|
|
|
// so it will make a query for it.
|
|
|
|
await test_utils.waitUntil(() => _.filter(
|
|
|
|
IQ_stanzas,
|
2019-06-03 07:58:51 +02:00
|
|
|
iq => iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#items"]')
|
2018-10-26 10:15:01 +02:00
|
|
|
).length
|
|
|
|
);
|
|
|
|
/* <iq from='montague.tld'
|
|
|
|
* id='step_01'
|
|
|
|
* to='romeo@montague.tld/garden'
|
|
|
|
* type='result'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#items'>
|
|
|
|
* <item jid='upload.montague.tld' name='HTTP File Upload' />
|
|
|
|
* <item jid='conference.montague.tld' name='Chatroom Service' />
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
stanza = _.find(IQ_stanzas, function (iq) {
|
2019-06-03 07:58:51 +02:00
|
|
|
return iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#items"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
});
|
2019-05-07 09:53:36 +02:00
|
|
|
const items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
2018-10-26 10:15:01 +02:00
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
2019-06-03 07:58:51 +02:00
|
|
|
'from': 'montague.lit',
|
|
|
|
'to': 'romeo@montague.lit/orchard',
|
2018-10-26 10:15:01 +02:00
|
|
|
'id': items_IQ_id
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#items'})
|
|
|
|
.c('item', {
|
2019-06-03 07:58:51 +02:00
|
|
|
'jid': 'upload.montague.lit',
|
2018-10-26 10:15:01 +02:00
|
|
|
'name': 'HTTP File Upload'});
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
_converse.api.disco.entities.get().then(function (entities) {
|
|
|
|
expect(entities.length).toBe(2);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(entities.get('montague.lit').items.length).toBe(1);
|
2018-10-26 10:15:01 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
// Converse.js sees that the entity has a disco#info feature,
|
|
|
|
// so it will make a query for it.
|
2018-03-28 18:38:22 +02:00
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
2019-06-03 07:58:51 +02:00
|
|
|
return iq.querySelector('iq[to="upload.montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
}).length > 0;
|
|
|
|
}, 300);
|
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
stanza = await test_utils.waitUntil(() =>
|
|
|
|
_.filter(
|
|
|
|
IQ_stanzas,
|
2019-06-03 07:58:51 +02:00
|
|
|
iq => iq.querySelector('iq[to="upload.montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]')
|
2018-10-26 10:15:01 +02:00
|
|
|
).pop()
|
|
|
|
);
|
|
|
|
const IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="`+IQ_id+`" to="upload.montague.lit" type="get" xmlns="jabber:client">`+
|
2018-10-26 10:15:01 +02:00
|
|
|
`<query xmlns="http://jabber.org/protocol/disco#info"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
|
|
|
// Upload service responds and reports a maximum file size of 5MiB
|
|
|
|
/* <iq from='upload.montague.tld'
|
|
|
|
* id='step_02'
|
|
|
|
* to='romeo@montague.tld/garden'
|
|
|
|
* type='result'>
|
|
|
|
* <query xmlns='http://jabber.org/protocol/disco#info'>
|
|
|
|
* <identity category='store'
|
|
|
|
* type='file'
|
|
|
|
* name='HTTP File Upload' />
|
|
|
|
* <feature var='urn:xmpp:http:upload:0' />
|
|
|
|
* <x type='result' xmlns='jabber:x:data'>
|
|
|
|
* <field var='FORM_TYPE' type='hidden'>
|
|
|
|
* <value>urn:xmpp:http:upload:0</value>
|
|
|
|
* </field>
|
|
|
|
* <field var='max-file-size'>
|
|
|
|
* <value>5242880</value>
|
|
|
|
* </field>
|
|
|
|
* </x>
|
|
|
|
* </query>
|
|
|
|
* </iq>
|
|
|
|
*/
|
2019-06-03 07:58:51 +02:00
|
|
|
stanza = $iq({'type': 'result', 'to': 'romeo@montague.lit/orchard', 'id': IQ_id, 'from': 'upload.montague.lit'})
|
2018-10-26 10:15:01 +02:00
|
|
|
.c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {'category':'store', 'type':'file', 'name':'HTTP File Upload'}).up()
|
|
|
|
.c('feature', {'var':'urn:xmpp:http:upload:0'}).up()
|
|
|
|
.c('x', {'type':'result', 'xmlns':'jabber:x:data'})
|
|
|
|
.c('field', {'var':'FORM_TYPE', 'type':'hidden'})
|
|
|
|
.c('value').t('urn:xmpp:http:upload:0').up().up()
|
|
|
|
.c('field', {'var':'max-file-size'})
|
|
|
|
.c('value').t('5242880');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
2019-05-07 09:53:36 +02:00
|
|
|
entities = await _converse.api.disco.entities.get();
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(entities.get('montague.lit').items.get('upload.montague.lit').identities.where({'category': 'store'}).length).toBe(1);
|
2019-05-07 09:53:36 +02:00
|
|
|
const supported = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);
|
|
|
|
expect(supported).toBe(true);
|
|
|
|
const features = await _converse.api.disco.features.get(Strophe.NS.HTTPUPLOAD, _converse.domain);
|
|
|
|
expect(features.length).toBe(1);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(features[0].get('jid')).toBe('upload.montague.lit');
|
2019-05-07 09:53:36 +02:00
|
|
|
expect(features[0].dataforms.where({'FORM_TYPE': {value: "urn:xmpp:http:upload:0", type: "hidden"}}).length).toBe(1);
|
|
|
|
done();
|
2018-03-28 18:38:22 +02:00
|
|
|
}));
|
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2018-04-22 17:47:34 +02:00
|
|
|
describe("When not supported", function () {
|
|
|
|
describe("A file upload toolbar button", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("does not appear in private chats", mock.initConverse(async (done, _converse) => {
|
2019-06-03 07:58:51 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-04-22 17:47:34 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-04-22 17:47:34 +02:00
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
2019-02-12 14:21:45 +01:00
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
2018-04-22 17:47:34 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], [], 'items');
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(view.el.querySelector('.chat-toolbar .upload-file')).toBe(null);
|
|
|
|
done();
|
2018-04-22 17:47:34 +02:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("does not appear in MUC chats", mock.initConverse(
|
2018-04-22 17:47:34 +02:00
|
|
|
null, ['rosterGroupsFetched'], {},
|
2019-02-12 14:21:45 +01:00
|
|
|
async (done, _converse) => {
|
2018-04-22 17:47:34 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
|
2019-02-12 14:21:45 +01:00
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
2018-04-22 17:47:34 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.lit'], 'items');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.lit', [], [Strophe.NS.HTTPUPLOAD], []);
|
|
|
|
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
2019-02-12 14:21:45 +01:00
|
|
|
expect(view.el.querySelector('.chat-toolbar .upload-file')).toBe(null);
|
|
|
|
done();
|
2018-04-22 17:47:34 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
describe("When supported", function () {
|
|
|
|
|
|
|
|
describe("A file upload toolbar button", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("appears in private chats", mock.initConverse(async (done, _converse) => {
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-03-29 20:22:05 +02:00
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
2019-02-12 14:21:45 +01:00
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.lit'], 'items')
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.lit', [], [Strophe.NS.HTTPUPLOAD], []);
|
2019-02-12 14:21:45 +01:00
|
|
|
test_utils.createContacts(_converse, 'current', 3);
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-02-12 14:21:45 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.upload-file'));
|
|
|
|
expect(view.el.querySelector('.chat-toolbar .upload-file')).not.toBe(null);
|
|
|
|
done();
|
2018-03-29 16:12:19 +02:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("appears in MUC chats", mock.initConverse(
|
2018-07-30 18:16:32 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-02-12 14:21:45 +01:00
|
|
|
async (done, _converse) => {
|
2018-04-22 17:02:01 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-04-22 17:02:01 +02:00
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
2019-02-12 14:21:45 +01:00
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.lit'], 'items');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.lit', [], [Strophe.NS.HTTPUPLOAD], []);
|
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
|
|
|
|
await test_utils.waitUntil(() => _converse.chatboxviews.get('lounge@montague.lit').el.querySelector('.upload-file'));
|
|
|
|
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
2019-02-12 14:21:45 +01:00
|
|
|
expect(view.el.querySelector('.chat-toolbar .upload-file')).not.toBe(null);
|
|
|
|
done();
|
2018-03-29 16:12:19 +02:00
|
|
|
}));
|
2018-04-14 21:13:02 +02:00
|
|
|
|
2018-04-18 10:03:21 +02:00
|
|
|
describe("when clicked and a file chosen", function () {
|
2018-04-17 15:17:39 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is uploaded and sent out", mock.initConverse(async (done, _converse) => {
|
2018-11-18 15:56:14 +01:00
|
|
|
const base_url = 'https://conversejs.org';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-04-14 21:13:02 +02:00
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
2018-10-13 23:25:01 +02:00
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
2018-04-14 21:13:02 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
const send_backup = XMLHttpRequest.prototype.send;
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.tld'], 'items');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.tld', [], [Strophe.NS.HTTPUPLOAD], []);
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const file = {
|
|
|
|
'type': 'image/jpeg',
|
|
|
|
'size': '23456' ,
|
|
|
|
'lastModifiedDate': "",
|
|
|
|
'name': "my-juliet.jpg"
|
|
|
|
};
|
|
|
|
view.model.sendFiles([file]);
|
|
|
|
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
await test_utils.waitUntil(() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[to="upload.montague.tld"] request')).length);
|
2019-02-12 14:21:45 +01:00
|
|
|
const iq = IQ_stanzas.pop();
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(iq)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" `+
|
2019-05-20 12:38:33 +02:00
|
|
|
`id="${iq.getAttribute("id")}" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`to="upload.montague.tld" `+
|
|
|
|
`type="get" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<request `+
|
|
|
|
`content-type="image/jpeg" `+
|
|
|
|
`filename="my-juliet.jpg" `+
|
|
|
|
`size="23456" `+
|
|
|
|
`xmlns="urn:xmpp:http:upload:0"/>`+
|
|
|
|
`</iq>`);
|
2018-04-14 21:13:02 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
const message = base_url+"/logo/conversejs-filled.svg";
|
|
|
|
|
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<iq from="upload.montague.tld"
|
2019-05-20 12:38:33 +02:00
|
|
|
id="${iq.getAttribute("id")}"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard"
|
2019-02-12 14:21:45 +01:00
|
|
|
type="result">
|
|
|
|
<slot xmlns="urn:xmpp:http:upload:0">
|
|
|
|
<put url="https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg">
|
|
|
|
<header name="Authorization">Basic Base64String==</header>
|
|
|
|
<header name="Cookie">foo=bar; user=romeo</header>
|
|
|
|
</put>
|
|
|
|
<get url="${message}" />
|
|
|
|
</slot>
|
|
|
|
</iq>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
spyOn(XMLHttpRequest.prototype, 'send').and.callFake(function () {
|
|
|
|
const message = view.model.messages.at(0);
|
|
|
|
expect(view.el.querySelector('.chat-content progress').getAttribute('value')).toBe('0');
|
|
|
|
message.set('progress', 0.5);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.chat-content progress').getAttribute('value') === '0.5')
|
2018-07-30 18:16:32 +02:00
|
|
|
.then(() => {
|
2018-10-13 23:25:01 +02:00
|
|
|
message.set('progress', 1);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.chat-content progress').getAttribute('value') === '1')
|
2018-07-30 18:16:32 +02:00
|
|
|
}).then(() => {
|
2018-10-13 23:25:01 +02:00
|
|
|
message.save({
|
|
|
|
'upload': _converse.SUCCESS,
|
|
|
|
'oob_url': message.get('get'),
|
|
|
|
'message': message.get('get')
|
2018-04-22 17:02:01 +02:00
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
return new Promise((resolve, reject) => view.model.messages.once('rendered', resolve));
|
2018-04-22 17:02:01 +02:00
|
|
|
});
|
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
let sent_stanza;
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(stanza => (sent_stanza = stanza));
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
await test_utils.waitUntil(() => sent_stanza, 1000);
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<message from="romeo@montague.lit/orchard" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`id="${sent_stanza.nodeTree.getAttribute("id")}" `+
|
2019-06-03 07:58:51 +02:00
|
|
|
`to="lady.montague@montague.lit" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`type="chat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>${message}</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
2018-11-03 14:37:57 +01:00
|
|
|
`<request xmlns="urn:xmpp:receipts"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`<x xmlns="jabber:x:oob">`+
|
|
|
|
`<url>${message}</url>`+
|
|
|
|
`</x>`+
|
2019-02-07 14:15:49 +01:00
|
|
|
`<origin-id id="${sent_stanza.nodeTree.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`</message>`);
|
|
|
|
await test_utils.waitUntil(() => view.el.querySelector('.chat-image'), 1000);
|
|
|
|
// Check that the image renders
|
|
|
|
expect(view.el.querySelector('.chat-msg .chat-msg__media').innerHTML.trim()).toEqual(
|
|
|
|
`<!-- src/templates/image.html -->\n`+
|
2018-11-18 15:56:14 +01:00
|
|
|
`<a href="${base_url}/logo/conversejs-filled.svg" target="_blank" rel="noopener">`+
|
|
|
|
`<img class="chat-image img-thumbnail" src="${base_url}/logo/conversejs-filled.svg">`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`</a>`);
|
|
|
|
XMLHttpRequest.prototype.send = send_backup;
|
|
|
|
done();
|
2018-04-22 17:02:01 +02:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is uploaded and sent out from a groupchat", mock.initConverse(async (done, _converse) => {
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2018-11-18 15:56:14 +01:00
|
|
|
const base_url = 'https://conversejs.org';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-04-22 17:02:01 +02:00
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
2018-10-13 23:25:01 +02:00
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
|
|
|
|
|
|
|
const send_backup = XMLHttpRequest.prototype.send;
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2018-04-22 17:02:01 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.tld'], 'items');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.tld', [], [Strophe.NS.HTTPUPLOAD], []);
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
|
2019-05-19 22:11:26 +02:00
|
|
|
|
|
|
|
// Wait until MAM query has been sent out
|
|
|
|
const sent_stanzas = _converse.connection.sent_stanzas;
|
|
|
|
await test_utils.waitUntil(() => sent_stanzas.filter(s => sizzle(`[xmlns="${Strophe.NS.MAM}"]`, s).length).pop());
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
2018-10-13 23:25:01 +02:00
|
|
|
const file = {
|
|
|
|
'type': 'image/jpeg',
|
|
|
|
'size': '23456' ,
|
|
|
|
'lastModifiedDate': "",
|
|
|
|
'name': "my-juliet.jpg"
|
|
|
|
};
|
|
|
|
view.model.sendFiles([file]);
|
|
|
|
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
await test_utils.waitUntil(() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[to="upload.montague.tld"] request')).length);
|
2019-02-12 14:21:45 +01:00
|
|
|
const iq = IQ_stanzas.pop();
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(iq)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" `+
|
2019-05-20 12:38:33 +02:00
|
|
|
`id="${iq.getAttribute("id")}" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`to="upload.montague.tld" `+
|
|
|
|
`type="get" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<request `+
|
|
|
|
`content-type="image/jpeg" `+
|
|
|
|
`filename="my-juliet.jpg" `+
|
|
|
|
`size="23456" `+
|
|
|
|
`xmlns="urn:xmpp:http:upload:0"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
const message = base_url+"/logo/conversejs-filled.svg";
|
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<iq from='upload.montague.tld'
|
2019-05-20 12:38:33 +02:00
|
|
|
id="${iq.getAttribute('id')}"
|
2019-06-03 07:58:51 +02:00
|
|
|
to='romeo@montague.lit/orchard'
|
2019-02-12 14:21:45 +01:00
|
|
|
type='result'>
|
|
|
|
<slot xmlns='urn:xmpp:http:upload:0'>
|
|
|
|
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg'>
|
|
|
|
<header name='Authorization'>Basic Base64String==</header>
|
|
|
|
<header name='Cookie'>foo=bar; user=romeo</header>
|
|
|
|
</put>
|
|
|
|
<get url="${message}" />
|
|
|
|
</slot>
|
|
|
|
</iq>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
spyOn(XMLHttpRequest.prototype, 'send').and.callFake(function () {
|
|
|
|
const message = view.model.messages.at(0);
|
|
|
|
expect(view.el.querySelector('.chat-content progress').getAttribute('value')).toBe('0');
|
|
|
|
message.set('progress', 0.5);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.chat-content progress').getAttribute('value') === '0.5')
|
|
|
|
.then(() => {
|
|
|
|
message.set('progress', 1);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.chat-content progress').getAttribute('value') === '1')
|
|
|
|
}).then(() => {
|
|
|
|
message.save({
|
|
|
|
'upload': _converse.SUCCESS,
|
|
|
|
'oob_url': message.get('get'),
|
|
|
|
'message': message.get('get')
|
2018-04-14 21:13:02 +02:00
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
return new Promise((resolve, reject) => view.model.messages.once('rendered', resolve));
|
2018-04-14 21:13:02 +02:00
|
|
|
});
|
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
let sent_stanza;
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(stanza => (sent_stanza = stanza));
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
await test_utils.waitUntil(() => sent_stanza, 1000);
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
`<message `+
|
2019-06-03 07:58:51 +02:00
|
|
|
`from="romeo@montague.lit/orchard" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`id="${sent_stanza.nodeTree.getAttribute("id")}" `+
|
2019-06-03 07:58:51 +02:00
|
|
|
`to="lounge@montague.lit" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`type="groupchat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>${message}</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<x xmlns="jabber:x:oob">`+
|
|
|
|
`<url>${message}</url>`+
|
|
|
|
`</x>`+
|
2019-02-07 14:15:49 +01:00
|
|
|
`<origin-id id="${sent_stanza.nodeTree.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`</message>`);
|
|
|
|
await test_utils.waitUntil(() => view.el.querySelector('.chat-image'), 1000);
|
|
|
|
// Check that the image renders
|
|
|
|
expect(view.el.querySelector('.chat-msg .chat-msg__media').innerHTML.trim()).toEqual(
|
|
|
|
`<!-- src/templates/image.html -->\n`+
|
2018-11-18 15:56:14 +01:00
|
|
|
`<a href="${base_url}/logo/conversejs-filled.svg" target="_blank" rel="noopener">`+
|
|
|
|
`<img class="chat-image img-thumbnail" src="${base_url}/logo/conversejs-filled.svg">`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`</a>`);
|
|
|
|
XMLHttpRequest.prototype.send = send_backup;
|
|
|
|
done();
|
2018-04-14 21:13:02 +02:00
|
|
|
}));
|
2018-04-18 10:03:21 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("shows an error message if the file is too large", mock.initConverse(async (done, _converse) => {
|
2018-07-30 18:16:32 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const IQ_ids = _converse.connection.IQ_ids;
|
|
|
|
const send_backup = XMLHttpRequest.prototype.send;
|
2018-10-26 10:15:01 +02:00
|
|
|
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []);
|
|
|
|
await test_utils.waitUntil(() => _.filter(
|
|
|
|
IQ_stanzas,
|
2019-06-03 07:58:51 +02:00
|
|
|
iq => iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]')).length
|
2018-10-26 10:15:01 +02:00
|
|
|
);
|
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
let stanza = _.find(IQ_stanzas, function (iq) {
|
|
|
|
return iq.querySelector(
|
2019-06-03 07:58:51 +02:00
|
|
|
'iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
});
|
2019-05-20 12:38:33 +02:00
|
|
|
const info_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
2018-10-26 10:15:01 +02:00
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
2019-06-03 07:58:51 +02:00
|
|
|
'from': 'montague.lit',
|
|
|
|
'to': 'romeo@montague.lit/orchard',
|
2018-10-26 10:15:01 +02:00
|
|
|
'id': info_IQ_id
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {
|
|
|
|
'category': 'server',
|
|
|
|
'type': 'im'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'http://jabber.org/protocol/disco#info'}).up()
|
|
|
|
.c('feature', {
|
|
|
|
'var': 'http://jabber.org/protocol/disco#items'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
let entities = await _converse.api.disco.entities.get();
|
|
|
|
|
|
|
|
expect(entities.length).toBe(2);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(_.includes(entities.pluck('jid'), 'montague.lit')).toBe(true);
|
|
|
|
expect(_.includes(entities.pluck('jid'), 'romeo@montague.lit')).toBe(true);
|
2018-10-26 10:15:01 +02:00
|
|
|
|
|
|
|
expect(entities.get(_converse.domain).features.length).toBe(2);
|
|
|
|
expect(entities.get(_converse.domain).identities.length).toBe(1);
|
|
|
|
|
|
|
|
await test_utils.waitUntil(function () {
|
|
|
|
// Converse.js sees that the entity has a disco#items feature,
|
|
|
|
// so it will make a query for it.
|
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
2019-06-03 07:58:51 +02:00
|
|
|
return iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#items"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
}).length > 0;
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
stanza = _.find(IQ_stanzas, function (iq) {
|
2019-06-03 07:58:51 +02:00
|
|
|
return iq.querySelector('iq[to="montague.lit"] query[xmlns="http://jabber.org/protocol/disco#items"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
});
|
|
|
|
var items_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
|
|
|
stanza = $iq({
|
|
|
|
'type': 'result',
|
2019-06-03 07:58:51 +02:00
|
|
|
'from': 'montague.lit',
|
|
|
|
'to': 'romeo@montague.lit/orchard',
|
2018-10-26 10:15:01 +02:00
|
|
|
'id': items_IQ_id
|
|
|
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#items'})
|
|
|
|
.c('item', {
|
2019-06-03 07:58:51 +02:00
|
|
|
'jid': 'upload.montague.lit',
|
2018-10-26 10:15:01 +02:00
|
|
|
'name': 'HTTP File Upload'});
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
entities = await _converse.api.disco.entities.get()
|
|
|
|
|
|
|
|
expect(entities.length).toBe(2);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(entities.get('montague.lit').items.length).toBe(1);
|
2018-10-26 10:15:01 +02:00
|
|
|
await test_utils.waitUntil(function () {
|
|
|
|
// Converse.js sees that the entity has a disco#info feature,
|
|
|
|
// so it will make a query for it.
|
|
|
|
return _.filter(IQ_stanzas, function (iq) {
|
2019-06-03 07:58:51 +02:00
|
|
|
return iq.querySelector('iq[to="upload.montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]');
|
2018-10-26 10:15:01 +02:00
|
|
|
}).length > 0;
|
|
|
|
}, 300);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
stanza = _.find(IQ_stanzas, iq => iq.querySelector('iq[to="upload.montague.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]'));
|
2019-05-20 12:38:33 +02:00
|
|
|
const IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
|
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${IQ_id}" to="upload.montague.lit" type="get" xmlns="jabber:client">`+
|
2018-10-26 10:15:01 +02:00
|
|
|
`<query xmlns="http://jabber.org/protocol/disco#info"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
|
|
|
// Upload service responds and reports a maximum file size of 5MiB
|
2019-06-03 07:58:51 +02:00
|
|
|
stanza = $iq({'type': 'result', 'to': 'romeo@montague.lit/orchard', 'id': IQ_id, 'from': 'upload.montague.lit'})
|
2018-10-26 10:15:01 +02:00
|
|
|
.c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
|
|
.c('identity', {'category':'store', 'type':'file', 'name':'HTTP File Upload'}).up()
|
|
|
|
.c('feature', {'var':'urn:xmpp:http:upload:0'}).up()
|
|
|
|
.c('x', {'type':'result', 'xmlns':'jabber:x:data'})
|
|
|
|
.c('field', {'var':'FORM_TYPE', 'type':'hidden'})
|
|
|
|
.c('value').t('urn:xmpp:http:upload:0').up().up()
|
|
|
|
.c('field', {'var':'max-file-size'})
|
|
|
|
.c('value').t('5242880');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
entities = await _converse.api.disco.entities.get();
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(entities.get('montague.lit').items.get('upload.montague.lit').identities.where({'category': 'store'}).length).toBe(1);
|
2019-05-07 09:53:36 +02:00
|
|
|
await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);
|
2018-10-26 10:15:01 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-26 10:15:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
var file = {
|
|
|
|
'type': 'image/jpeg',
|
|
|
|
'size': '5242881',
|
|
|
|
'lastModifiedDate': "",
|
|
|
|
'name': "my-juliet.jpg"
|
|
|
|
};
|
|
|
|
view.model.sendFiles([file]);
|
|
|
|
await test_utils.waitUntil(() => view.el.querySelectorAll('.message').length)
|
|
|
|
const messages = view.el.querySelectorAll('.message.chat-error');
|
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(messages[0].textContent).toBe(
|
|
|
|
'The size of your file, my-juliet.jpg, exceeds the maximum allowed by your server, which is 5 MB.');
|
|
|
|
done();
|
2018-04-18 10:03:21 +02:00
|
|
|
}));
|
2018-04-14 21:13:02 +02:00
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
});
|
2018-04-18 11:49:53 +02:00
|
|
|
|
|
|
|
describe("While a file is being uploaded", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("shows a progress bar", mock.initConverse(
|
2018-10-13 23:25:01 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
|
|
async function (done, _converse) {
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-04-18 11:49:53 +02:00
|
|
|
_converse, _converse.domain,
|
|
|
|
[{'category': 'server', 'type':'IM'}],
|
2018-10-13 23:25:01 +02:00
|
|
|
['http://jabber.org/protocol/disco#items'], [], 'info');
|
2018-04-18 11:49:53 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
const send_backup = XMLHttpRequest.prototype.send;
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.tld'], 'items');
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.tld', [], [Strophe.NS.HTTPUPLOAD], []);
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const file = {
|
|
|
|
'type': 'image/jpeg',
|
|
|
|
'size': '23456' ,
|
|
|
|
'lastModifiedDate': "",
|
|
|
|
'name': "my-juliet.jpg"
|
|
|
|
};
|
|
|
|
view.model.sendFiles([file]);
|
|
|
|
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
2019-05-20 12:38:33 +02:00
|
|
|
await test_utils.waitUntil(() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[to="upload.montague.tld"] request')).length)
|
2018-10-13 23:25:01 +02:00
|
|
|
const iq = IQ_stanzas.pop();
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(iq)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" `+
|
2019-05-20 12:38:33 +02:00
|
|
|
`id="${iq.getAttribute("id")}" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`to="upload.montague.tld" `+
|
|
|
|
`type="get" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<request `+
|
|
|
|
`content-type="image/jpeg" `+
|
|
|
|
`filename="my-juliet.jpg" `+
|
|
|
|
`size="23456" `+
|
|
|
|
`xmlns="urn:xmpp:http:upload:0"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
2018-11-18 15:56:14 +01:00
|
|
|
const base_url = 'https://conversejs.org';
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = base_url+"/logo/conversejs-filled.svg";
|
2019-02-12 14:21:45 +01:00
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<iq from="upload.montague.tld"
|
2019-05-20 12:38:33 +02:00
|
|
|
id="${iq.getAttribute("id")}"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard"
|
2019-02-12 14:21:45 +01:00
|
|
|
type="result">
|
|
|
|
<slot xmlns="urn:xmpp:http:upload:0">
|
|
|
|
<put url="https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg">
|
|
|
|
<header name="Authorization">Basic Base64String==</header>
|
|
|
|
<header name="Cookie">foo=bar; user=romeo</header>
|
|
|
|
</put>
|
|
|
|
<get url="${message}" />
|
|
|
|
</slot>
|
|
|
|
</iq>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
spyOn(XMLHttpRequest.prototype, 'send').and.callFake(function () {
|
|
|
|
const message = view.model.messages.at(0);
|
|
|
|
expect(view.el.querySelector('.chat-content progress').getAttribute('value')).toBe('0');
|
|
|
|
message.set('progress', 0.5);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.chat-content progress').getAttribute('value') === '0.5')
|
2018-07-30 18:16:32 +02:00
|
|
|
.then(() => {
|
2018-10-13 23:25:01 +02:00
|
|
|
message.set('progress', 1);
|
|
|
|
test_utils.waitUntil(() => view.el.querySelector('.chat-content progress').getAttribute('value') === '1')
|
2018-07-30 18:16:32 +02:00
|
|
|
}).then(() => {
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelector('.chat-content .chat-msg__text').textContent).toBe('Uploading file: my-juliet.jpg, 22.91 KB');
|
|
|
|
done();
|
2018-04-18 11:49:53 +02:00
|
|
|
});
|
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
let sent_stanza;
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(stanza => (sent_stanza = stanza));
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2018-04-18 11:49:53 +02:00
|
|
|
}));
|
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
});
|
2018-03-28 18:38:22 +02:00
|
|
|
});
|
|
|
|
}));
|