Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/js_tests/spec/DynamicStructureSpec.js
blob: 8b5c84b47ebc6e522aaf45f69e8e503cd19ffa4d (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
describe("", function() {

    jasmine.getFixtures().fixturesPath = "fixtures/";

    it("Correct container", function() {
        loadFixtures("container.html");

        var container = $('#WGroupContainer');

        expect(container).toExist();
        expect(container).toBeEmpty();
    });

    describe("Groups", function() {

        beforeEach(function() {

            jasmine.getFixtures().fixturesPath = "fixtures/";
            loadFixtures("container.html");

            var group_mustache_template = $.ajax({
                type: "GET",
                url: '/jasmine/mustache_templates/group.html',
                cache: false,
                async: false
            }).responseText;
            $("#jasmine-fixtures").append(group_mustache_template);

            var group_mustache_template = $.ajax({
                type: "GET",
                url: '/jasmine/mustache_templates/field.html',
                cache: false,
                async: false
            }).responseText;
            $("#jasmine-fixtures").append(group_mustache_template);

            var group_mustache_template = $.ajax({
                type: "GET",
                url: '/jasmine/mustache_templates/option_default.html',
                cache: false,
                async: false
            }).responseText;
            $("#jasmine-fixtures").append(group_mustache_template);

            Mustache.tags = ['[[', ']]'];

            // Preparing mustache TEMPLATES
            $('script[type="text/x-mustache-template"]').each(function(i, obj){
                TEMPLATES[$(obj).attr('name')] = $(obj).text();
            });

        });

        it("- Group template must contains right classes", function() {
            var group_template = $(TEMPLATES['group']);

            var group_remove_button = group_template.find('.WGroup_remove');
            expect(group_remove_button).toExist();
            expect(group_remove_button).toBe(':button');

            var group_add_button = group_template.find('.WGroup_add_field');
            expect(group_add_button).toExist();
            expect(group_add_button).toBe(':button');

            expect(group_template.find('.error')).toExist();

            expect(group_template.find('.WGroup_field_containter')).toExist();
        });

        it("- factoryGroup must add a empty group in WGroupContainer", function() {
            var groups = $('#WGroupContainer > .group');

            expect(groups.length).toBe(0);

            factoryGroup(0, {"name": '', "fields": []});

            groups = $('#WGroupContainer > .group');

            expect(groups.length).toBe(1);
        });

        it("- Render group widget: A new group must contain right names for inputs", function() {
            factoryGroup(0, {"name": '', "fields": []});

            var inputs = $('.group').find(':input:not(button)');

            $.each(inputs, function(i, input) {
                expect($(input).attr('name')).toContain("groups.0.");
            });

        });

        it("- Render group widget: show name", function() {
            factoryGroup(0, {"name": 'group name', "fields": []});

            var input_name = $(':input[name="groups.0.name"]');

            expect(input_name.attr('value')).toBe('group name');
        });

        it("- Render group widget: show error", function() {
            factoryGroup(0, {"name": '', "fields": [], 'errors': ['error#1']});

            var error = $('.error li');

            expect(error).toHaveText('error#1');
        });

        it("- Render fields", function() {
            factoryGroup(0,
                {"name": '', "fields": [{'widget_type': "InputText"}]}
            );

            fields = $('.field');

            expect(fields.length).toBe(1);

        });

        it("- bindGroupRemoveButton: Remove group and Update order of groups, very important!", function() {
            var groups;

            factoryGroup(0, {"name": 'group name', "fields": []});

            var group_widget_0 = $(".group");
            var button_remove_group_widget_0 = group_widget_0.find('.WGroup_remove');

            factoryGroup(1, {"name": 'group name', "fields": []});

            groups = $('#WGroupContainer > .group');

            expect(groups.length).toBe(2);

            button_remove_group_widget_0.click();

            groups = $('#WGroupContainer > .group');

            expect(groups.length).toBe(1);

            expect($('.group').has($(':input[name="groups.0.order"]'))).toExist();

        });

        it("- Adding a empty field with right group order", function(){
            var group_order = 0;
            factoryGroup(group_order, {'name': ''});
            var add_field_button = $('.group').find('.WGroup_add_field');

            add_field_button.click();

            var fields = $('.field');
            expect(fields.length).toBe(1);

            var inputs = $(fields[0]).find(':input:not(button)');
            $.each(inputs, function(i, input) {
                expect($(input).attr('name')).toContain("groups.0.fields.");
            });
        });

    });

});