2014-11-06 11:04:43 +00:00
describe ( 'mRoomName filter' , function ( ) {
var filter , mRoomName ;
var roomId = "!weufhewifu:matrix.org" ;
// test state values (f.e. test)
var testUserId , testAlias , testDisplayName , testOtherDisplayName , testRoomState ;
// mocked services which return the test values above.
var matrixService = {
getRoomIdToAliasMapping : function ( room _id ) {
return testAlias ;
} ,
config : function ( ) {
return {
user _id : testUserId
} ;
}
} ;
var eventHandlerService = {
getUserDisplayName : function ( room _id , user _id ) {
if ( user _id === testUserId ) {
return testDisplayName ;
}
return testOtherDisplayName ;
}
} ;
var modelService = {
getRoom : function ( room _id ) {
return {
current _room _state : testRoomState
} ;
}
} ;
beforeEach ( function ( ) {
// inject mocked dependencies
module ( function ( $provide ) {
$provide . value ( 'matrixService' , matrixService ) ;
$provide . value ( 'eventHandlerService' , eventHandlerService ) ;
$provide . value ( 'modelService' , modelService ) ;
} ) ;
module ( 'matrixFilter' ) ;
} ) ;
beforeEach ( inject ( function ( $filter ) {
filter = $filter ;
mRoomName = filter ( "mRoomName" ) ;
// purge the previous test values
testUserId = undefined ;
testAlias = undefined ;
testDisplayName = undefined ;
testOtherDisplayName = undefined ;
// mock up a stub room state
testRoomState = {
s : { } , // internal; stores the state events
state : function ( type , key ) {
// accessor used by filter
return key ? this . s [ type + key ] : this . s [ type ] ;
} ,
members : { } , // struct used by filter
// test helper methods
setJoinRule : function ( rule ) {
this . s [ "m.room.join_rules" ] = {
content : {
join _rule : rule
}
} ;
} ,
setRoomName : function ( name ) {
this . s [ "m.room.name" ] = {
content : {
name : name
}
} ;
} ,
setMember : function ( user _id , membership , inviter _user _id ) {
if ( ! inviter _user _id ) {
inviter _user _id = user _id ;
}
this . s [ "m.room.member" + user _id ] = {
2014-11-06 14:52:22 +00:00
event : {
content : {
membership : membership
} ,
state _key : user _id ,
user _id : inviter _user _id
}
2014-11-06 11:04:43 +00:00
} ;
this . members [ user _id ] = this . s [ "m.room.member" + user _id ] ;
}
} ;
} ) ) ;
/**** ROOM NAME ****/
it ( "should show the room name if one exists for private (invite join_rules) rooms." , function ( ) {
var roomName = "The Room Name" ;
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "invite" ) ;
testRoomState . setRoomName ( roomName ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( roomName ) ;
} ) ;
it ( "should show the room name if one exists for public (public join_rules) rooms." , function ( ) {
var roomName = "The Room Name" ;
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "public" ) ;
testRoomState . setRoomName ( roomName ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( roomName ) ;
} ) ;
/**** ROOM ALIAS ****/
2014-11-06 11:14:31 +00:00
it ( "should show the room alias if one exists for private (invite join_rules) rooms if a room name doesn't exist." , function ( ) {
testAlias = "#thealias:matrix.org" ;
2014-11-06 11:04:43 +00:00
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "invite" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( testAlias ) ;
} ) ;
2014-11-06 11:14:31 +00:00
it ( "should show the room alias if one exists for public (public join_rules) rooms if a room name doesn't exist." , function ( ) {
testAlias = "#thealias:matrix.org" ;
2014-11-06 11:04:43 +00:00
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "public" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( testAlias ) ;
} ) ;
/**** ROOM ID ****/
it ( "should show the room ID for public (public join_rules) rooms if a room name and alias don't exist." , function ( ) {
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "public" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( roomId ) ;
} ) ;
it ( "should show the room ID for private (invite join_rules) rooms if a room name and alias don't exist and there are >2 members." , function ( ) {
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "public" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
testRoomState . setMember ( "@alice:matrix.org" , "join" ) ;
testRoomState . setMember ( "@bob:matrix.org" , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( roomId ) ;
} ) ;
/**** SELF-CHAT ****/
it ( "should show your display name for private (invite join_rules) rooms if a room name and alias don't exist and it is a self-chat." , function ( ) {
testUserId = "@me:matrix.org" ;
testDisplayName = "Me" ;
testRoomState . setJoinRule ( "private" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( testDisplayName ) ;
} ) ;
2014-11-06 11:14:31 +00:00
it ( "should show your user ID for private (invite join_rules) rooms if a room name and alias don't exist and it is a self-chat and they don't have a display name set." , function ( ) {
2014-11-06 11:04:43 +00:00
testUserId = "@me:matrix.org" ;
testRoomState . setJoinRule ( "private" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( testUserId ) ;
} ) ;
/**** ONE-TO-ONE CHAT ****/
it ( "should show the other user's display name for private (invite join_rules) rooms if a room name and alias don't exist and it is a 1:1-chat." , function ( ) {
testUserId = "@me:matrix.org" ;
otherUserId = "@alice:matrix.org" ;
testOtherDisplayName = "Alice" ;
testRoomState . setJoinRule ( "private" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
testRoomState . setMember ( "@alice:matrix.org" , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( testOtherDisplayName ) ;
} ) ;
2014-11-06 11:14:31 +00:00
it ( "should show the other user's ID for private (invite join_rules) rooms if a room name and alias don't exist and it is a 1:1-chat and they don't have a display name set." , function ( ) {
2014-11-06 11:04:43 +00:00
testUserId = "@me:matrix.org" ;
otherUserId = "@alice:matrix.org" ;
testRoomState . setJoinRule ( "private" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
testRoomState . setMember ( "@alice:matrix.org" , "join" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( otherUserId ) ;
} ) ;
/**** INVITED TO ROOM ****/
it ( "should show the other user's display name for private (invite join_rules) rooms if you are invited to it." , function ( ) {
testUserId = "@me:matrix.org" ;
testDisplayName = "Me" ;
otherUserId = "@alice:matrix.org" ;
testOtherDisplayName = "Alice" ;
testRoomState . setJoinRule ( "private" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
testRoomState . setMember ( otherUserId , "join" ) ;
testRoomState . setMember ( testUserId , "invite" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( testOtherDisplayName ) ;
} ) ;
2014-11-06 11:14:31 +00:00
it ( "should show the other user's ID for private (invite join_rules) rooms if you are invited to it and the inviter doesn't have a display name." , function ( ) {
2014-11-06 11:04:43 +00:00
testUserId = "@me:matrix.org" ;
testDisplayName = "Me" ;
otherUserId = "@alice:matrix.org" ;
testRoomState . setJoinRule ( "private" ) ;
testRoomState . setMember ( testUserId , "join" ) ;
testRoomState . setMember ( otherUserId , "join" ) ;
testRoomState . setMember ( testUserId , "invite" ) ;
var output = mRoomName ( roomId ) ;
expect ( output ) . toEqual ( otherUserId ) ;
} ) ;
} ) ;
describe ( 'duration filter' , function ( ) {
2014-11-05 17:49:03 +00:00
var filter , durationFilter ;
beforeEach ( module ( 'matrixWebClient' ) ) ;
beforeEach ( inject ( function ( $filter ) {
filter = $filter ;
durationFilter = filter ( "duration" ) ;
} ) ) ;
it ( "should represent 15000 ms as '15s'" , function ( ) {
var output = durationFilter ( 15000 ) ;
expect ( output ) . toEqual ( "15s" ) ;
} ) ;
it ( "should represent 60000 ms as '1m'" , function ( ) {
var output = durationFilter ( 60000 ) ;
expect ( output ) . toEqual ( "1m" ) ;
} ) ;
it ( "should represent 65000 ms as '1m'" , function ( ) {
var output = durationFilter ( 65000 ) ;
expect ( output ) . toEqual ( "1m" ) ;
} ) ;
it ( "should represent 10 ms as '0s'" , function ( ) {
var output = durationFilter ( 10 ) ;
expect ( output ) . toEqual ( "0s" ) ;
} ) ;
it ( "should represent 4m as '4m'" , function ( ) {
var output = durationFilter ( 1000 * 60 * 4 ) ;
expect ( output ) . toEqual ( "4m" ) ;
} ) ;
it ( "should represent 4m30s as '4m'" , function ( ) {
var output = durationFilter ( 1000 * 60 * 4 + 1000 * 30 ) ;
expect ( output ) . toEqual ( "4m" ) ;
} ) ;
it ( "should represent 2h as '2h'" , function ( ) {
var output = durationFilter ( 1000 * 60 * 60 * 2 ) ;
expect ( output ) . toEqual ( "2h" ) ;
} ) ;
it ( "should represent 2h35m as '2h'" , function ( ) {
var output = durationFilter ( 1000 * 60 * 60 * 2 + 1000 * 60 * 35 ) ;
expect ( output ) . toEqual ( "2h" ) ;
} ) ;
2014-11-06 11:04:43 +00:00
} ) ;
describe ( 'orderMembersList filter' , function ( ) {
var filter , orderMembersList ;
beforeEach ( module ( 'matrixWebClient' ) ) ;
beforeEach ( inject ( function ( $filter ) {
filter = $filter ;
orderMembersList = filter ( "orderMembersList" ) ;
} ) ) ;
it ( "should sort a single entry" , function ( ) {
var output = orderMembersList ( {
"@a:example.com" : {
last _active _ago : 50 ,
last _updated : 1415266943964
}
} ) ;
expect ( output ) . toEqual ( [ {
id : "@a:example.com" ,
last _active _ago : 50 ,
last _updated : 1415266943964
} ] ) ;
} ) ;
it ( "should sort by taking last_active_ago into account" , function ( ) {
var output = orderMembersList ( {
"@a:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
"@b:example.com" : {
last _active _ago : 50 ,
last _updated : 1415266943964
} ,
"@c:example.com" : {
last _active _ago : 99999 ,
last _updated : 1415266943964
}
} ) ;
expect ( output ) . toEqual ( [
{
id : "@b:example.com" ,
last _active _ago : 50 ,
last _updated : 1415266943964
} ,
{
id : "@a:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
{
id : "@c:example.com" ,
last _active _ago : 99999 ,
last _updated : 1415266943964
} ,
] ) ;
} ) ;
it ( "should sort by taking last_updated into account" , function ( ) {
var output = orderMembersList ( {
"@a:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
"@b:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266900000
} ,
"@c:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266943000
}
} ) ;
expect ( output ) . toEqual ( [
{
id : "@a:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
{
id : "@c:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266943000
} ,
{
id : "@b:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266900000
} ,
] ) ;
} ) ;
it ( "should sort by taking last_updated and last_active_ago into account" ,
function ( ) {
var output = orderMembersList ( {
"@a:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266943000
} ,
"@b:example.com" : {
last _active _ago : 100000 ,
last _updated : 1415266943900
} ,
"@c:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266943964
}
} ) ;
expect ( output ) . toEqual ( [
{
id : "@c:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
{
id : "@a:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266943000
} ,
{
id : "@b:example.com" ,
last _active _ago : 100000 ,
last _updated : 1415266943900
} ,
] ) ;
} ) ;
// SYWEB-26 comment
it ( "should sort members who do not have last_active_ago value at the end of the list" ,
function ( ) {
// single undefined entry
var output = orderMembersList ( {
"@a:example.com" : {
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
"@b:example.com" : {
last _active _ago : 100000 ,
last _updated : 1415266943964
} ,
"@c:example.com" : {
last _active _ago : undefined ,
last _updated : 1415266943964
}
} ) ;
expect ( output ) . toEqual ( [
{
id : "@a:example.com" ,
last _active _ago : 1000 ,
last _updated : 1415266943964
} ,
{
id : "@b:example.com" ,
last _active _ago : 100000 ,
last _updated : 1415266943964
} ,
{
id : "@c:example.com" ,
last _active _ago : undefined ,
last _updated : 1415266943964
} ,
] ) ;
} ) ;
it ( "should sort multiple members who do not have last_active_ago according to presence" ,
function ( ) {
// single undefined entry
var output = orderMembersList ( {
"@a:example.com" : {
last _active _ago : undefined ,
last _updated : 1415266943964 ,
presence : "unavailable"
} ,
"@b:example.com" : {
last _active _ago : undefined ,
last _updated : 1415266943964 ,
presence : "online"
} ,
"@c:example.com" : {
last _active _ago : undefined ,
last _updated : 1415266943964 ,
presence : "offline"
}
} ) ;
expect ( output ) . toEqual ( [
{
id : "@b:example.com" ,
last _active _ago : undefined ,
last _updated : 1415266943964 ,
presence : "online"
} ,
{
id : "@a:example.com" ,
last _active _ago : undefined ,
last _updated : 1415266943964 ,
presence : "unavailable"
} ,
{
id : "@c:example.com" ,
last _active _ago : undefined ,
last _updated : 1415266943964 ,
presence : "offline"
} ,
] ) ;
} ) ;
} ) ;