mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Merge branch 'master' into vislib/refactor
This commit is contained in:
commit
38ca0be1e8
3 changed files with 128 additions and 0 deletions
|
@ -4,6 +4,7 @@ define(function (require) {
|
|||
.directive('confirmClick', function () {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {},
|
||||
link: function ($scope, $elem, attrs) {
|
||||
$elem.bind('click', function () {
|
||||
var message = attrs.confirmation || 'Are you sure?';
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
'kibana',
|
||||
'sinon/sinon',
|
||||
'specs/apps/discover/hit_sort_fn',
|
||||
'specs/directives/confirm-click',
|
||||
'specs/directives/timepicker',
|
||||
'specs/directives/truncate',
|
||||
'specs/directives/typeahead',
|
||||
|
|
126
test/unit/specs/directives/confirm-click.js
Normal file
126
test/unit/specs/directives/confirm-click.js
Normal file
|
@ -0,0 +1,126 @@
|
|||
define(function (require) {
|
||||
var angular = require('angular');
|
||||
var $ = require('jquery');
|
||||
var sinon = require('sinon/sinon');
|
||||
|
||||
require('directives/confirm_click');
|
||||
|
||||
// Load the kibana app dependencies.
|
||||
require('angular-route');
|
||||
|
||||
// Load kibana and its applications
|
||||
require('index');
|
||||
|
||||
require('apps/discover/index');
|
||||
|
||||
var $parentScope, $scope, $elem;
|
||||
|
||||
var init = function (text) {
|
||||
// Load the application
|
||||
module('kibana');
|
||||
|
||||
// Create the scope
|
||||
inject(function ($rootScope, $compile) {
|
||||
|
||||
// Give us a scope
|
||||
$parentScope = $rootScope;
|
||||
|
||||
// Create the element
|
||||
$elem = angular.element(
|
||||
'<a confirm-click="runThis()">runThis</a>'
|
||||
);
|
||||
|
||||
// And compile it
|
||||
$compile($elem)($parentScope);
|
||||
|
||||
// Fire a digest cycle
|
||||
$elem.scope().$digest();
|
||||
|
||||
// Grab the isolate scope so we can test it
|
||||
$scope = $elem.isolateScope();
|
||||
|
||||
// Add a function to check the run status of.
|
||||
$scope.runThis = sinon.spy();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
describe('confirmClick directive', function () {
|
||||
|
||||
|
||||
describe('event handlers', function () {
|
||||
var events;
|
||||
|
||||
beforeEach(function () {
|
||||
init();
|
||||
events = $._data($elem[0], 'events');
|
||||
});
|
||||
|
||||
it('should get a click handler', function (done) {
|
||||
expect(events).to.be.a(Object);
|
||||
expect(events.click).to.be.a(Array);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should unbind click handlers when the scope is destroyed', function (done) {
|
||||
$scope.$destroy();
|
||||
expect(events.click).to.be(undefined);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('confirmed', function () {
|
||||
var confirmed;
|
||||
|
||||
beforeEach(function () {
|
||||
init();
|
||||
confirmed = sinon.stub(window, 'confirm');
|
||||
confirmed.returns(true);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
window.confirm.restore();
|
||||
});
|
||||
|
||||
it('should trigger window.confirm when clicked', function (done) {
|
||||
$elem.click();
|
||||
expect(confirmed.called).to.be(true);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should run the click function when positively confirmed', function (done) {
|
||||
$elem.click();
|
||||
expect($scope.runThis.called).to.be(true);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('not confirmed', function () {
|
||||
var confirmed;
|
||||
|
||||
beforeEach(function () {
|
||||
init();
|
||||
confirmed = sinon.stub(window, 'confirm');
|
||||
confirmed.returns(false);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
window.confirm.restore();
|
||||
});
|
||||
|
||||
it('should not run the click function when canceled', function (done) {
|
||||
$elem.click();
|
||||
expect($scope.runThis.called).to.be(false);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue