Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions src/ui/public/directives/__tests__/confirm-click.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import angular from 'angular';
import sinon from 'sinon';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import $ from 'jquery';
import 'ui/directives/confirm_click';
import 'plugins/kibana/discover/index';
import sinon from 'auto-release-sinon';

let $window;

let $parentScope;

let $scope;

let $elem;

const init = function (text) {
const init = function (confirm) {
// Load the application
ngMock.module('kibana');
ngMock.module('kibana', function ($provide) {
$window = {
confirm: sinon.stub().returns(confirm)
};
$provide.value('$window', $window);
});

// Create the scope
ngMock.inject(function ($rootScope, $compile) {

// Give us a scope
$parentScope = $rootScope;

Expand Down Expand Up @@ -71,21 +76,11 @@ describe('confirmClick directive', function () {


describe('confirmed', function () {
let confirmed;

beforeEach(function () {
init();
confirmed = sinon.stub(window, 'confirm');
confirmed.returns(true);
});

afterEach(function () {
window.confirm.restore();
});
beforeEach(() => init(true));

it('should trigger window.confirm when clicked', function (done) {
$elem.click();
expect(confirmed.called).to.be(true);
expect($window.confirm.called).to.be(true);
done();
});

Expand All @@ -98,17 +93,7 @@ describe('confirmClick directive', function () {
});

describe('not confirmed', function () {
let confirmed;

beforeEach(function () {
init();
confirmed = sinon.stub(window, 'confirm');
confirmed.returns(false);
});

afterEach(function () {
window.confirm.restore();
});
beforeEach(() => init(false));

it('should not run the click function when canceled', function (done) {
$elem.click();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/directives/confirm_click.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import uiModules from 'ui/modules';
uiModules
.get('kibana')
.directive('confirmClick', function () {
.directive('confirmClick', function ($window) {
return {
restrict: 'A',
link: function ($scope, $elem, attrs) {
$elem.bind('click', function () {
const message = attrs.confirmation || 'Are you sure?';
if (window.confirm(message)) { // eslint-disable-line no-alert
if ($window.confirm(message)) { // eslint-disable-line no-alert
const action = attrs.confirmClick;
if (action) {
$scope.$apply($scope.$eval(action));
Expand Down