~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/javascript/tests/test_bugspeclinks.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-03 01:21:39 UTC
  • mfrom: (13564.1.4 bug-809511)
  • Revision ID: launchpad@pqm.canonical.com-20110803012139-0te2a224h5zrb8r7
[r=gary][bug=809511] use a heuristic to guess the likely bug ID from
        the branch name when associating

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
 * GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 *
 
4
 * Tests for lp.code.branch.bugspeclinks.
 
5
 *
 
6
 */
 
7
 
 
8
YUI({
 
9
    base: '../../../../canonical/launchpad/icing/yui/',
 
10
    filter: 'raw', combine: false
 
11
    }).use('test', 'console', 'node-event-simulate',
 
12
        'lp.code.branch.bugspeclinks', function(Y) {
 
13
 
 
14
    var module = Y.lp.code.branch.bugspeclinks;
 
15
    var extract_candidate_bug_id = module._extract_candidate_bug_id;
 
16
    var suite = new Y.Test.Suite("lp.code.branch.bugspeclinks Tests");
 
17
 
 
18
    suite.add(new Y.Test.Case({
 
19
        name: 'Test bug ID guessing',
 
20
 
 
21
        test_no_bug_id_present: function() {
 
22
            // If nothing that looks like a bug ID is present, null is
 
23
            // returned.
 
24
            Y.Assert.isNull(extract_candidate_bug_id('no-id-here'));
 
25
        },
 
26
 
 
27
        test_short_digit_rund_ignored: function() {
 
28
            Y.Assert.isNull(extract_candidate_bug_id('foo-1234-bar'));
 
29
        },
 
30
 
 
31
        test_leading_zeros_disqualify_potential_ids: function() {
 
32
            // Since bug IDs can't start with zeros, any string of numbers
 
33
            // with a leading zero are not considered as a potential ID.
 
34
            Y.Assert.isNull(extract_candidate_bug_id('foo-0123456-bar'));
 
35
            Y.Assert.areEqual(
 
36
                extract_candidate_bug_id('foo-0123456-999999-bar'), '999999');
 
37
        },
 
38
 
 
39
        test_five_digit_bug_ids_are_extracted: function() {
 
40
            Y.Assert.areEqual(
 
41
                extract_candidate_bug_id('foo-12345-bar'), '12345');
 
42
        },
 
43
 
 
44
        test_six_digit_bug_ids_are_extracted: function() {
 
45
            Y.Assert.areEqual(
 
46
                extract_candidate_bug_id('foo-123456-bar'), '123456');
 
47
        },
 
48
 
 
49
        test_seven_digit_bug_ids_are_extracted: function() {
 
50
            Y.Assert.areEqual(
 
51
                extract_candidate_bug_id('foo-1234567-bar'), '1234567');
 
52
        },
 
53
 
 
54
        test_eight_digit_bug_ids_are_extracted: function() {
 
55
            Y.Assert.areEqual(
 
56
                extract_candidate_bug_id('foo-12345678-bar'), '12345678');
 
57
        },
 
58
 
 
59
        test_longest_potential_id_is_extracted: function() {
 
60
            // Since there may be numbers other than a bug ID in a branch
 
61
            // name, we want to extract the longest string of digits.
 
62
            Y.Assert.areEqual(
 
63
                extract_candidate_bug_id('bug-123456-take-2'), '123456');
 
64
            Y.Assert.areEqual(
 
65
                extract_candidate_bug_id('123456-1234567'), '1234567');
 
66
        }
 
67
 
 
68
        }));
 
69
 
 
70
    var handle_complete = function(data) {
 
71
        window.status = '::::' + JSON.stringify(data);
 
72
        };
 
73
    Y.Test.Runner.on('complete', handle_complete);
 
74
    Y.Test.Runner.add(suite);
 
75
 
 
76
    var console = new Y.Console({newestOnTop: false});
 
77
    console.render('#log');
 
78
 
 
79
    // Start the test runner on Y.after to ensure all setup has had a
 
80
    // chance to complete.
 
81
    Y.after('domready', function() {
 
82
        Y.Test.Runner.run();
 
83
    });
 
84
});