Merge branch '2136-http_directive' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
7a5201a657
|
@ -0,0 +1,66 @@
|
||||||
|
describe('Directive http-click', () => {
|
||||||
|
let $scope;
|
||||||
|
let element;
|
||||||
|
let compile;
|
||||||
|
|
||||||
|
beforeEach(ngModule('vnCore'));
|
||||||
|
|
||||||
|
compile = (_element, _childElement) => {
|
||||||
|
inject(($compile, $rootScope) => {
|
||||||
|
$scope = $rootScope.$new();
|
||||||
|
element = angular.element(_element);
|
||||||
|
$compile(element)($scope);
|
||||||
|
$scope.$digest();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
it('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);
|
||||||
|
|
||||||
|
let finalValue;
|
||||||
|
myPromise.then(() => {
|
||||||
|
finalValue = 'called!';
|
||||||
|
|
||||||
|
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()"/>`;
|
||||||
|
compile(html);
|
||||||
|
|
||||||
|
const myPromise = new Promise(resolve => resolve());
|
||||||
|
$scope.myEvent = () => {
|
||||||
|
return myPromise;
|
||||||
|
};
|
||||||
|
|
||||||
|
element[0].$ctrl = {disabled: true};
|
||||||
|
element[0].click();
|
||||||
|
|
||||||
|
expect(element[0].$ctrl.disabled).toEqual(true);
|
||||||
|
|
||||||
|
let finalValue;
|
||||||
|
myPromise.then(() => {
|
||||||
|
finalValue = 'called!';
|
||||||
|
|
||||||
|
expect(element[0].$ctrl.disabled).toEqual(true);
|
||||||
|
}).finally(() => {
|
||||||
|
expect(finalValue).toEqual('called!');
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue