~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/javascript/tests/test_subscription.js

  • Committer: Ian Booth
  • Date: 2011-04-19 15:10:57 UTC
  • mfrom: (12868 devel)
  • mto: This revision was merged to the branch mainline in revision 12983.
  • Revision ID: ian.booth@canonical.com-20110419151057-he56y6k29c4zeiyk
Merge from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
YUI({
2
2
    base: '../../../../canonical/launchpad/icing/yui/',
3
3
    filter: 'raw', combine: false, fetchCSS: false
4
 
    }).use('test', 'console', 'lp.bugs.subscription', function(Y) {
 
4
    }).use('test', 'console', 'lp.bugs.subscription', 'node-event-simulate',
 
5
           function(Y) {
5
6
 
6
7
var suite = new Y.Test.Suite("lp.bugs.subscription Tests");
7
8
var module = Y.lp.bugs.subscription;
8
9
 
9
10
/**
 
11
 * LPClient is taken from test_structural_subscription.js.
 
12
 * It maybe should be pushed to a shared test module.
 
13
 */
 
14
function LPClient(){
 
15
    if (!(this instanceof LPClient)) {
 
16
        throw new Error("Constructor called as a function");
 
17
    }
 
18
    this.received = [];
 
19
    // We create new functions every time because we allow them to be
 
20
    // configured.
 
21
    this.named_post = function(url, func, config) {
 
22
        this._call('named_post', config, arguments);
 
23
    };
 
24
    this.patch = function(bug_filter, data, config) {
 
25
        this._call('patch', config, arguments);
 
26
    };
 
27
}
 
28
LPClient.prototype._call = function(name, config, args) {
 
29
    this.received.push(
 
30
        [name, Array.prototype.slice.call(args)]);
 
31
    if (!Y.Lang.isValue(args.callee.args)) {
 
32
        throw new Error("Set call_args on "+name);
 
33
    }
 
34
    var do_action = function () {
 
35
        if (Y.Lang.isValue(args.callee.fail) && args.callee.fail) {
 
36
            config.on.failure.apply(undefined, args.callee.args);
 
37
        } else {
 
38
            config.on.success.apply(undefined, args.callee.args);
 
39
        }
 
40
    };
 
41
    if (Y.Lang.isValue(args.callee.halt) && args.callee.halt) {
 
42
        args.callee.resume = do_action;
 
43
    } else {
 
44
        do_action();
 
45
    }
 
46
};
 
47
 
 
48
/**
10
49
 * Test selection of the string by the number.
11
50
 * We expect to receive a plural string for all numbers
12
51
 * not equal to 1, and a singular string otherwise.
45
84
            something: 'nothing'
46
85
        };
47
86
        var cache = {};
48
 
        module._replace_textual_references(object, cache)
 
87
        module._replace_textual_references(object, cache);
49
88
        Y.Assert.areEqual('nothing', object.something);
50
89
    },
51
90
 
123
162
        var subs = module._gather_subscriptions_as_assignee(mock_category);
124
163
        Y.Assert.areEqual(1, subs.length);
125
164
        Y.Assert.areEqual(module._reasons.YOU_ASSIGNED, subs[0].reason);
 
165
        Y.Assert.areEqual(module._actions.CHANGE_ASSIGNEES, subs[0].action);
126
166
    },
127
167
 
128
168
    test_team_member: function() {
139
179
        Y.Assert.areEqual(module._reasons.TEAM_ASSIGNED, subs[0].reason);
140
180
        // And there is a 'team' variable containing the team object.
141
181
        Y.Assert.areEqual('my team', subs[0].vars.team);
 
182
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
142
183
    },
143
184
 
144
185
    test_team_member_multiple: function() {
158
199
        // And there is a 'teams' variable containing all the team objects.
159
200
        Y.ArrayAssert.itemsAreEqual(['team1', 'team2'],
160
201
                                    subs[0].vars.teams);
 
202
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
 
203
    },
 
204
 
 
205
    test_team_member_multiple_duplicate: function() {
 
206
        // As with the previous test, but we need to show that each team is
 
207
        // only represented once even if they are responsible for multiple
 
208
        // bug tasks.
 
209
        // We test with full-fledged objects to make sure they work with the
 
210
        // mechanism used to find dupes.
 
211
        var team1 = {display_name: 'team 1',
 
212
                     web_link: 'http://launchpad.net/~team1'},
 
213
            team2 = {display_name: 'team 2',
 
214
                     web_link: 'http://launchpad.net/~team2'},
 
215
            mock_category = {
 
216
                count: 2,
 
217
                personal: [],
 
218
                as_team_member: [{ principal: team1 },
 
219
                                 { principal: team2 },
 
220
                                 { principal: team2 }],
 
221
                as_team_admin: []
 
222
            },
 
223
            subs = module._gather_subscriptions_as_assignee(mock_category);
 
224
        Y.Assert.areEqual(1, subs.length);
 
225
        Y.Assert.areEqual(module._reasons.TEAMS_ASSIGNED, subs[0].reason);
 
226
        // And there is a 'teams' variable containing all the team objects.
 
227
        var teams_found = [];
 
228
        var index;
 
229
        for (index = 0; index < subs[0].vars.teams.length; index++) {
 
230
            teams_found.push(subs[0].vars.teams[index].title);
 
231
        }
 
232
        Y.ArrayAssert.itemsAreEqual(['team 1', 'team 2'], teams_found);
161
233
    },
162
234
 
163
235
    test_team_admin: function() {
167
239
            count: 1,
168
240
            personal: [],
169
241
            as_team_member: [],
170
 
            as_team_admin: [{ principal: 'my team' }],
 
242
            as_team_admin: [{ principal: 'my team' }]
171
243
        };
172
244
        var subs = module._gather_subscriptions_as_assignee(mock_category);
173
245
        Y.Assert.areEqual(1, subs.length);
175
247
            module._reasons.ADMIN_TEAM_ASSIGNED, subs[0].reason);
176
248
        // And there is a 'team' variable containing the team object.
177
249
        Y.Assert.areEqual('my team', subs[0].vars.team);
 
250
        Y.Assert.areEqual(module._actions.CHANGE_ASSIGNEES, subs[0].action);
178
251
    },
179
252
 
180
253
    test_team_admin_multiple: function() {
186
259
            personal: [],
187
260
            as_team_member: [],
188
261
            as_team_admin: [{ principal: 'team1'},
189
 
                             { principal: 'team2'}],
 
262
                             { principal: 'team2'}]
190
263
        };
191
264
        var subs = module._gather_subscriptions_as_assignee(mock_category);
192
265
        Y.Assert.areEqual(1, subs.length);
195
268
        // And there is a 'teams' variable containing all the team objects.
196
269
        Y.ArrayAssert.itemsAreEqual(['team1', 'team2'],
197
270
                                    subs[0].vars.teams);
 
271
        Y.Assert.areEqual(module._actions.CHANGE_ASSIGNEES, subs[0].action);
 
272
    },
 
273
 
 
274
    test_team_admin_multiple_duplicate: function() {
 
275
        // As with the previous test, but we need to show that each team is
 
276
        // only represented once even if they are responsible for multiple
 
277
        // bug tasks.
 
278
        // We test with full-fledged objects to make sure they work with the
 
279
        // mechanism used to find dupes.
 
280
        var team1 = {display_name: 'team 1',
 
281
                     web_link: 'http://launchpad.net/~team1'},
 
282
            team2 = {display_name: 'team 2',
 
283
                     web_link: 'http://launchpad.net/~team2'},
 
284
            mock_category = {
 
285
                count: 2,
 
286
                personal: [],
 
287
                as_team_admin: [{ principal: team1 },
 
288
                                { principal: team2 },
 
289
                                { principal: team2 }],
 
290
                as_team_member: []
 
291
            },
 
292
            subs = module._gather_subscriptions_as_assignee(mock_category);
 
293
        Y.Assert.areEqual(1, subs.length);
 
294
        // And there is a 'teams' variable containing all the team objects.
 
295
        var teams_found = [];
 
296
        for (index = 0; index < subs[0].vars.teams.length; index++) {
 
297
            teams_found.push(subs[0].vars.teams[index].title);
 
298
        }
 
299
        Y.ArrayAssert.itemsAreEqual(['team 1', 'team 2'], teams_found);
198
300
    },
199
301
 
200
302
    test_combined: function() {
204
306
            count: 3,
205
307
            personal: [{}],
206
308
            as_team_member: [{ principal: 'users' }],
207
 
            as_team_admin: [{ principal: 'admins' }],
 
309
            as_team_admin: [{ principal: 'admins' }]
208
310
        };
209
311
        var subs = module._gather_subscriptions_as_assignee(mock_category);
210
312
        Y.Assert.areEqual(3, subs.length);
218
320
            as_team_member: [
219
321
                { principal: { display_name: 'My team',
220
322
                               web_link: 'http://link' } }],
221
 
            as_team_admin: [],
 
323
            as_team_admin: []
222
324
        };
223
325
        var subs = module._gather_subscriptions_as_assignee(mock_category);
224
326
        Y.Assert.areEqual('My team', subs[0].vars.team.title);
225
327
        Y.Assert.areEqual('http://link', subs[0].vars.team.url);
226
 
    },
 
328
    }
227
329
}));
228
330
 
229
331
/**
259
361
        Y.Assert.areEqual(1, subs.length);
260
362
        Y.Assert.areEqual(module._reasons.YOU_OWNER, subs[0].reason);
261
363
        Y.Assert.areEqual('project', subs[0].vars.pillar);
 
364
        Y.Assert.areEqual(module._actions.SET_BUG_SUPERVISOR, subs[0].action);
262
365
    },
263
366
 
264
367
    test_personal_multiple: function() {
267
370
        // supervisor.
268
371
        var mock_category = {
269
372
            count: 2,
270
 
            personal: [{pillar: 'project'}, {pillar: 'distro'}],
 
373
            personal: [ {pillar: {title: 'project'} },
 
374
                        {pillar: {title:'distro'} }],
271
375
            as_team_member: [],
272
376
            as_team_admin: []
273
377
        };
291
395
        // And there is a 'team' variable containing the team object.
292
396
        Y.Assert.areEqual('my team', subs[0].vars.team);
293
397
        Y.Assert.areEqual('project', subs[0].vars.pillar);
 
398
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
294
399
    },
295
400
 
296
401
    test_team_member_multiple: function() {
301
406
            count: 2,
302
407
            personal: [],
303
408
            as_team_member: [{ principal: 'team1',
304
 
                               pillar: 'project' },
 
409
                               pillar: {display_name: 'project'} },
305
410
                             { principal: 'team2',
306
 
                               pillar: 'distro' }],
 
411
                               pillar: {display_name: 'distro'} }],
307
412
            as_team_admin: []
308
413
        };
309
414
        var subs = module._gather_subscriptions_as_supervisor(mock_category);
318
423
            personal: [],
319
424
            as_team_member: [],
320
425
            as_team_admin: [{ principal: 'my team',
321
 
                              pillar: 'project' }],
 
426
                              pillar: 'project' }]
322
427
        };
323
428
        var subs = module._gather_subscriptions_as_supervisor(mock_category);
324
429
        Y.Assert.areEqual(1, subs.length);
327
432
        // And there is a 'team' variable containing the team object.
328
433
        Y.Assert.areEqual('my team', subs[0].vars.team);
329
434
        Y.Assert.areEqual('project', subs[0].vars.pillar);
 
435
        Y.Assert.areEqual(module._actions.SET_BUG_SUPERVISOR, subs[0].action);
330
436
    },
331
437
 
332
438
    test_team_admin_multiple: function() {
338
444
            personal: [],
339
445
            as_team_member: [],
340
446
            as_team_admin: [{ principal: 'team1',
341
 
                               pillar: 'project' },
342
 
                             { principal: 'team2',
343
 
                               pillar: 'distro' }]
 
447
                              pillar: {display_name: 'project'} },
 
448
                            { principal: 'team2',
 
449
                              pillar: {display_name: 'distro'} }]
344
450
        };
345
451
        var subs = module._gather_subscriptions_as_supervisor(mock_category);
346
452
        Y.Assert.areEqual(2, subs.length);
347
453
    },
348
454
 
 
455
    test_repeated_pillars: function() {
 
456
        // Different bug tasks might still be on the same pillar,
 
457
        // and we should only get one action.
 
458
        var mock_pillar = { display_name: 'project',
 
459
                            web_link: 'http://project/' };
 
460
        var mock_category = {
 
461
            count: 1,
 
462
            personal: [{pillar: mock_pillar},
 
463
                       {pillar: mock_pillar}],
 
464
            as_team_member: [],
 
465
            as_team_admin: []
 
466
        };
 
467
        var subs = module._gather_subscriptions_as_supervisor(mock_category);
 
468
        Y.Assert.areEqual(1, subs.length);
 
469
        Y.Assert.areEqual(module._reasons.YOU_OWNER, subs[0].reason);
 
470
        Y.Assert.areEqual(mock_pillar, subs[0].vars.pillar.self);
 
471
        Y.Assert.areEqual(module._actions.SET_BUG_SUPERVISOR, subs[0].action);
 
472
    },
 
473
 
349
474
    test_combined: function() {
350
475
        // Test that multiple implicit bug supervisor roles
351
476
        // are all returned.
353
478
            count: 3,
354
479
            personal: [{pillar: 'project1'}],
355
480
            as_team_member: [{ principal: 'users', pillar: 'project2' }],
356
 
            as_team_admin: [{ principal: 'admins', pillar: 'distro' }],
 
481
            as_team_admin: [{ principal: 'admins', pillar: 'distro' }]
357
482
        };
358
483
        var subs = module._gather_subscriptions_as_assignee(mock_category);
359
484
        Y.Assert.areEqual(3, subs.length);
371
496
                pillar: { display_name: 'My project',
372
497
                          web_link: 'http://project/' }
373
498
            }],
374
 
            as_team_admin: [],
 
499
            as_team_admin: []
375
500
        };
376
501
        var subs = module._gather_subscriptions_as_supervisor(mock_category);
377
502
        Y.Assert.areEqual('My team', subs[0].vars.team.title);
379
504
 
380
505
        Y.Assert.areEqual('My project', subs[0].vars.pillar.title);
381
506
        Y.Assert.areEqual('http://project/', subs[0].vars.pillar.url);
382
 
    },
 
507
    }
383
508
}));
384
509
 
385
510
/**
415
540
        Y.Assert.areEqual(
416
541
            module._reasons.YOU_SUBSCRIBED_TO_DUPLICATE, subs[0].reason);
417
542
        Y.Assert.areEqual('dupe bug', subs[0].vars.duplicate_bug);
 
543
        Y.Assert.areEqual(module._actions.UNSUBSCRIBE_DUPLICATES,
 
544
                          subs[0].action);
418
545
    },
419
546
 
420
547
    test_personal_multiple: function() {
433
560
            module._reasons.YOU_SUBSCRIBED_TO_DUPLICATES, subs[0].reason);
434
561
        Y.ArrayAssert.itemsAreEqual(
435
562
            ['dupe1', 'dupe2'], subs[0].vars.duplicate_bugs);
 
563
        Y.Assert.areEqual(module._actions.UNSUBSCRIBE_DUPLICATES,
 
564
                          subs[0].action);
436
565
    },
437
566
 
438
567
    test_team_member: function() {
453
582
        Y.Assert.areEqual('my team', subs[0].vars.team);
454
583
        // And a 'duplicate_bug' variable pointing to the dupe.
455
584
        Y.Assert.areEqual('dupe', subs[0].vars.duplicate_bug);
 
585
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
456
586
    },
457
587
 
458
588
    test_team_member_multiple_bugs: function() {
480
610
        // And a 'duplicate_bugs' variable with the list of dupes.
481
611
        Y.ArrayAssert.itemsAreEqual(
482
612
            ['dupe1', 'dupe2'], subs[0].vars.duplicate_bugs);
 
613
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
483
614
    },
484
615
 
485
616
    test_team_member_multiple: function() {
520
651
        Y.Assert.areEqual('my team', subs[0].vars.team);
521
652
        // And a 'duplicate_bug' variable pointing to the dupe.
522
653
        Y.Assert.areEqual('dupe', subs[0].vars.duplicate_bug);
 
654
        Y.Assert.areEqual(module._actions.UNSUBSCRIBE_DUPLICATES,
 
655
                          subs[0].action);
523
656
    },
524
657
 
525
658
    test_team_admin_multiple_bugs: function() {
548
681
        // And a 'duplicate_bugs' variable with the list of dupes.
549
682
        Y.ArrayAssert.itemsAreEqual(
550
683
            ['dupe1', 'dupe2'], subs[0].vars.duplicate_bugs);
 
684
        Y.Assert.areEqual(module._actions.UNSUBSCRIBE_DUPLICATES,
 
685
                          subs[0].action);
551
686
    },
552
687
 
553
688
    test_team_admin_multiple: function() {
560
695
            as_team_admin: [{ principal: 'team1',
561
696
                               bug: 'dupe1' },
562
697
                             { principal: 'team2',
563
 
                               bug: 'dupe1' }],
 
698
                               bug: 'dupe1' }]
564
699
        };
565
700
 
566
701
        // Result is two separate subscription records.
581
716
                bug: { id: 1,
582
717
                       web_link: 'http://launchpad/bug/1' }
583
718
            }],
584
 
            as_team_admin: [],
 
719
            as_team_admin: []
585
720
        };
586
721
        var subs = module._gather_subscriptions_from_duplicates(
587
722
            mock_category);
591
726
        Y.Assert.areEqual('#1', subs[0].vars.duplicate_bug.title);
592
727
        Y.Assert.areEqual(
593
728
            'http://launchpad/bug/1', subs[0].vars.duplicate_bug.url);
594
 
    },
 
729
    }
595
730
}));
596
731
 
597
732
/**
639
774
        Y.Assert.areEqual(module._reasons.TEAM_SUBSCRIBED, subs[0].reason);
640
775
        // And there is a 'team' variable containing the team object.
641
776
        Y.Assert.areEqual('my team', subs[0].vars.team);
 
777
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
642
778
    },
643
779
 
644
780
    test_team_member_multiple: function() {
656
792
        // And there is a 'teams' variable containing all the team objects.
657
793
        Y.ArrayAssert.itemsAreEqual(['team1', 'team2'],
658
794
                                    subs[0].vars.teams);
 
795
        Y.Assert.areEqual(module._actions.CONTACT_TEAMS, subs[0].action);
 
796
    },
 
797
 
 
798
    test_team_member_multiple_duplicate: function() {
 
799
        // As with the previous test, but we need to show that each team is
 
800
        // only represented once even if they are responsible for multiple
 
801
        // bug tasks.
 
802
        // We test with full-fledged objects to make sure they work with the
 
803
        // mechanism used to find dupes.
 
804
        var team1 = {display_name: 'team 1',
 
805
                     web_link: 'http://launchpad.net/~team1'},
 
806
            team2 = {display_name: 'team 2',
 
807
                     web_link: 'http://launchpad.net/~team2'},
 
808
            mock_category = {
 
809
                count: 2,
 
810
                personal: [],
 
811
                as_team_member: [{ principal: team1 },
 
812
                                 { principal: team2 },
 
813
                                 { principal: team2 }],
 
814
                as_team_admin: []
 
815
            },
 
816
            subs = module._gather_subscriptions_through_team(mock_category);
 
817
        Y.Assert.areEqual(1, subs.length);
 
818
        // And there is a 'teams' variable containing all the team objects.
 
819
        var teams_found = [];
 
820
        for (index = 0; index < subs[0].vars.teams.length; index++) {
 
821
            teams_found.push(subs[0].vars.teams[index].title);
 
822
        }
 
823
        Y.ArrayAssert.itemsAreEqual(['team 1', 'team 2'], teams_found);
659
824
    },
660
825
 
661
826
    test_team_admin: function() {
664
829
            count: 1,
665
830
            personal: [],
666
831
            as_team_member: [],
667
 
            as_team_admin: [{ principal: 'my team' }],
 
832
            as_team_admin: [{ principal: 'my team' }]
668
833
        };
669
834
        var subs = module._gather_subscriptions_through_team(mock_category);
670
835
        Y.Assert.areEqual(1, subs.length);
672
837
            module._reasons.ADMIN_TEAM_SUBSCRIBED, subs[0].reason);
673
838
        // And there is a 'team' variable containing the team object.
674
839
        Y.Assert.areEqual('my team', subs[0].vars.team);
 
840
        Y.Assert.areEqual(module._actions.CHANGE_TEAM_SUBSCRIPTIONS,
 
841
                          subs[0].action);
675
842
    },
676
843
 
677
844
    test_team_admin_multiple: function() {
681
848
            personal: [],
682
849
            as_team_member: [],
683
850
            as_team_admin: [{ principal: 'team1'},
684
 
                             { principal: 'team2'}],
 
851
                             { principal: 'team2'}]
685
852
        };
686
853
        var subs = module._gather_subscriptions_through_team(mock_category);
687
854
        Y.Assert.areEqual(1, subs.length);
690
857
        // And there is a 'teams' variable containing all the team objects.
691
858
        Y.ArrayAssert.itemsAreEqual(['team1', 'team2'],
692
859
                                    subs[0].vars.teams);
 
860
        Y.Assert.areEqual(module._actions.CHANGE_TEAM_SUBSCRIPTIONS,
 
861
                          subs[0].action);
 
862
    },
 
863
 
 
864
    test_team_admin_multiple_duplicate: function() {
 
865
        // As with the previous test, but we need to show that each team is
 
866
        // only represented once even if they are responsible for multiple
 
867
        // bug tasks.
 
868
        // We test with full-fledged objects to make sure they work with the
 
869
        // mechanism used to find dupes.
 
870
        var team1 = {display_name: 'team 1',
 
871
                     web_link: 'http://launchpad.net/~team1'},
 
872
            team2 = {display_name: 'team 2',
 
873
                     web_link: 'http://launchpad.net/~team2'},
 
874
            mock_category = {
 
875
                count: 2,
 
876
                personal: [],
 
877
                as_team_admin: [{ principal: team1 },
 
878
                                { principal: team2 },
 
879
                                { principal: team2 }],
 
880
                as_team_member: []
 
881
            },
 
882
            subs = module._gather_subscriptions_through_team(mock_category);
 
883
        Y.Assert.areEqual(1, subs.length);
 
884
        // And there is a 'teams' variable containing all the team objects.
 
885
        var teams_found = [];
 
886
        for (index = 0; index < subs[0].vars.teams.length; index++) {
 
887
            teams_found.push(subs[0].vars.teams[index].title);
 
888
        }
 
889
        Y.ArrayAssert.itemsAreEqual(['team 1', 'team 2'], teams_found);
693
890
    },
694
891
 
695
892
    test_combined: function() {
700
897
            count: 3,
701
898
            personal: [{}],
702
899
            as_team_member: [{ principal: 'users' }],
703
 
            as_team_admin: [{ principal: 'admins' }],
 
900
            as_team_admin: [{ principal: 'admins' }]
704
901
        };
705
902
        var subs = module._gather_subscriptions_through_team(mock_category);
706
903
        Y.Assert.areEqual(2, subs.length);
714
911
            as_team_member: [
715
912
                { principal: { display_name: 'My team',
716
913
                               web_link: 'http://link' } }],
717
 
            as_team_admin: [],
 
914
            as_team_admin: []
718
915
        };
719
916
        var subs = module._gather_subscriptions_through_team(mock_category);
720
917
        Y.Assert.areEqual('My team', subs[0].vars.team.title);
721
918
        Y.Assert.areEqual('http://link', subs[0].vars.team.url);
722
 
    },
 
919
    }
723
920
}));
724
921
 
725
922
 
801
998
        // The direct subscription is muted.
802
999
        var info = {
803
1000
            direct: _constructCategory(['direct']),
804
 
            muted: true,
 
1001
            muted: true
805
1002
        };
806
1003
        info.count = info.direct.count;
807
1004
        Y.Assert.areSame(
813
1010
        // The simple direct subscription.
814
1011
        var sub = {
815
1012
            bug: {
816
 
                private: false,
817
 
                security_related: false,
 
1013
                //private: false, // JSLint complains
 
1014
                security_related: false
818
1015
            },
819
 
            principal_is_reporter: false,
 
1016
            principal_is_reporter: false
820
1017
        };
 
1018
        sub.bug['private'] = false;
821
1019
        var info = {
822
1020
            direct: _constructCategory([sub]),
823
1021
            count: 1
832
1030
        // The direct subscription created for bug reporter.
833
1031
        var sub = {
834
1032
            bug: {},
835
 
            principal_is_reporter: true,
 
1033
            principal_is_reporter: true
836
1034
        };
837
1035
        var info = {
838
1036
            direct: _constructCategory([sub]),
848
1046
        // the bug supervisor.
849
1047
        var sub = {
850
1048
            bug: {
851
 
                private: true,
852
 
            },
 
1049
                //private: true //JSLint complains
 
1050
            }
853
1051
        };
 
1052
        sub.bug['private'] = true;
854
1053
        var info = {
855
1054
            direct: _constructCategory([sub]),
856
1055
            count: 1
864
1063
        // The simple direct subscription.
865
1064
        var sub = {
866
1065
            bug: {
867
 
                security_related: true,
868
 
            },
 
1066
                security_related: true
 
1067
            }
869
1068
        };
870
1069
        var info = {
871
1070
            direct: _constructCategory([sub]),
874
1073
        Y.Assert.areSame(
875
1074
            module._reasons.YOU_SUBSCRIBED_SECURITY_CONTACT,
876
1075
            module._get_direct_subscription_information(info));
877
 
    },
 
1076
    }
878
1077
 
879
1078
}));
880
1079
 
945
1144
        Y.Assert.areNotEqual(
946
1145
            '<a href="' + url + '">Title</a>',
947
1146
            module._get_objectlink_html(link));
948
 
    },
 
1147
    }
949
1148
 
950
1149
}));
951
1150
 
1057
1256
        Y.Assert.areEqual(
1058
1257
            'test string with <a href="http://link/">extras</a>',
1059
1258
            module._safely_render_description(sub, extra_vars));
1060
 
    },
 
1259
    }
1061
1260
 
1062
1261
}));
1063
1262
 
1093
1292
            'direct-subscription', node.get('id'));
1094
1293
        Y.Assert.areEqual(
1095
1294
            expected_text, node.get('text'));
1096
 
    },
 
1295
    }
1097
1296
 
1098
1297
}));
1099
1298
 
1105
1304
 
1106
1305
    test_simple_text: function() {
1107
1306
        // A simple subscription with 'Text' as the reason and no variables.
1108
 
        var sub = { reason: 'Text', vars: {} };
 
1307
        var sub = { reason: 'Text', vars: {}, action: function() {} };
1109
1308
        var node = module._get_single_description_node(sub);
1110
1309
 
1111
1310
        // The node has appropriate CSS class set.
1120
1319
        // A subscription with variables and extra variables
1121
1320
        // has them replaced.
1122
1321
        var sub = { reason: 'Test {var1} {var2}',
1123
 
                    vars: { var1: 'my text'} };
 
1322
                    vars: { var1: 'my text'},
 
1323
                    action: function() {} };
1124
1324
        var extra_data = { var2: 'globally' };
1125
1325
        var node = module._get_single_description_node(sub, extra_data);
1126
1326
 
1130
1330
        // There is also a sub-node containing the actual description.
1131
1331
        var subnode = node.one('.description-text');
1132
1332
        Y.Assert.areEqual('Test my text globally', subnode.get('text'));
1133
 
    },
 
1333
    }
1134
1334
 
1135
1335
}));
1136
1336
 
1149
1349
            as_owner: _constructCategory(),
1150
1350
            count: 1
1151
1351
        };
 
1352
        window.LP = { cache: {} };
1152
1353
        Y.Assert.areSame(
1153
1354
            undefined,
1154
1355
            module._get_other_descriptions_node(info));
 
1356
        delete window.LP;
1155
1357
    },
1156
1358
 
1157
1359
    test_one_subscription: function() {
1163
1365
            as_owner: _constructCategory(),
1164
1366
            count: 1
1165
1367
        };
 
1368
        window.LP = { links: { me: '~' } };
1166
1369
 
1167
1370
        // A node is returned with ID of 'other-subscriptions'.
1168
1371
        var node = module._get_other_descriptions_node(info);
1171
1374
        // And it contains single '.subscription-description' node.
1172
1375
        Y.Assert.areEqual(
1173
1376
            1, node.all('.subscription-description').size());
 
1377
        delete window.LP;
1174
1378
    },
1175
1379
 
1176
1380
    test_multiple_subscription: function() {
1183
1387
            as_owner: _constructCategory(),
1184
1388
            count: 1
1185
1389
        };
 
1390
        window.LP = { cache: { context: { web_link: '/' } },
 
1391
                      links: { me: '~' } };
1186
1392
 
1187
1393
        // A node is returned containing two
1188
1394
        // '.subscription-description' nodes.
1189
1395
        var node = module._get_other_descriptions_node(info);
1190
1396
        Y.Assert.areEqual(
1191
1397
            2, node.all('.subscription-description').size());
1192
 
    },
 
1398
        delete window.LP;
 
1399
    },
 
1400
 
 
1401
    test_no_direct_has_structural_subscriptions: function() {
 
1402
        // With no non-personal subscriptions, and a structural
 
1403
        // subscription, the node is still constructed because
 
1404
        // structural subscriptions go there as well.
 
1405
        var info = {
 
1406
            direct: _constructCategory([{ bug: {} }]),
 
1407
            from_duplicate: _constructCategory(),
 
1408
            as_assignee: _constructCategory(),
 
1409
            as_owner: _constructCategory(),
 
1410
            count: 1
 
1411
        };
 
1412
        window.LP = { cache: { subscription_info: ['1'] } };
 
1413
        Y.Assert.isNotUndefined(
 
1414
            module._get_other_descriptions_node(info));
 
1415
        delete window.LP;
 
1416
    },
 
1417
 
 
1418
    test_header: function() {
 
1419
        // There is a subscription on the duplicate bug.
 
1420
        var info = {
 
1421
            direct: _constructCategory(),
 
1422
            from_duplicate: _constructCategory([{ bug: {id: 1} }]),
 
1423
            as_assignee: _constructCategory(),
 
1424
            as_owner: _constructCategory(),
 
1425
            count: 1
 
1426
        };
 
1427
 
 
1428
        window.LP = { links: { me: '~' } };
 
1429
 
 
1430
        // A returned node contains the 'other-subscriptions-header'
 
1431
        // div with the link.
 
1432
        var node = module._get_other_descriptions_node(info);
 
1433
        var header = node.one('#other-subscriptions-header');
 
1434
        Y.Assert.isNotUndefined(header);
 
1435
        var link = header.one('a');
 
1436
        Y.Assert.areEqual('Other subscriptions', link.get('text'));
 
1437
 
 
1438
        delete window.LP;
 
1439
    },
 
1440
 
 
1441
    test_header_slideout: function() {
 
1442
        // Clicking on the header slides-out the box, and
 
1443
        // clicking it again slides it back in.
 
1444
        var info = {
 
1445
            direct: _constructCategory(),
 
1446
            from_duplicate: _constructCategory([{ bug: {id: 1} }]),
 
1447
            as_assignee: _constructCategory(),
 
1448
            as_owner: _constructCategory(),
 
1449
            count: 1
 
1450
        };
 
1451
 
 
1452
        window.LP = { links: { me: '~' } };
 
1453
 
 
1454
        // A returned node contains the 'other-subscriptions-header'
 
1455
        // div with the link.
 
1456
        var node = module._get_other_descriptions_node(info);
 
1457
        var link = node.one('#other-subscriptions-header a');
 
1458
        var list = node.one('#other-subscriptions-list');
 
1459
 
 
1460
        // Initially, the list is hidden.
 
1461
        Y.Assert.isTrue(link.hasClass('treeCollapsed'));
 
1462
        Y.Assert.isTrue(list.hasClass('lazr-closed'));
 
1463
        Y.Assert.areEqual('none', list.getStyle('display'));
 
1464
 
 
1465
        // Clicking the link slides out the list of other subscriptions.
 
1466
        Y.Event.simulate(Y.Node.getDOMNode(link), 'click');
 
1467
        this.wait(function() {
 
1468
            Y.Assert.isFalse(link.hasClass('treeCollapsed'));
 
1469
            Y.Assert.isTrue(link.hasClass('treeExpanded'));
 
1470
            Y.Assert.isFalse(list.hasClass('lazr-closed'));
 
1471
            Y.Assert.areNotEqual('none', list.getStyle('display'));
 
1472
 
 
1473
            // Clicking it again, slides it back in.
 
1474
            // It has to be nested inside 'wait' because we need
 
1475
            // to wait for the first click to "finish".
 
1476
            Y.Event.simulate(Y.Node.getDOMNode(link), 'click');
 
1477
 
 
1478
            this.wait(function() {
 
1479
                Y.Assert.isTrue(link.hasClass('treeCollapsed'));
 
1480
                Y.Assert.isFalse(link.hasClass('treeExpanded'));
 
1481
                Y.Assert.isTrue(list.hasClass('lazr-closed'));
 
1482
                delete window.LP;
 
1483
            }, 500);
 
1484
        }, 500);
 
1485
    }
1193
1486
 
1194
1487
}));
1195
1488
 
1205
1498
        this.parent_node = Y.one('#test-root');
1206
1499
        this.parent_node.appendChild(this.content_node);
1207
1500
        this.config = {
1208
 
            description_box: '#description-container',
 
1501
            description_box: '#description-container'
1209
1502
        };
1210
1503
    },
1211
1504
 
1225
1518
            bug_id: 1,
1226
1519
            count: 0
1227
1520
        };
1228
 
        window.LP = {};
 
1521
        window.LP = { cache: {} };
1229
1522
        module.show_subscription_description(this.config);
1230
1523
        this.wait(function() {
1231
1524
            Y.Assert.areEqual(
1233
1526
            Y.Assert.areEqual(
1234
1527
                0, this.content_node.all('#other-subscriptions').size());
1235
1528
        }, 50);
 
1529
        delete window.LP;
1236
1530
    },
1237
1531
 
1238
1532
    test_combined_subscriptions: function() {
1246
1540
            bug_id: 1,
1247
1541
            count: 0
1248
1542
        };
1249
 
        window.LP = {};
 
1543
        window.LP = { cache: { context: { web_link: '/' } },
 
1544
                      links: { me: '~' } };
1250
1545
        module.show_subscription_description(this.config);
1251
1546
        this.wait(function() {
1252
1547
            Y.Assert.areEqual(
1253
1548
                1, this.content_node.all('#direct-subscription').size());
1254
1549
            Y.Assert.areEqual(
1255
1550
                1, this.content_node.all('#other-subscriptions').size());
 
1551
            delete window.LP;
1256
1552
        }, 50);
1257
1553
    },
1258
1554
 
1277
1573
        Y.Assert.areEqual(
1278
1574
            'value',
1279
1575
            this.config.subscription_info.reference);
1280
 
    },
 
1576
        delete window.LP;
 
1577
    }
 
1578
 
 
1579
}));
 
1580
 
 
1581
/**
 
1582
 * Test for helper method to construct actions text and subscriptions list
 
1583
 * for duplicate subscriptions:
 
1584
 *   get_unsubscribe_duplicates_text_and_subscriptions()
 
1585
 */
 
1586
suite.add(new Y.Test.Case({
 
1587
    name: 'Test duplicate actions text and subscriptions list.',
 
1588
 
 
1589
    _should: {
 
1590
        error: {
 
1591
            test_multiple_teams_fails:
 
1592
            new Error('We can only unsubscribe a single team from ' +
 
1593
                      'multiple duplicate bugs.')
 
1594
        }
 
1595
    },
 
1596
 
 
1597
    setUp: function() {
 
1598
        window.LP = { cache: { context: { web_link: 'http://test/' } },
 
1599
                      links: { me: '~' } };
 
1600
    },
 
1601
 
 
1602
    tearDown: function() {
 
1603
        delete window.LP;
 
1604
    },
 
1605
 
 
1606
    test_yourself_single_bug: function() {
 
1607
        // There is a single duplicate bug you are subscribed to.
 
1608
        var args = { bugs: [ { self: { self_link: 'http://bug/' } } ] };
 
1609
        var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
 
1610
            args);
 
1611
        Y.Assert.areEqual('Unsubscribe yourself from the duplicate',
 
1612
                          data.text);
 
1613
        Y.Assert.areEqual(1, data.subscriptions.length);
 
1614
        var sub = data.subscriptions[0];
 
1615
        Y.Assert.areEqual(window.LP.links.me, sub.subscriber);
 
1616
        Y.Assert.areEqual('http://bug/', sub.bug);
 
1617
    },
 
1618
 
 
1619
    test_yourself_multiple_bug: function() {
 
1620
        // There is a single duplicate bug you are subscribed to.
 
1621
        var args = { bugs: [ { self: { self_link: 'http://bug1/' } },
 
1622
                             { self: { self_link: 'http://bug2/' } }] };
 
1623
        var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
 
1624
            args);
 
1625
        Y.Assert.areEqual('Unsubscribe yourself from all duplicates',
 
1626
                          data.text);
 
1627
        Y.Assert.areEqual(2, data.subscriptions.length);
 
1628
        var sub = data.subscriptions[0];
 
1629
        Y.Assert.areEqual(window.LP.links.me, sub.subscriber);
 
1630
        Y.Assert.areEqual('http://bug1/', sub.bug);
 
1631
 
 
1632
        sub = data.subscriptions[1];
 
1633
        Y.Assert.areEqual(window.LP.links.me, sub.subscriber);
 
1634
        Y.Assert.areEqual('http://bug2/', sub.bug);
 
1635
    },
 
1636
 
 
1637
    test_team_single_bug: function() {
 
1638
        // There is a single duplicate bug you are subscribed to.
 
1639
        var args = { bugs: [ { self: { self_link: 'http://bug/' } } ],
 
1640
                     teams: [ { self: { self_link: 'http://team/' } } ] };
 
1641
        var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
 
1642
            args);
 
1643
        Y.Assert.areEqual('Unsubscribe this team from the duplicate',
 
1644
                          data.text);
 
1645
        Y.Assert.areEqual(1, data.subscriptions.length);
 
1646
        var sub = data.subscriptions[0];
 
1647
        Y.Assert.areEqual('http://team/', sub.subscriber);
 
1648
        Y.Assert.areEqual('http://bug/', sub.bug);
 
1649
    },
 
1650
 
 
1651
    test_team_multiple_bugs: function() {
 
1652
        // There is a single duplicate bug you are subscribed to.
 
1653
        var args = { bugs: [ { self: { self_link: 'http://bug1/' } },
 
1654
                             { self: { self_link: 'http://bug2/' } }],
 
1655
                     teams: [ { self: { self_link: 'http://team/' } } ] };
 
1656
        var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
 
1657
            args);
 
1658
        Y.Assert.areEqual('Unsubscribe this team from all duplicates',
 
1659
                          data.text);
 
1660
        Y.Assert.areEqual(2, data.subscriptions.length);
 
1661
        var sub = data.subscriptions[0];
 
1662
        Y.Assert.areEqual('http://team/', sub.subscriber);
 
1663
        Y.Assert.areEqual('http://bug1/', sub.bug);
 
1664
 
 
1665
        sub = data.subscriptions[1];
 
1666
        Y.Assert.areEqual('http://team/', sub.subscriber);
 
1667
        Y.Assert.areEqual('http://bug2/', sub.bug);
 
1668
    },
 
1669
 
 
1670
    test_multiple_teams_fails: function() {
 
1671
        // There is a single duplicate bug you are subscribed to.
 
1672
        var args = { bugs: [ { self: { self_link: 'http://bug/' } } ],
 
1673
                     teams: [ { self: { self_link: 'http://team1/' } },
 
1674
                              { self: { self_link: 'http://team2/' } }] };
 
1675
        var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
 
1676
            args);
 
1677
    }
 
1678
 
 
1679
}));
 
1680
 
 
1681
/**
 
1682
 * Test for helper method to get modified object links:
 
1683
 *   add_url_element_to_links()
 
1684
 */
 
1685
suite.add(new Y.Test.Case({
 
1686
    name: 'Test add_url_element_to_links helper.',
 
1687
 
 
1688
    compare_object_links: function (first, second) {
 
1689
        return first.title === second.title &&
 
1690
               first.url === second.url &&
 
1691
               first.self === second.self;
 
1692
    },
 
1693
 
 
1694
    test_single_link: function () {
 
1695
        var self = 'object stand-in',
 
1696
            original = {
 
1697
                title: 'Rutebega',
 
1698
                url: 'http://example.net/kumquat',
 
1699
                self: self
 
1700
            },
 
1701
            modified = module._add_url_element_to_links(
 
1702
                [original], '/avocado');
 
1703
        Y.ArrayAssert.itemsAreEquivalent(
 
1704
            [{title: 'Rutebega',
 
1705
              url: 'http://example.net/kumquat/avocado',
 
1706
              self: self}],
 
1707
            modified,
 
1708
            this.compare_object_links);
 
1709
        // The original was not modified.
 
1710
        Y.Assert.areEqual(original.url, 'http://example.net/kumquat');
 
1711
    },
 
1712
 
 
1713
    test_multiple_link: function () {
 
1714
        var self1 = 'object stand-in 1',
 
1715
            original1 = {
 
1716
                title: 'Rutebega',
 
1717
                url: 'http://example.net/kumquat',
 
1718
                self: self1
 
1719
            },
 
1720
            self2 = 'object stand-in 2',
 
1721
            original2 = {
 
1722
                title: 'Shazam',
 
1723
                url: 'http://example.net/abracadabra',
 
1724
                self: self2
 
1725
            },
 
1726
            modified = module._add_url_element_to_links(
 
1727
                [original1, original2], '/avocado');
 
1728
        Y.ArrayAssert.itemsAreEquivalent(
 
1729
            [{title: 'Rutebega',
 
1730
              url: 'http://example.net/kumquat/avocado',
 
1731
              self: self1},
 
1732
             {title: 'Shazam',
 
1733
              url: 'http://example.net/abracadabra/avocado',
 
1734
              self: self2}],
 
1735
            modified,
 
1736
            this.compare_object_links);
 
1737
        // The originals were not modified.
 
1738
        Y.Assert.areEqual(original1.url, 'http://example.net/kumquat');
 
1739
        Y.Assert.areEqual(original2.url, 'http://example.net/abracadabra');
 
1740
    }
 
1741
 
 
1742
}));
 
1743
 
 
1744
/**
 
1745
 * Test for helper method to construct action "unsubscribe" node:
 
1746
 *   get_node_for_unsubscribing()
 
1747
 */
 
1748
suite.add(new Y.Test.Case({
 
1749
    name: 'Test duplicate actions text and subscriptions list.',
 
1750
 
 
1751
    setUp: function () {
 
1752
        module._lp_client = new LPClient();
 
1753
        this.wrapper_node = Y.Node.create(
 
1754
            '<div class="subscription-description"></div>');
 
1755
        Y.one('body').appendChild(this.wrapper_node);
 
1756
    },
 
1757
 
 
1758
    tearDown: function () {
 
1759
        delete module._lp_client;
 
1760
        this.wrapper_node.remove();
 
1761
        var error_overlay = Y.one('.yui3-lazr-formoverlay');
 
1762
        if (Y.Lang.isValue(error_overlay)) {
 
1763
            error_overlay.remove();
 
1764
        }
 
1765
    },
 
1766
 
 
1767
    get_subscriptions: function () {
 
1768
        // Usually multiple subscriptions will share a subscriber.  This
 
1769
        // function under test does not actually care, so we make it possible
 
1770
        // to distinguish between the first and the second.
 
1771
        return [{subscriber: 'http://example.net/~person1',
 
1772
                 bug: 'http://example.net/firefox/bug/1'},
 
1773
                {subscriber: 'http://example.net/~person2',
 
1774
                 bug: 'http://example.net/firefox/bug/2'}];
 
1775
    },
 
1776
 
 
1777
    test_node_basic: function () {
 
1778
        var node = module._get_node_for_unsubscribing(
 
1779
            'Rutebega', this.get_subscriptions());
 
1780
        Y.Assert.areEqual(node.get('text'), 'Rutebega');
 
1781
        Y.Assert.isTrue(node.hasClass('sprite'));
 
1782
        Y.Assert.isTrue(node.hasClass('modify'));
 
1783
        Y.Assert.isTrue(node.hasClass('remove'));
 
1784
    },
 
1785
 
 
1786
    test_one_subscription_success: function () {
 
1787
        var subscriptions = this.get_subscriptions();
 
1788
        subscriptions.pop();
 
1789
        Y.Assert.areEqual(subscriptions.length, 1);
 
1790
        var node = module._get_node_for_unsubscribing(
 
1791
            'Rutebega', subscriptions);
 
1792
        module._lp_client.named_post.args = [];
 
1793
        module._lp_client.named_post.halt = true;
 
1794
        Y.one('.subscription-description').appendChild(node);
 
1795
        node.simulate('click');
 
1796
        // Now it is as if we are waiting for the server to reply.  The
 
1797
        // spinner spins.
 
1798
        Y.Assert.isTrue(node.hasClass('spinner'));
 
1799
        Y.Assert.isFalse(node.hasClass('remove'));
 
1800
        // Now the server replies back with a success.
 
1801
        module._lp_client.named_post.resume();
 
1802
        // We have no spinner.
 
1803
        Y.Assert.isTrue(node.hasClass('remove'));
 
1804
        Y.Assert.isFalse(node.hasClass('spinner'));
 
1805
        // The subscriptions array is empty.
 
1806
        Y.Assert.areEqual(subscriptions.length, 0);
 
1807
        // We called unsubscribe on the server once, with the right arguments.
 
1808
        Y.Assert.areEqual(module._lp_client.received.length, 1);
 
1809
        Y.Assert.areEqual(module._lp_client.received[0][0], 'named_post');
 
1810
        var args = module._lp_client.received[0][1];
 
1811
        Y.Assert.areEqual(args[0], 'http://example.net/firefox/bug/1');
 
1812
        Y.Assert.areEqual(args[1], 'unsubscribe');
 
1813
        Y.Assert.areEqual(args[2].parameters.person,
 
1814
                          'http://example.net/~person1');
 
1815
        // The parent node is gone, after giving some time to collapse.
 
1816
        this.wait(
 
1817
            function () {
 
1818
                Y.Assert.isNull(Y.one('.subscription-description'));
 
1819
            },
 
1820
            500
 
1821
        );
 
1822
    },
 
1823
 
 
1824
    test_two_subscriptions_success: function () {
 
1825
        var subscriptions = this.get_subscriptions();
 
1826
        Y.Assert.areEqual(subscriptions.length, 2);
 
1827
        var node = module._get_node_for_unsubscribing(
 
1828
            'Rutebega', subscriptions);
 
1829
        module._lp_client.named_post.args = [];
 
1830
        Y.one('.subscription-description').appendChild(node);
 
1831
        node.simulate('click');
 
1832
        // The subscriptions array is empty.
 
1833
        Y.Assert.areEqual(subscriptions.length, 0);
 
1834
        // We called unsubscribe on the server twice, once for each
 
1835
        // subscription.
 
1836
        Y.Assert.areEqual(module._lp_client.received.length, 2);
 
1837
    },
 
1838
 
 
1839
    test_failure: function () {
 
1840
        var subscriptions = this.get_subscriptions();
 
1841
        var node = module._get_node_for_unsubscribing(
 
1842
            'Rutebega', subscriptions);
 
1843
        module._lp_client.named_post.fail = true;
 
1844
        module._lp_client.named_post.args = [
 
1845
            true,
 
1846
            {status: 400, responseText: 'Rutebegas!'}];
 
1847
        module._lp_client.named_post.halt = true;
 
1848
        Y.one('.subscription-description').appendChild(node);
 
1849
        node.simulate('click');
 
1850
        // Right now, this is as if we are waiting for the server to
 
1851
        // reply. The link is spinning.
 
1852
        Y.Assert.isTrue(node.hasClass('spinner'));
 
1853
        Y.Assert.isFalse(node.hasClass('remove'));
 
1854
        // Now the server replies with an error.
 
1855
        module._lp_client.named_post.resume();
 
1856
        // We have no spinner.
 
1857
        Y.Assert.isTrue(node.hasClass('remove'));
 
1858
        Y.Assert.isFalse(node.hasClass('spinner'));
 
1859
        // The page has rendered the error overlay.
 
1860
        var error_box = Y.one('.yui3-lazr-formoverlay-errors');
 
1861
        // The way the LP error display works now is that it flashes the
 
1862
        // problem area red for 1 second (the lazr.anim default), and
 
1863
        // *then* shows the overlay.
 
1864
        this.wait(
 
1865
            function () {
 
1866
                Y.Assert.areEqual(
 
1867
                    "The following errors were encountered: Rutebegas!",
 
1868
                    error_box.get('text'));
 
1869
            },
 
1870
            1100
 
1871
        );
 
1872
    }
 
1873
 
 
1874
}));
 
1875
 
 
1876
 
 
1877
/**
 
1878
 * Test for helper method to construct actions text and subscriptions list
 
1879
 * for team subscriptions:
 
1880
 *   get_team_unsubscribe_text_and_subscriptions()
 
1881
 */
 
1882
suite.add(new Y.Test.Case({
 
1883
    name: 'Test duplicate actions text and subscriptions list.',
 
1884
 
 
1885
    _should: {
 
1886
        error: {
 
1887
            test_multiple_teams_fails:
 
1888
            new Error('We can only unsubscribe a single team from ' +
 
1889
                      'multiple duplicate bugs.')
 
1890
        }
 
1891
    },
 
1892
 
 
1893
    setUp: function() {
 
1894
        window.LP = { cache: { context: { bug_link: 'http://bug/' } },
 
1895
                      links: { me: '~' } };
 
1896
    },
 
1897
 
 
1898
    tearDown: function() {
 
1899
        delete window.LP;
 
1900
    },
 
1901
 
 
1902
    test_single_team: function() {
 
1903
        // There is a single team you admin that is subscribed to the bug.
 
1904
        var args = { teams: [ { self: { self_link: 'http://team/' } } ] };
 
1905
        var data = module._get_team_unsubscribe_text_and_subscriptions(args);
 
1906
        Y.Assert.areEqual('Unsubscribe this team', data.text);
 
1907
        Y.Assert.areEqual(1, data.subscriptions.length);
 
1908
        var sub = data.subscriptions[0];
 
1909
        Y.Assert.areEqual('http://team/', sub.subscriber);
 
1910
        Y.Assert.areEqual('http://bug/', sub.bug);
 
1911
    },
 
1912
 
 
1913
    test_multiple_teams: function() {
 
1914
        // There are multiple teams you admin that are subscribed to the bug.
 
1915
        var args = { teams: [ { self: { self_link: 'http://team1/' } },
 
1916
                              { self: { self_link: 'http://team2/' } }] };
 
1917
        var data = module._get_team_unsubscribe_text_and_subscriptions(args);
 
1918
        Y.Assert.areEqual('Unsubscribe all of these teams', data.text);
 
1919
        Y.Assert.areEqual(2, data.subscriptions.length);
 
1920
        var sub = data.subscriptions[0];
 
1921
        Y.Assert.areEqual('http://team1/', sub.subscriber);
 
1922
        Y.Assert.areEqual('http://bug/', sub.bug);
 
1923
 
 
1924
        sub = data.subscriptions[1];
 
1925
        Y.Assert.areEqual('http://team2/', sub.subscriber);
 
1926
        Y.Assert.areEqual('http://bug/', sub.bug);
 
1927
    },
 
1928
 
 
1929
    test_multiple_teams_fails: function() {
 
1930
        // There is a single duplicate bug you are subscribed to.
 
1931
        var args = { bugs: [ { self: { self_link: 'http://bug/' } } ],
 
1932
                     teams: [ { self: { self_link: 'http://team1/' } },
 
1933
                              { self: { self_link: 'http://team2/' } }] };
 
1934
        var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
 
1935
            args);
 
1936
    }
 
1937
 
 
1938
}));
 
1939
 
 
1940
/**
 
1941
 * Test for actions node construction.
 
1942
 */
 
1943
suite.add(new Y.Test.Case({
 
1944
    name: 'Test node construction for actions.',
 
1945
 
 
1946
    setUp: function() {
 
1947
        window.LP = { cache: { context: { web_link: 'http://test/' } },
 
1948
                      links: { me: '~' } };
 
1949
    },
 
1950
 
 
1951
    tearDown: function() {
 
1952
        delete window.LP;
 
1953
    },
 
1954
 
 
1955
    test_change_assignees: function() {
 
1956
        // Change assignees action.
 
1957
        var link = module._actions.CHANGE_ASSIGNEES();
 
1958
        Y.Assert.areEqual('Change assignees for this bug', link.get('text'));
 
1959
        Y.Assert.areEqual('http://test/', link.get('href'));
 
1960
    },
 
1961
 
 
1962
    test_unsubscribe_duplicates: function() {
 
1963
        // There is a single duplicate bug you are subscribed to.
 
1964
        var args = { bugs: [ { self: { self_link: 'http://bug/' } } ] };
 
1965
        var node = module._actions.UNSUBSCRIBE_DUPLICATES(args);
 
1966
        Y.Assert.areEqual('Unsubscribe yourself from the duplicate',
 
1967
                          node.get('text'));
 
1968
        Y.Assert.isTrue(node.hasClass('js-action'));
 
1969
        Y.Assert.isTrue(node.hasClass('remove'));
 
1970
    },
 
1971
 
 
1972
    test_set_bug_supervisor: function() {
 
1973
        // You are the pillar owner and can set the supervisor.
 
1974
        var args = { pillar: { title: 'Project',
 
1975
                               web_link: 'http://pillar' } };
 
1976
        var node = module._actions.SET_BUG_SUPERVISOR(args);
 
1977
        Y.Assert.areEqual('Set the bug supervisor for Project',
 
1978
                          node.get('text'));
 
1979
        Y.Assert.areEqual('http://pillar/+bugsupervisor', node.get('href'));
 
1980
    },
 
1981
 
 
1982
    test_contact_teams: function() {
 
1983
        // You are only a member of the subscribed team,
 
1984
        // so you need to contact the team admin to unsubscribe.
 
1985
        var args = { teams: [{ title: 'Team <1>',
 
1986
                               url: 'http://team',
 
1987
                               self: 'self' }] };
 
1988
        var node = module._actions.CONTACT_TEAMS(args);
 
1989
        Y.Assert.areEqual(
 
1990
            'Contact ' +
 
1991
                '<a href="http://team/+contactuser">Team &lt;1&gt;</a>' +
 
1992
                ' to request the administrators make a change',
 
1993
            node.get('innerHTML'));
 
1994
        var link = node.one('a');
 
1995
        Y.Assert.areEqual('http://team/+contactuser', link.get('href'));
 
1996
    }
1281
1997
 
1282
1998
}));
1283
1999
 
1296
2012
    Y.Test.Runner.run();
1297
2013
});
1298
2014
});
1299