1
/* Copyright 2011 Canonical Ltd. This software is licensed under the
2
* GNU Affero General Public License version 3 (see the file LICENSE).
4
* Tests for lp.code.branch.bugspeclinks.
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) {
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");
18
suite.add(new Y.Test.Case({
19
name: 'Test bug ID guessing',
21
test_no_bug_id_present: function() {
22
// If nothing that looks like a bug ID is present, null is
24
Y.Assert.isNull(extract_candidate_bug_id('no-id-here'));
27
test_short_digit_rund_ignored: function() {
28
Y.Assert.isNull(extract_candidate_bug_id('foo-1234-bar'));
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'));
36
extract_candidate_bug_id('foo-0123456-999999-bar'), '999999');
39
test_five_digit_bug_ids_are_extracted: function() {
41
extract_candidate_bug_id('foo-12345-bar'), '12345');
44
test_six_digit_bug_ids_are_extracted: function() {
46
extract_candidate_bug_id('foo-123456-bar'), '123456');
49
test_seven_digit_bug_ids_are_extracted: function() {
51
extract_candidate_bug_id('foo-1234567-bar'), '1234567');
54
test_eight_digit_bug_ids_are_extracted: function() {
56
extract_candidate_bug_id('foo-12345678-bar'), '12345678');
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.
63
extract_candidate_bug_id('bug-123456-take-2'), '123456');
65
extract_candidate_bug_id('123456-1234567'), '1234567');
70
var handle_complete = function(data) {
71
window.status = '::::' + JSON.stringify(data);
73
Y.Test.Runner.on('complete', handle_complete);
74
Y.Test.Runner.add(suite);
76
var console = new Y.Console({newestOnTop: false});
77
console.render('#log');
79
// Start the test runner on Y.after to ensure all setup has had a
80
// chance to complete.
81
Y.after('domready', function() {