1
1
'use strict' ;
2
2
3
- /* global chai: false */
3
+ /* global chai, sinon : false */
4
4
5
5
var expect = chai . expect ;
6
6
7
- describe ( 'The contactEditionForm directive' , function ( ) {
7
+ describe . only ( 'The contactEditionForm directive' , function ( ) {
8
8
var $compile , $rootScope , $scope , session ;
9
9
var CONTACT_AVATAR_SIZE , DEFAULT_ADDRESSBOOK_NAME , CONTACT_COLLECTED_ADDRESSBOOK_NAME ;
10
10
var contactAddressbookService , esnConfigMock ;
11
+ let userAPIMock , contactAddressbookDisplayServiceMock ;
11
12
12
13
beforeEach ( function ( ) {
14
+ contactAddressbookDisplayServiceMock = {
15
+ convertShellsToDisplayShells : sinon . spy ( function ( shells ) {
16
+ return shells . map ( shell => ( {
17
+ bookName : shell . bookName ,
18
+ shell : shell
19
+ } ) ) ;
20
+ } ) ,
21
+ sortAddressbookDisplayShells : shells => shells
22
+ } ;
13
23
angular . mock . module ( 'esn.core' ) ;
14
24
angular . mock . module ( 'linagora.esn.contact' ) ;
15
25
angular . mock . module ( function ( $provide ) {
16
26
esnConfigMock = function ( ) {
17
27
return $q . when ( true ) ;
18
28
} ;
19
29
30
+ const user = {
31
+ data : {
32
+ id : 123456 ,
33
+ firstname : 'john' ,
34
+ lastname : 'doe'
35
+ }
36
+ } ;
37
+
38
+ userAPIMock = {
39
+ user : sinon . mock ( ) . returns (
40
+ $q . when ( user )
41
+ ) ,
42
+ currentUser : ( ) => $q . when ( user )
43
+ } ;
44
+
20
45
$provide . value ( 'esnConfig' , esnConfigMock ) ;
46
+ $provide . value ( 'userAPI' , userAPIMock ) ;
47
+ $provide . value ( 'contactAddressbookDisplayService' , contactAddressbookDisplayServiceMock ) ;
21
48
} ) ;
22
49
} ) ;
23
50
@@ -46,18 +73,31 @@ describe('The contactEditionForm directive', function() {
46
73
urls : [ ]
47
74
} ;
48
75
contactAddressbookService . listAddressbooksUserCanCreateContact = function ( ) {
49
- return $q . when ( [ {
50
- bookName : DEFAULT_ADDRESSBOOK_NAME ,
51
- href : '/addressbooks/userId/' + DEFAULT_ADDRESSBOOK_NAME + '.json'
52
- } , {
53
- bookName : CONTACT_COLLECTED_ADDRESSBOOK_NAME ,
54
- href : '/addressbooks/userId/' + CONTACT_COLLECTED_ADDRESSBOOK_NAME + '.json'
55
- } ] ) ;
76
+ return $q . when ( [
77
+ {
78
+ bookName : DEFAULT_ADDRESSBOOK_NAME ,
79
+ href : '/addressbooks/userId/' + DEFAULT_ADDRESSBOOK_NAME + '.json'
80
+ } ,
81
+ {
82
+ bookName : CONTACT_COLLECTED_ADDRESSBOOK_NAME ,
83
+ href : '/addressbooks/userId/' + CONTACT_COLLECTED_ADDRESSBOOK_NAME + '.json'
84
+ } ,
85
+ {
86
+ bookName : 'shared' ,
87
+ href : '/addressbooks/123456/123456.json' ,
88
+ group : undefined ,
89
+ isSubscription : true ,
90
+ source : {
91
+ bookId : 123456
92
+ }
93
+ }
94
+ ] ) ;
56
95
} ;
57
96
} ) ) ;
58
97
59
98
beforeEach ( function ( ) {
60
99
session . user = { _id : 'userId' } ;
100
+ session . fetchUser = ( ) => $q . when ( session . user ) ;
61
101
} ) ;
62
102
63
103
function initDirective ( scope ) {
@@ -73,4 +113,10 @@ describe('The contactEditionForm directive', function() {
73
113
74
114
expect ( element . isolateScope ( ) . avatarSize ) . to . equal ( CONTACT_AVATAR_SIZE . bigger ) ;
75
115
} ) ;
116
+
117
+ it ( 'should try to load the user using the userId collected from the shared addressbook' , ( ) => {
118
+ initDirective ( $scope ) ;
119
+
120
+ expect ( userAPIMock . user ) . to . have . been . calledWith ( 123456 ) ;
121
+ } ) ;
76
122
} ) ;
0 commit comments