<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-ng-href-production</title>
<script src="//code.angularjs.org/1.7.7/angular.min.js"></script>
</head>
<body ng-app="heitor">
<div ng-controller="testeController as testeCtrl">
<input type="checkbox" ng-model="$rootScope.enabled" /> {{$rootScope.enabled}}
<div ng-repeat="item in [1,2,3,4]">
<a id="link-2" ng-click="log('clickou')">
link {{ item }}
</a>
<br />
</div>
</div>
<script>
var app = angular.module("heitor", []);
app.controller("testeController", ["$scope", "$rootScope",
function($scope, $rootScope) {
$scope.windowAlert = window.alert;
$rootScope.enabled = true;
$scope.log = console.log;
}]);
app.directive('confirmationNeeded', ['$rootScope' ,function ($rootScope) {
return {
priority: 1001,
link: function (scope, element, attr) {
if(!$rootScope.enabled) {
element.bind('click', function (event) {
console.log(element);
event.preventDefault();
});
}
}
};
}]);
</script>
</body>
</html>
<!--
Copyright 2019 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->
it('should execute ng-click but not reload when href without value', function() {
element(by.id('link-1')).click();
expect(element(by.model('value')).getAttribute('value')).toEqual('1');
expect(element(by.id('link-1')).getAttribute('href')).toBe('');
});
it('should execute ng-click but not reload when href empty string', function() {
element(by.id('link-2')).click();
expect(element(by.model('value')).getAttribute('value')).toEqual('2');
expect(element(by.id('link-2')).getAttribute('href')).toBe('');
});
it('should execute ng-click and change url when ng-href specified', function() {
expect(element(by.id('link-3')).getAttribute('href')).toMatch(/\/123$/);
element(by.id('link-3')).click();
// At this point, we navigate away from an AngularJS page, so we need
// to use browser.driver to get the base webdriver.
browser.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return url.match(/\/123$/);
});
}, 5000, 'page should navigate to /123');
});
it('should execute ng-click but not reload when href empty string and name specified', function() {
element(by.id('link-4')).click();
expect(element(by.model('value')).getAttribute('value')).toEqual('4');
expect(element(by.id('link-4')).getAttribute('href')).toBe('');
});
it('should execute ng-click but not reload when no href but name specified', function() {
element(by.id('link-5')).click();
expect(element(by.model('value')).getAttribute('value')).toEqual('5');
expect(element(by.id('link-5')).getAttribute('href')).toBe(null);
});
it('should only change url when only ng-href', function() {
element(by.model('value')).clear();
element(by.model('value')).sendKeys('6');
expect(element(by.id('link-6')).getAttribute('href')).toMatch(/\/6$/);
element(by.id('link-6')).click();
// At this point, we navigate away from an AngularJS page, so we need
// to use browser.driver to get the base webdriver.
browser.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return url.match(/\/6$/);
});
}, 5000, 'page should navigate to /6');
});
/*
Copyright 2019 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/