Tests/spec/generatemodel.spec.js   A
last analyzed

Complexity

Total Complexity 29
Complexity/F 1.04

Size

Lines of Code 129
Function Count 28

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 29
c 1
b 0
f 0
dl 0
loc 129
rs 10
cc 0
nc 1
mnd 1
bc 29
fnc 28
bpm 1.0357
cpm 1.0357
noi 22
1
describe('Model Generator', function () {
2
    it('Person Model exist', function () {
3
        expect(Test.model.Person).toBeDefined();
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
4
    });
5
    it('Base Book Model to exist', function() {
6
        expect(Test.model.BaseBook).toBeDefined();
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
7
    });
8
    it('Book Model to exist', function() {
9
        expect(Test.model.Book).toBeDefined();
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
    });
11
    describe('Model Fields', function () {
12
        var getField = (function () {
13
            var fields = Test.model.Person.getFields();
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
            var list = {};
15
            for (var i = 0; i < fields.length; i++) {
16
                list[fields[i].name] = fields[i];
17
            }
18
            return function (name) {
19
                return list[name];
20
            }
21
        })();
22
        it('contain 9 fields', function () {
23
            expect(Test.model.Person.getFields().length).toBe(9);
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
24
        });
25
        it('age field', function () {
26
            expect(getField('age').type).toBe(Ext.data.Types.INT);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
27
        });
28
        it('active field', function () {
29
            expect(getField('active').type).toBe(Ext.data.Types.BOOLEAN);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
30
        });
31
        it('createdAt field', function () {
32
            expect(getField('createdAt').type).toBe(Ext.data.Types.DATE);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
33
        });
34
        it('email field', function () {
35
            expect(getField('email').type).toBe(Ext.data.Types.STRING);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
36
        });
37
        it('exclude dob field', function() {
38
            expect(getField('dob')).toBeUndefined();
39
        });
40
    });
41
    describe('Model Validations', function() {
42
        it('Presence Failed', function() {
43
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
            p.set("firstName", "");
45
            var errors = p.validate();
46
            expect(errors.getByField("firstName").length).toBe(1);
47
        });
48
        it('Presence Success', function() {
49
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
50
            p.set("lastName", "test");
51
            var errors = p.validate();
52
            expect(errors.getByField("lastName").length).toBe(0);
53
        });
54
        it('Length Failed', function() {
55
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
56
            p.set("email", "[email protected]");
57
            var errors = p.validate();
58
            expect(errors.getByField("email").length).toBe(1);
59
            p.set("email", "[email protected]");
60
            errors = p.validate();
61
            expect(errors.getByField("email").length).toBe(1);
62
        });
63
        it('Length Success', function() {
64
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
65
            p.set("email", "[email protected]");
66
            var errors = p.validate();
67
            expect(errors.getByField("email").length).toBe(0);
68
        });
69
        it('Email Failed', function() {
70
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
71
            p.set("email", "as.ad.coma1.au");
72
            var errors = p.validate();
73
            expect(errors.getByField("email").length).toBe(1);
74
        });
75
        it('Email Success', function() {
76
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
            p.set("email", "[email protected]");
78
            var errors = p.validate();
79
            expect(errors.getByField("email").length).toBe(0);
80
        });
81
        it('Regex Success', function() {
82
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
83
            p.set("regex", "81 4");
84
            var errors = p.validate();
85
            expect(errors.getByField("regex").length).toBe(0);
86
        });
87
        it('Regex Failed', function() {
88
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
89
            p.set("regex", "a1 4");
90
            var errors = p.validate();
91
            expect(errors.getByField("regex").length).toBe(1);
92
        });
93
        it('Choice Success', function() {
94
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
95
            p.set("color", "red");
96
            var errors = p.validate();
97
            expect(errors.getByField("color").length).toBe(0);
98
        });
99
        it('Choice Failed', function() {
100
            var p = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
101
            p.set("color", "green");
102
            var errors = p.validate();
103
            expect(errors.getByField("color").length).toBe(1);
104
        });
105
    });
106
    describe('Model Associations', function() {
107
        it('books define in person', function() {
108
            var person = Ext.create('Test.model.Person');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
109
            expect(person.books).toBeDefined();
110
        });
111
        it('person define in book', function() {
112
            var book = Ext.create('Test.model.Book');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
113
            expect(book.getPerson).toBeDefined();
114
            expect(book.setPerson).toBeDefined();
115
        });
116
        it('associate books to person', function() {
117
            var book1 = Ext.create('Test.model.Book');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
118
            book1.set('name', 'Book A');
119
            var book2 = Ext.create('Test.model.Book');
120
            book2.set('name', 'Book 2');
121
            var person = Ext.create('Test.model.Person', {id: 10});
122
            person.books().add(book1, book2);
123
            expect(person.books().count()).toEqual(2);
124
            person.books().remove(book2);
125
            expect(person.books().count()).toEqual(1);
126
            expect(book1.dirty).toBeTruthy();
127
        })
128
    });
129
});