~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
/* Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 * GNU Affero General Public License version 3 (see the file LICENSE).
 *
 * Tests for lp.code.branchmergeproposal.diff.
 *
 */

YUI({
    base: '../../../../canonical/launchpad/icing/yui/',
    filter: 'raw', combine: false
    }).use('test', 'console', 'node-event-simulate', 'lp.client',
           'lp.code.branchmergeproposal.diff', function(Y) {

    var module = Y.lp.code.branchmergeproposal.diff;
    var suite = new Y.Test.Suite("branchmergeproposal.diff Tests");

    /*
     * A Mock client that always calls success on get.
     */
    var MockClient = function() {};
    MockClient.prototype = {
        'get': function(uri, config) {
            var content = Y.Node.create('<p>Sample diff.</p>');
            config.on.success(content);
        }
    };

    suite.add(new Y.Test.Case({
        name: 'Test branch diff functions',

        /*
         * Diff overlays should reopen with multiple clicks. The widget's
         * visible attribute must be toggled, too.
         */
        test_diff_overlay_multiple_opens: function() {
            // Setup mock client and initialize the link click handler.
            var mock_client = new MockClient();
            var link_node = Y.one('#test-diff-popup');
            var api_url = link_node.one('a.api-ref').getAttribute('href');
            module.link_popup_diff_onclick(link_node, mock_client);

            // Open the overlay once.
            link_node.one('a.diff-link').simulate('click');
            var widget = module.rendered_overlays[api_url];
            var overlay = widget.get('boundingBox');
            Y.Assert.isNotNull(overlay);
            Y.Assert.areEqual(overlay.getStyle('display'), 'block');
            Y.Assert.isTrue(widget.get('visible'));

            // verify that the widget has a header div
            Y.Assert.isNotNull(Y.one('.yui3-widget-hd'));

            // Close the overlay.
            overlay.one('.close a').simulate('click');
            Y.Assert.areEqual(overlay.getStyle('display'), 'none');
            Y.Assert.isFalse(widget.get('visible'));

            // Open it again.
            link_node.one('a.diff-link').simulate('click');
            Y.Assert.areEqual(overlay.getStyle('display'), 'block');
            Y.Assert.isTrue(widget.get('visible'));
        }

        }));

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

    // Keep the default console object so we can debug with our dev tools
    // while still allowing us to log to the YUI Console via Y.log and
    // yconsole.
    var yconsole = new Y.Console({newestOnTop: false});
    yconsole.render('#log');

    // Start the test runner on Y.after to ensure all setup has had a
    // chance to complete.
    Y.after('domready', function() {
        Y.Test.Runner.run();
    });
});