mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
use angular instead of global window (#9743)
This commit is contained in:
parent
64a03fafd4
commit
6fd728011c
2 changed files with 14 additions and 29 deletions
|
@ -1,11 +1,12 @@
|
|||
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;
|
||||
|
||||
|
@ -13,13 +14,17 @@ 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;
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue