summaryrefslogtreecommitdiffstats
path: root/install/ui/test/framework_tests.js
blob: 296e74ebeaf0bec29f55cd4d2d7cbe0604941ccf (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*  Authors:
 *    Petr Vobornik <pvoborni@redhat.com>
 *
 * Copyright (C) 2012 Red Hat
 * see file 'COPYING' for use and warranty information
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

var FOO = {}; //foo app

module('framework',{
    setup: function() {
        FOO.facet = function() {

            //this is a new class: facet
            var that = IFW.type('facet');

            //define method init in facet class
            that._.method('init', function(spec) {

                that.foo = spec.foo || 'facet_foo';
                that.baz = spec.baz || 'facet_baz';
                that.bar = spec.bar || 'facet_bar';
                this._.on('pre_with_events', this.preevent_handler, this);
                this._.on('post_with_events', this.postevent_handler, this);
            });

            that._.method('with_events', function(first, second) {
                this.with_events_called = true;
                this.with_events_attrs = [first, second];
            }, {
                pre_event: true,
                post_event: true
            });

            that._.method('preevent_handler', function(first, second) {
                that.preevent_handler_called = true;
                this.preevent_handler_bound = true;
                this.preevent_handler_attrs = [first, second];
            });

            that._.method('postevent_handler', function(first, second) {
                that.postevent_handler_called = true;
                this.postevent_handler_bound = true;
                this.postevent_handler_attrs = [first, second];
            });

            return that;
        };

        IFW.register('facet', FOO.facet);

        FOO.details_facet = function() {

            //new class details facet, inherits from FOO.facet
            var that = IFW.type('details_facet', FOO.facet);

            //define method init in details_facet class.
            //this overrides init method form facet class
            that._.method('init', function(spec) {

                that._.parent('init', spec);

                that.baz = spec.baz || 'details_baz';
            });

            return that;
        };

        IFW.register('details_facet', FOO.details_facet);
    },
    teardown: function() {

        IFW.register('facet');
        IFW.register('details_facet');
    }
});

test("Build and inheritence" ,function() {

    var details_facet = IFW.build({
        factory: FOO.details_facet,
        bar: 'custom_bar'
    });

    same(details_facet._.klass, 'details_facet', "Class");
    same(details_facet._.ancestor, 'facet', "Ancestor");

    same(details_facet.foo, 'facet_foo', "Property - ancestor's default");
    same(details_facet.baz, 'details_baz', "Property - child's default");
    same(details_facet.bar, 'custom_bar', "Property - custom");

    //test method calls and pre/post events

    var attrs = ["first", "second"];
    details_facet.with_events(attrs[0], attrs[1]);

    ok(details_facet.with_events_called, "With events called.");
    same(details_facet.with_events_attrs, attrs, "With event called with good attrs");

    ok(details_facet.preevent_handler_called, "Pre event called.");
    ok(details_facet.preevent_handler_bound, "Pre event correctly bounded.");
    same(details_facet.preevent_handler_attrs, attrs, "Pre event called with good attrs");

    ok(details_facet.postevent_handler_called, "Post event called.");
    ok(details_facet.postevent_handler_bound, "Post event correctly bounded.");
    same(details_facet.postevent_handler_attrs, attrs, "Post event called with good attrs");

    //calls
});