PostalAddress.spec.js
2.03 KB
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
define(function(require) {
'use strict';
var PostalAddress= require('ofbiz/model/PostalAddress');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('PostalAddress', function() {
it('exists', function() {
expect(PostalAddress).toBeTruthy();
});
});
if (true) describe('PostalAddress', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, postalAddress;
postalAddress = new PostalAddress();
expect(postalAddress.validate()).toBeUndefined();
expect(postalAddress.isValid()).toBe(true);
postalAddress._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(postalAddress.isValid()).toBe(true);
result = postalAddress.validate()
expect(result).not.toBeUndefined();
expect(postalAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['address1', 'city', 'postalCode']);
expect(result['address1']).toEqual(jasmine.any(String));
expect(result['city']).toEqual(jasmine.any(String));
expect(result['postalCode']).toEqual(jasmine.any(String));
postalAddress.set('city', 'Anytown');
result = postalAddress.validate()
expect(result).not.toBeUndefined();
expect(postalAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['address1', 'postalCode']);
expect(result['address1']).toEqual(jasmine.any(String));
expect(result['postalCode']).toEqual(jasmine.any(String));
postalAddress._isRequired = false;
expect(postalAddress.isValid()).toBe(false);
expect(postalAddress.validate()).toBeUndefined();
expect(postalAddress.isValid()).toBe(true);
});
});
});