salix/front/core/directives/specs/http-click.spec.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-03-05 09:08:02 +00:00
fdescribe('Directive http-click', () => {
let $scope;
let element;
let compile;
beforeEach(ngModule('vnCore'));
compile = (_element, _childElement) => {
2020-03-08 16:42:49 +00:00
inject(($compile, $rootScope) => {
2020-03-05 09:08:02 +00:00
$scope = $rootScope.$new();
element = angular.element(_element);
$compile(element)($scope);
$scope.$digest();
});
};
2020-03-08 16:42:49 +00:00
xit('should call click function on the element, disable it and then enable it again', () => {
let html = `<input vn-http-click="myEvent()"/>`;
compile(html);
const myPromise = new Promise(resolve => resolve());
$scope.myEvent = () => {
return myPromise;
};
element[0].$ctrl = {disabled: false};
element[0].click();
expect(element[0].$ctrl.disabled).toEqual(true);
2020-03-05 09:08:02 +00:00
2020-03-08 16:42:49 +00:00
let finalValue;
myPromise.then(() => {
finalValue = 'called!';
2020-03-05 09:08:02 +00:00
2020-03-08 16:42:49 +00:00
expect(element[0].$ctrl.disabled).toEqual(false);
}).finally(() => {
expect(finalValue).toEqual('called!');
});
});
it('should call click function on the element and not disable it', () => {
let html = `<input vn-http-click="myEvent()"/>`;
2020-03-05 09:08:02 +00:00
compile(html);
2020-03-08 16:42:49 +00:00
const myPromise = new Promise(resolve => resolve());
$scope.myEvent = () => {
return myPromise;
};
element[0].$ctrl = {disabled: true};
2020-03-05 09:08:02 +00:00
element[0].click();
2020-03-08 16:42:49 +00:00
expect(element[0].$ctrl.disabled).toEqual(true);
let finalValue;
myPromise.then(() => {
finalValue = 'called!';
expect(element[0].$ctrl.disabled).toEqual(false);
}).finally(() => {
expect(finalValue).toEqual('called!');
}).catch(err => {
console.log(err);
});
2020-03-05 09:08:02 +00:00
});
});