diff --git a/test/unit/specs/directives/validate_index_name.js b/test/unit/specs/directives/validate_index_name.js index c73b89f484cc26..da1b5eede0e727 100644 --- a/test/unit/specs/directives/validate_index_name.js +++ b/test/unit/specs/directives/validate_index_name.js @@ -15,123 +15,54 @@ define(function (require) { $rootScope = _$rootScope_; })); - it('should not accept null index name patterns', function () { - $rootScope.indexName = null; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept undefined index name patterns', function () { - $rootScope.indexName = undefined; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept empty index name patterns', function () { - $rootScope.indexName = ''; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept . as an index name pattern', function () { - $rootScope.indexName = '.'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept .. as an index name pattern', function () { - $rootScope.indexName = '..'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept \\ in an index name pattern', function () { - $rootScope.indexName = 'foo\\bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept / in an index name pattern', function () { - $rootScope.indexName = 'foo/bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept ? in an index name pattern', function () { - $rootScope.indexName = 'foo?bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept " in an index name pattern', function () { - $rootScope.indexName = 'foo"bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept < in an index name pattern', function () { - $rootScope.indexName = 'foo in an index name pattern', function () { - $rootScope.indexName = 'foo>bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept | in an index name pattern', function () { - $rootScope.indexName = 'foo|bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept spaces in an index name pattern', function () { - $rootScope.indexName = 'foo bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should not accept , in an index name pattern', function () { - $rootScope.indexName = 'foo,bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.be.ok(); - }); - - it('should accept a valid index name pattern', function () { - $rootScope.indexName = 'foo.bar'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.not.be.ok(); - }); - - it('should accept * in an index name pattern', function () { - $rootScope.indexName = 'foo.*'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.not.be.ok(); - }); - - it('should accept [] in an index name pattern', function () { - $rootScope.indexName = '[foo]-YYYY.MM.DD'; - var element = $compile(html)($rootScope); - $rootScope.$digest(); - expect(element.hasClass('ng-invalid')).to.not.be.ok(); + function checkPattern(input) { + $rootScope.indexName = input; + var element = $compile(html)($rootScope); + $rootScope.$digest(); + return element; + } + + var badPatterns = [ + null, + undefined, + '', + '.', + '..', + 'foo\\bar', + 'foo/bar', + 'foo?bar', + 'foo"bar', + 'foobar', + 'foo|bar', + 'foo bar', + 'foo,bar', + ]; + + var goodPatterns = [ + '...', + 'foo', + 'foo.bar', + 'foo*', + 'foo.bar*', + 'foo.*', + '[foo-]YYYY-MM-DD', + ]; + + badPatterns.forEach(function (pattern) { + it('should not accept index pattern: ' + pattern, function () { + var element = checkPattern(pattern); + expect(element.hasClass('ng-invalid')).to.be(true); + expect(element.hasClass('ng-valid')).to.not.be(true); + }); + }); + + goodPatterns.forEach(function (pattern) { + it('should accept index pattern: ' + pattern, function () { + var element = checkPattern(pattern); + expect(element.hasClass('ng-invalid')).to.not.be(true); + expect(element.hasClass('ng-valid')).to.be(true); + }); }); }); }); \ No newline at end of file