@@ -110,6 +110,10 @@ StartTest(async t => {
110
110
packageCtrl = Ext . create ( "conjoon.cn_mail.app.PackageController" ) ;
111
111
t . expect ( packageCtrl instanceof coon . core . app . PackageController ) . toBe ( true ) ;
112
112
113
+ t . expect ( packageCtrl . getControl ( ) [ "cn_mail-maildesktopview > cn_mail-mailinboxview cn_mail-mailmessagereadermessageview" ] ) . toEqual (
114
+ { "cn_mail-messageviewitemchange" : "onMailMessageViewItemChange" }
115
+ ) ;
116
+
113
117
t . expect ( conjoon . cn_mail . app . PackageController . required ) . toEqual ( {
114
118
mailAccountHandler : "conjoon.cn_mail.view.mail.account.MailAccountHandler"
115
119
} ) ;
@@ -258,6 +262,7 @@ StartTest(async t => {
258
262
t . it ( "showMailEditor()" , t => {
259
263
260
264
let CN_HREF = "foo" ;
265
+ const FAKE_EDITOR = { } ;
261
266
262
267
packageCtrl = Ext . create ( "conjoon.cn_mail.app.PackageController" ) ;
263
268
let mvp = {
@@ -267,6 +272,7 @@ StartTest(async t => {
267
272
} ;
268
273
} ,
269
274
showMailEditor : function ( ) {
275
+ return FAKE_EDITOR ;
270
276
}
271
277
} ;
272
278
packageCtrl . getMainPackageView = function ( ) {
@@ -275,13 +281,9 @@ StartTest(async t => {
275
281
276
282
t . isCalledNTimes ( "showMailEditor" , mvp , 1 ) ;
277
283
278
- packageCtrl . showMailEditor ( "a" , "compose" ) ;
284
+ t . expect ( packageCtrl . showMailEditor ( "a" , "compose" ) ) . toBe ( FAKE_EDITOR ) ;
279
285
280
- let exc ;
281
- try { packageCtrl . showMailEditor ( ) ; } catch ( e ) { exc = e ; }
282
- t . expect ( exc ) . toBeDefined ( ) ;
283
- t . expect ( exc . msg ) . toBeDefined ( ) ;
284
- t . expect ( exc . msg . toLowerCase ( ) ) . toContain ( "expects an instance" ) ;
286
+ t . expect ( packageCtrl . showMailEditor ( ) ) . toBeUndefined ( ) ;
285
287
286
288
} ) ;
287
289
@@ -407,7 +409,7 @@ StartTest(async t => {
407
409
} ;
408
410
} ;
409
411
410
- packageCtrl . getItemOrDraftFromActiveView = function ( ) {
412
+ packageCtrl . getDraftOrItemFromActiveView = function ( ) {
411
413
return "foo" ;
412
414
} ;
413
415
@@ -1332,9 +1334,22 @@ StartTest(async t => {
1332
1334
packageCtrl = Ext . create ( "conjoon.cn_mail.app.PackageController" ) ;
1333
1335
1334
1336
let activeTab = null ,
1337
+ mailInboxMessageView ,
1335
1338
COMPOUNDKEY = MessageEntityCompoundKey . createFor (
1336
1339
1 , 2 , 3 ) , SETKEY = null ;
1337
1340
1341
+ let FAKE_MESSAGE_ITEM = {
1342
+ getCompoundKey : function ( ) {
1343
+ return COMPOUNDKEY ;
1344
+ }
1345
+ } ;
1346
+
1347
+ let SELECTION = [ FAKE_MESSAGE_ITEM ] ;
1348
+ let FAKE_MAIL_MESSAGE_GRID = {
1349
+ getSelection ( ) {
1350
+ return SELECTION ;
1351
+ }
1352
+ } ;
1338
1353
packageCtrl . getMailDesktopView = function ( ) {
1339
1354
return {
1340
1355
getActiveTab : function ( ) {
@@ -1353,22 +1368,51 @@ StartTest(async t => {
1353
1368
1354
1369
activeTab = Ext . create ( "conjoon.cn_mail.view.mail.message.reader.MessageView" ) ;
1355
1370
activeTab . getMessageItem = function ( ) {
1356
- return {
1357
- getCompoundKey : function ( ) {
1358
- return COMPOUNDKEY ;
1359
- }
1360
- } ;
1371
+ return FAKE_MESSAGE_ITEM ;
1361
1372
} ;
1362
1373
packageCtrl . getMailInboxView = function ( ) {
1363
1374
return activeTab ;
1364
1375
} ;
1376
+ mailInboxMessageView = Ext . create ( "conjoon.cn_mail.view.mail.message.reader.MessageView" ) ;
1377
+ mailInboxMessageView . getMessageItem = function ( ) {
1378
+ return FAKE_MESSAGE_ITEM ;
1379
+ } ;
1380
+ packageCtrl . getMailInboxMessageView = function ( ) {
1381
+ return mailInboxMessageView ;
1382
+ } ;
1383
+
1384
+ t . isCalledNTimes ( "getCompoundKeyFromGridOrMessageView" , packageCtrl , 3 ) ;
1385
+ t . isCalledNTimes ( "getMailInboxMessageView" , packageCtrl , 1 ) ;
1386
+
1387
+ // return item from MailDesktopView's active MessageView
1388
+ t . expect ( SETKEY ) . toBe ( null ) ;
1389
+ packageCtrl . onMessageEditButtonClick ( ) ;
1390
+ t . expect ( SETKEY ) . toBe ( COMPOUNDKEY ) ;
1365
1391
1366
- t . isCalledOnce ( "getCompoundKeyFromGridOrMessageView" , packageCtrl ) ;
1367
1392
1393
+ // return MessageItem from MessageGrid
1394
+ packageCtrl . getMailMessageGrid = function ( ) {
1395
+ return FAKE_MAIL_MESSAGE_GRID ;
1396
+ } ;
1397
+ let selectionSpy = t . spyOn ( FAKE_MAIL_MESSAGE_GRID , "getSelection" ) ;
1398
+ activeTab = null ;
1399
+ SETKEY = null ;
1400
+ t . expect ( SETKEY ) . toBe ( null ) ;
1401
+ packageCtrl . onMessageEditButtonClick ( ) ;
1402
+ t . expect ( selectionSpy . calls . count ( ) ) . toBe ( 2 ) ;
1403
+ t . expect ( SETKEY ) . toBe ( COMPOUNDKEY ) ;
1404
+
1405
+ // selection = null
1406
+ // returns messageItem from MessageView embedded in MailInboxView
1407
+ SELECTION = null ;
1408
+ activeTab = null ;
1409
+ SETKEY = null ;
1368
1410
t . expect ( SETKEY ) . toBe ( null ) ;
1369
1411
packageCtrl . onMessageEditButtonClick ( ) ;
1412
+ t . expect ( selectionSpy . calls . count ( ) ) . toBe ( 3 ) ;
1370
1413
t . expect ( SETKEY ) . toBe ( COMPOUNDKEY ) ;
1371
1414
1415
+ selectionSpy . remove ( ) ;
1372
1416
} ) ;
1373
1417
} ) ;
1374
1418
@@ -1514,7 +1558,7 @@ StartTest(async t => {
1514
1558
} ) ;
1515
1559
1516
1560
1517
- t . it ( "getItemOrDraftFromActiveView ()" , t => {
1561
+ t . it ( "getDraftOrItemFromActiveView ()" , t => {
1518
1562
1519
1563
let ACTIVETAB = "" ;
1520
1564
@@ -1544,17 +1588,16 @@ StartTest(async t => {
1544
1588
messageDraft : 1
1545
1589
} ) ;
1546
1590
ACTIVETAB . getMessageDraft = function ( ) { return 1 ; } ;
1547
- t . expect ( packageCtrl . getItemOrDraftFromActiveView ( ) ) . toBe ( 1 ) ;
1548
-
1549
- ACTIVETAB = Ext . create ( "conjoon.cn_mail.view.mail.message.reader.MessageView" ) ;
1550
- ACTIVETAB . getMessageItem = function ( ) { return 2 ; } ;
1551
- t . expect ( packageCtrl . getItemOrDraftFromActiveView ( ) ) . toBe ( 2 ) ;
1591
+ t . expect ( packageCtrl . getDraftOrItemFromActiveView ( ) ) . toBe ( 1 ) ;
1552
1592
1553
- ACTIVETAB = 3 ;
1554
- t . expect ( packageCtrl . getItemOrDraftFromActiveView ( ) ) . toBe ( 4 ) ;
1593
+ const getItemFromGridOrMessageViewSpy = t . spyOn (
1594
+ packageCtrl , "getItemFromGridOrMessageView" ) . and . callFake ( ( ) => ( { } ) ) ;
1595
+ ACTIVETAB = { } ;
1596
+ t . expect ( packageCtrl . getDraftOrItemFromActiveView ( ) ) . toBe (
1597
+ getItemFromGridOrMessageViewSpy . calls . mostRecent ( ) . returnValue
1598
+ ) ;
1555
1599
1556
- ACTIVETAB = 4 ;
1557
- t . expect ( packageCtrl . getItemOrDraftFromActiveView ( ) ) . toBe ( null ) ;
1600
+ getItemFromGridOrMessageViewSpy . remove ( ) ;
1558
1601
} ) ;
1559
1602
1560
1603
@@ -1914,5 +1957,35 @@ StartTest(async t => {
1914
1957
1915
1958
} ) ;
1916
1959
1960
+ t . it ( "onMailMessageViewItemChange" , t => {
1961
+
1962
+ packageCtrl = Ext . create ( "conjoon.cn_mail.app.PackageController" ) ;
1963
+
1964
+ const contextSpy = t . spyOn ( packageCtrl , "disableMessageItemContextButtons" ) . and . callFake ( ( ) => { } ) ;
1965
+
1966
+ packageCtrl . onMailMessageViewItemChange ( { } , null ) ;
1967
+ t . expect ( contextSpy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( true ) ;
1968
+
1969
+ packageCtrl . onMailMessageViewItemChange ( { } , { } ) ;
1970
+ t . expect ( contextSpy . calls . count ( ) ) . toBe ( 1 ) ;
1971
+ } ) ;
1972
+
1973
+
1974
+ t . it ( "onMessageDeleteButtonClick" , t => {
1975
+
1976
+ packageCtrl = Ext . create ( "conjoon.cn_mail.app.PackageController" ) ;
1977
+
1978
+ let DRAFT = null ;
1979
+ const draftSpy = t . spyOn ( packageCtrl , "getDraftOrItemFromActiveView" ) . and . callFake ( ( ) => DRAFT ) ;
1980
+ const moveSpy = t . spyOn ( packageCtrl , "moveOrDeleteMessage" ) . and . callFake ( ( ) => { } ) ;
1981
+
1982
+ t . expect ( packageCtrl . onMessageDeleteButtonClick ( ) ) . toBeUndefined ( ) ;
1983
+ DRAFT = { } ;
1984
+ t . expect ( moveSpy . calls . count ( ) ) . toBe ( 0 ) ;
1985
+ t . expect ( packageCtrl . onMessageDeleteButtonClick ( ) ) . toBe ( true ) ;
1986
+ t . expect ( moveSpy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( DRAFT ) ;
1987
+ [ draftSpy , moveSpy ] . map ( spy => spy . remove ( ) ) ;
1988
+ } ) ;
1989
+
1917
1990
1918
1991
} ) ; } ) ; } ) ;
0 commit comments