From 05cae2e7d09ef442c4f94bd06a2bf67ef8c54371 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Thu, 18 Dec 2014 11:47:01 -0700 Subject: [PATCH 1/2] clean up tests, add failing test --- .../specs/directives/validate_index_name.js | 165 +++++------------- 1 file changed, 48 insertions(+), 117 deletions(-) diff --git a/test/unit/specs/directives/validate_index_name.js b/test/unit/specs/directives/validate_index_name.js index c73b89f484cc2..3afc73dac6bf7 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 From 0d5603ba82c7f73539df576eacf991829c3f5388 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Thu, 18 Dec 2014 11:51:11 -0700 Subject: [PATCH 2/2] apparently ... is a passing index pattern --- test/unit/specs/directives/validate_index_name.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/specs/directives/validate_index_name.js b/test/unit/specs/directives/validate_index_name.js index 3afc73dac6bf7..da1b5eede0e72 100644 --- a/test/unit/specs/directives/validate_index_name.js +++ b/test/unit/specs/directives/validate_index_name.js @@ -28,7 +28,6 @@ define(function (require) { '', '.', '..', - '...', 'foo\\bar', 'foo/bar', 'foo?bar', @@ -41,6 +40,7 @@ define(function (require) { ]; var goodPatterns = [ + '...', 'foo', 'foo.bar', 'foo*',