Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1b6b1aa

Browse files
Added test for a PoC
1 parent 7e4149b commit 1b6b1aa

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

test/ng/directive/inputSpec.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ describe('ngModel', function() {
983983

984984
describe('input', function() {
985985
var formElm, inputElm, scope, $compile, $sniffer, $browser, changeInputValueTo, currentSpec;
986+
var compileProvider;
986987

987988
function compileInput(inputHtml, mockValidity) {
988989
inputElm = jqLite(inputHtml);
@@ -1002,8 +1003,9 @@ describe('input', function() {
10021003
var attrs;
10031004
beforeEach(function() { currentSpec = this; });
10041005
afterEach(function() { currentSpec = null; });
1005-
beforeEach(module(function($compileProvider) {
1006-
$compileProvider.directive('attrCapture', function() {
1006+
beforeEach(module(function($compileProvider, $exceptionHandlerProvider) {
1007+
compileProvider = $compileProvider;
1008+
compileProvider.directive('attrCapture', function() {
10071009
return function(scope, element, $attrs) {
10081010
attrs = $attrs;
10091011
};
@@ -1865,6 +1867,40 @@ describe('input', function() {
18651867

18661868
describe('maxlength', function() {
18671869

1870+
it('should validate after minlength attr being observed', function() {
1871+
1872+
var actualCalls = [];
1873+
var expectedCalls = [ "X-Observe", "X-Validate" ];
1874+
1875+
compileProvider
1876+
.directive('ngMinlengthX', function () {
1877+
return {
1878+
restrict: 'A',
1879+
require: '?ngModel',
1880+
link: function (scope, elm, attr, ctrl) {
1881+
if (!ctrl)
1882+
return;
1883+
1884+
var minlength = 0;
1885+
attr.$observe('minlength', function(value) {
1886+
actualCalls.push("[X-Observe]");
1887+
minlength = int(value) || 0;
1888+
ctrl.$validate();
1889+
});
1890+
1891+
ctrl.$validators.minlength = function(modelValue, viewValue) {
1892+
actualCalls.push("[X-Validate]");
1893+
return ctrl.$isEmpty(viewValue) || viewValue.length >= minlength;
1894+
};
1895+
}
1896+
};
1897+
});
1898+
1899+
compileInput('<input type="text" ng-model="value" ng-minlength-x="5"/>');
1900+
1901+
expect(actualCalls).toEqual(expectedCalls);
1902+
});
1903+
18681904
it('should invalidate values that are longer than the given maxlength', function() {
18691905
compileInput('<input type="text" ng-model="value" ng-maxlength="5" />');
18701906

0 commit comments

Comments
 (0)