48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
|
import './textfield.js';
|
||
|
|
||
|
describe('Component vnTextfield', () => {
|
||
|
let $componentController;
|
||
|
let $scope;
|
||
|
let $attrs;
|
||
|
let $timeout;
|
||
|
let $element;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
angular.mock.module('client');
|
||
|
});
|
||
|
|
||
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
|
||
|
$componentController = _$componentController_;
|
||
|
$scope = $rootScope.$new();
|
||
|
$attrs = {};
|
||
|
$timeout = _$timeout_;
|
||
|
$element = angular.element('<div><input></div>');
|
||
|
}));
|
||
|
|
||
|
describe('value() setter', () => {
|
||
|
it(`should set _value, input.value and hasValue properties to null, '' and false then call mdlUpdate()`, () => {
|
||
|
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
|
||
|
spyOn(controller, 'mdlUpdate');
|
||
|
let testValue = '';
|
||
|
controller.value = testValue;
|
||
|
|
||
|
expect(controller._value).toEqual(null);
|
||
|
expect(controller.input.value).toEqual(testValue);
|
||
|
expect(controller.hasValue).toEqual(Boolean(testValue));
|
||
|
expect(controller.mdlUpdate).toHaveBeenCalledWith();
|
||
|
});
|
||
|
|
||
|
it(`should set _value, input.value and hasValue propertiest to test, test and true then call mdlUpdate()`, () => {
|
||
|
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
|
||
|
spyOn(controller, 'mdlUpdate');
|
||
|
let testValue = 'test';
|
||
|
controller.value = testValue;
|
||
|
|
||
|
expect(controller._value).toEqual(testValue);
|
||
|
expect(controller.input.value).toEqual(testValue);
|
||
|
expect(controller.hasValue).toEqual(Boolean(testValue));
|
||
|
expect(controller.mdlUpdate).toHaveBeenCalledWith();
|
||
|
});
|
||
|
});
|
||
|
});
|