Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
d73394fa
Commit
d73394fa
authored
Apr 22, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for XEP-0363 for MUC
Update #161
parent
aacfe3b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
2 deletions
+129
-2
spec/http-file-upload.js
spec/http-file-upload.js
+129
-2
No files found.
spec/http-file-upload.js
View file @
d73394fa
...
...
@@ -199,8 +199,29 @@
});
}));
it
(
"
appears in MUC chats
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
it
(
"
appears in MUC chats
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[
'
http://jabber.org/protocol/disco#items
'
],
[],
'
info
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.localhost
'
],
'
items
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.localhost
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]).
then
(
function
()
{
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
).
then
(
function
()
{
var
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
test_utils
.
waitUntil
(
function
()
{
return
view
.
el
.
querySelector
(
'
.upload-file
'
);
}).
then
(
function
()
{
expect
(
view
.
el
.
querySelector
(
'
.chat-toolbar .upload-file
'
)).
not
.
toBe
(
null
);
done
();
});
});
});
});
});
}));
describe
(
"
when clicked and a file chosen
"
,
function
()
{
...
...
@@ -311,6 +332,112 @@
});
}));
it
(
"
is uploaded and sent out from a groupchat
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[
'
http://jabber.org/protocol/disco#items
'
],
[],
'
info
'
).
then
(
function
()
{
var
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.montague.tld
'
],
'
items
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.montague.tld
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]).
then
(
function
()
{
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
).
then
(
function
()
{
var
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
var
file
=
{
'
type
'
:
'
image/jpeg
'
,
'
size
'
:
'
23456
'
,
'
lastModifiedDate
'
:
""
,
'
name
'
:
"
my-juliet.jpg
"
};
view
.
model
.
sendFiles
([
file
]);
return
test_utils
.
waitUntil
(
function
()
{
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.montague.tld"] request
'
);
}).
length
>
0
;
}).
then
(
function
()
{
var
iq
=
IQ_stanzas
.
pop
();
expect
(
iq
.
toLocaleString
()).
toBe
(
"
<iq from='dummy@localhost/resource'
"
+
"
to='upload.montague.tld'
"
+
"
type='get'
"
+
"
xmlns='jabber:client'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'>
"
+
"
<request xmlns='urn:xmpp:http:upload:0'
"
+
"
filename='my-juliet.jpg'
"
+
"
size='23456'
"
+
"
content-type='image/jpeg'/>
"
+
"
</iq>
"
);
var
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
var
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
var
stanza
=
Strophe
.
xmlHtmlNode
(
"
<iq from='upload.montague.tld'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'
"
+
"
to='dummy@localhost/resource'
"
+
"
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>
"
).
firstElementChild
;
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
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0.5
'
);
message
.
set
(
'
progress
'
,
1
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
1
'
);
message
.
save
({
'
upload
'
:
_converse
.
SUCCESS
,
'
message
'
:
message
.
get
(
'
get
'
)
});
});
var
sent_stanza
;
spyOn
(
_converse
.
connection
,
'
send
'
).
and
.
callFake
(
function
(
stanza
)
{
sent_stanza
=
stanza
;
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(
function
()
{
return
sent_stanza
;
},
1000
).
then
(
function
()
{
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
"
<message from='dummy@localhost/resource'
"
+
"
to='lounge@localhost'
"
+
"
type='groupchat'
"
+
"
id='
"
+
sent_stanza
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
' xmlns='jabber:client'>
"
+
"
<body>
"
+
message
+
"
</body>
"
+
"
<active xmlns='http://jabber.org/protocol/chatstates'/>
"
+
"
<x xmlns='jabber:x:oob'>
"
+
"
<url>
"
+
message
+
"
</url>
"
+
"
</x>
"
+
"
</message>
"
);
return
test_utils
.
waitUntil
(
function
()
{
return
view
.
el
.
querySelector
(
'
.chat-image
'
);
},
1000
);
}).
then
(
function
()
{
// Check that the image renders
expect
(
view
.
el
.
querySelector
(
'
.chat-message .chat-msg-content
'
).
innerHTML
).
toEqual
(
'
<a target="_blank" rel="noopener" href="http://localhost:8000/logo/conversejs-filled.svg">
'
+
'
<img class="chat-image" src="http://localhost:8000/logo/conversejs-filled.svg"></a>
'
)
XMLHttpRequest
.
prototype
.
send
=
send_backup
;
done
();
});
});
});
});
});
});
}));
it
(
"
shows and error message if the file is too large
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
var
IQ_ids
=
_converse
.
connection
.
IQ_ids
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment