UNPKG

@spalger/kibana

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

89 lines (71 loc) 2.2 kB
var angular = require('angular'); var expect = require('expect.js'); var ngMock = require('ngMock'); // Load the kibana app dependencies. require('ui/directives/validate_json'); var $parentScope; var $elemScope; var $elem; var mockScope = ''; var input = { valid: '{ "test": "json input" }', invalid: 'strings are not json' }; var markup = { textarea: '<textarea ng-model="mockModel" validate-json></textarea>', input: '<input type="text" ng-model="mockModel" validate-json>' }; var init = function (type) { // Load the application ngMock.module('kibana'); type = type || 'input'; var elMarkup = markup[type]; // Create the scope ngMock.inject(function ($injector, $rootScope, $compile) { // Give us a scope $parentScope = $rootScope; $parentScope.mockModel = mockScope; $elem = angular.element(elMarkup); $compile($elem)($parentScope); $elemScope = $elem.isolateScope(); }); }; describe('validate-json directive', function () { var checkValid = function (inputVal, className) { $parentScope.mockModel = inputVal; $elem.scope().$digest(); expect($elem.hasClass(className)).to.be(true); }; describe('initialization', function () { beforeEach(function () { init(); }); it('should use the model', function () { expect($elemScope).to.have.property('ngModel'); }); }); Object.keys(markup).forEach(function (inputType) { describe(inputType, function () { beforeEach(function () { init(inputType); }); it('should be an input', function () { expect($elem.get(0).tagName).to.be(inputType.toUpperCase()); }); it('should set valid state', function () { checkValid(input.valid, 'ng-valid'); }); it('should be valid when empty', function () { checkValid('', 'ng-valid'); }); it('should set invalid state', function () { checkValid(input.invalid, 'ng-invalid'); }); it('should update validity on changes', function () { checkValid(input.valid, 'ng-valid'); checkValid(input.invalid, 'ng-invalid'); checkValid(input.valid, 'ng-valid'); }); }); }); });