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

74 lines (61 loc) 2.09 kB
var angular = require('angular'); var expect = require('expect.js'); var ngMock = require('ngMock'); require('ui/directives/inequality'); describe('greater_than model validator directive', function () { var $compile; var $rootScope; var html; beforeEach(ngMock.module('kibana')); beforeEach(ngMock.inject(function (_$compile_, _$rootScope_) { $compile = _$compile_; $rootScope = _$rootScope_; })); // no value is the same as 0 describe('without value', function () { var element; beforeEach(function () { html = '<input type="text" ng-model="value" greater-than />'; element = $compile(html)($rootScope); }); it('should be valid when larger than 0', function () { $rootScope.value = '1'; $rootScope.$digest(); expect(element.hasClass('ng-valid')).to.be.ok(); }); it('should be valid for 0', function () { $rootScope.value = '0'; $rootScope.$digest(); expect(element.hasClass('ng-valid')).to.be.ok(); }); it('should be valid for negatives', function () { $rootScope.value = '-10'; $rootScope.$digest(); expect(element.hasClass('ng-valid')).to.be.ok(); }); }); [0, 1, 10, 42, -12].forEach(function (num) { describe('with value ' + num, function () { var element; beforeEach(function () { html = '<input type="text" ng-model="value" greater-than="' + num + '" />'; element = $compile(html)($rootScope); }); it('should be valid when larger than ' + num, function () { $rootScope.value = num + 1; $rootScope.$digest(); expect(element.hasClass('ng-valid')).to.be.ok(); }); it('should be invalid for ' + num, function () { $rootScope.value = num; $rootScope.$digest(); expect(element.hasClass('ng-invalid')).to.be.ok(); }); it('should be invalid for less than ' + num, function () { $rootScope.value = num - 1; $rootScope.$digest(); expect(element.hasClass('ng-invalid')).to.be.ok(); }); }); }); });