TelecomNumber.spec.js 1.68 KB
define(function(require) {
    'use strict';

    var TelecomNumber = require('ofbiz/model/TelecomNumber');
    var _ = require('underscore');
    var Backbone = require('backbone');
    require('backbone-validation');

    describe('TelecomNumber', function() {
        it('exists', function() {
            expect(TelecomNumber).toBeTruthy();
        });
    });
    if (true) describe('TelecomNumber', function() {
        beforeEach(function() {
             _.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
        });
        it('validation', function() {
            var result, telecomNumber;
            telecomNumber = new TelecomNumber();
            expect(telecomNumber.validate()).toBeUndefined();
            expect(telecomNumber.isValid()).toBe(true);

            telecomNumber._isRequired = true;
            // changing _isRequired doesn't have an effect until validate is called
            expect(telecomNumber.isValid()).toBe(true);
            result = telecomNumber.validate()
            expect(result).not.toBeUndefined();
            expect(telecomNumber.isValid()).toBe(false);
            expect(_.keys(result).sort()).toEqual(['contactNumber']);
            expect(result['contactNumber']).toEqual(jasmine.any(String));

            telecomNumber.set('contactNumber', '123-456-7890');
            result = telecomNumber.validate()
            expect(result).toBeUndefined();
            expect(telecomNumber.isValid()).toBe(true);

            telecomNumber._isRequired = false;
            expect(telecomNumber.isValid()).toBe(true);
            expect(telecomNumber.validate()).toBeUndefined();
            expect(telecomNumber.isValid()).toBe(true);
        });
    });
});