EmailAddress.spec.js
3.16 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
define(function(require) {
'use strict';
var EmailAddress= require('ofbiz/model/EmailAddress');
var _ = require('underscore');
var Backbone = require('backbone');
require('backbone-validation');
describe('EmailAddress', function() {
it('exists', function() {
expect(EmailAddress).toBeTruthy();
});
});
describe('EmailAddress', function() {
beforeEach(function() {
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
});
it('validation', function() {
var result, emailAddress;
emailAddress = new EmailAddress();
expect(emailAddress.validate()).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
emailAddress._isRequired = true;
// changing _isRequired doesn't have an effect until validate is called
expect(emailAddress.isValid()).toBe(true);
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress.set('emailAddress', 'foo');
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress.set('emailAddress', 'name@example.com');
result = emailAddress.validate();
expect(result).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
emailAddress.set('emailAddress', null);
result = emailAddress.validate();
expect(result).not.toBeUndefined();
expect(emailAddress.isValid()).toBe(false);
expect(_.keys(result).sort()).toEqual(['emailAddress']);
expect(result['emailAddress']).toEqual(jasmine.any(String));
emailAddress._isRequired = false;
expect(emailAddress.isValid()).toBe(false);
expect(emailAddress.validate()).toBeUndefined();
expect(emailAddress.isValid()).toBe(true);
});
it('parse', function() {
var result, emailAddress;
emailAddress = new EmailAddress({infoString: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
emailAddress = new EmailAddress({emailAddress: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
emailAddress = new EmailAddress({infoString: 'foo', emailAddress: 'name@example.com'}, {parse: true});
expect(emailAddress.get('infoString')).toBeUndefined();
expect(emailAddress.get('emailAddress')).toEqual('name@example.com');
});
});
});