~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */

YUI({
    base: '../../../../canonical/launchpad/icing/yui/',
    filter: 'raw',
    combine: false,
    fetchCSS: false
      }).use('event', 'lp.bugs.bugtask_index', 'lp.client', 'node',
             'test', 'widget-stack', 'console', function(Y) {

// Local aliases
var Assert = Y.Assert,
    ArrayAssert = Y.ArrayAssert;

// A picker implementation that records method calls for testing.
function FauxPicker() {
    this.events = [];
}

FauxPicker.prototype.get = function(name) {
    this.events.push('get ' + name);
    return 47;
};

FauxPicker.prototype.set = function(name, value) {
    this.events.push('set ' + name + ' = ' + value);
};

FauxPicker.prototype.fire = function(name, value) {
    this.events.push('fire ' + name + ' with ' + value);
};


var suite = new Y.Test.Suite("Link a related branch preemptive search.");
var module = Y.lp.bugs.bugtask_index;

suite.add(new Y.Test.Case({

    name: 'pre_search',

    setUp: function() {
    },

    tearDown: function() {
    },

    /**
     * A loading message is added to the footer slot.
     */
    test_loading_message: function() {
        picker = new FauxPicker();
        module._do_pre_search(picker, 'BUG-ID');
        ArrayAssert.contains(
            'set footer_slot = Loading suggestions...',
            picker.events);
    },

    /**
     * Because some bug numbers are short strings, the minimum search
     * character limit has to be set to zero and then reset to its original
     * value.
     */
    test_min_search_length: function() {
        picker = new FauxPicker();
        module._do_pre_search(picker, 'BUG-ID');
        ArrayAssert.contains(
            'get min_search_chars',
            picker.events);
        ArrayAssert.contains(
            'set min_search_chars = 47',
            picker.events);
    },

    /**
     * After the search event is fired, search_mode has to be (immediately)
     * disbled so the user can enter a search.
     */
    test_disable_search_mode: function() {
        picker = new FauxPicker();
        module._do_pre_search(picker, 'BUG-ID');
        ArrayAssert.contains(
            'fire search with BUG-ID',
            picker.events);
        ArrayAssert.contains(
            'set search_mode = false',
            picker.events);
    }

}));

var handle_complete = function(data) {
    window.status = '::::' + JSON.stringify(data);
    };
Y.Test.Runner.on('complete', handle_complete);
Y.Test.Runner.add(suite);

var yconsole = new Y.Console({
    newestOnTop: false
});
yconsole.render('#log');

Y.on('domready', function() {
    Y.Test.Runner.run();
});

});