Skip to content

Commit

Permalink
Merge pull request #2 from w33ble/issue-2326
Browse files Browse the repository at this point in the history
Clean up tests, add failing test
  • Loading branch information
lukasolson committed Dec 18, 2014
2 parents 6c2ac8b + 0d5603b commit 19f2f9c
Showing 1 changed file with 48 additions and 117 deletions.
165 changes: 48 additions & 117 deletions test/unit/specs/directives/validate_index_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 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',
'foo<bar',
'foo>bar',
'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);
});
});
});
});

0 comments on commit 19f2f9c

Please sign in to comment.