@@ -180,6 +180,172 @@ describe('Directives: validation - match', function() {
180180 expect ( form . testConfirm . $error . match ) . to . be . undefined ( ) ;
181181 } ) ;
182182
183+ it ( 'should check if $viewValues are not identical' , function ( ) {
184+ form . testConfirm . $setViewValue ( inputValue + 'extra' ) ;
185+ $scope . $digest ( ) ;
186+ expect ( form . testConfirm . $error . match ) . to . be . true ( ) ;
187+ } ) ;
188+
189+ } ) ;
190+
191+ } ) ;
192+
193+ describe ( 'not-match validation' , function ( ) {
194+
195+ describe ( 'behavior:' , function ( ) {
196+ var validTemplate = '<input ng-model="confirmation" match="original" not-match="true"></input>' ;
197+
198+ it ( 'returns true if no model value has been defined' , function ( ) {
199+ compiled = $compile ( validTemplate ) ( $scope ) ;
200+ expect ( $scope . confirmation ) . to . be . undefined ( ) ;
201+ $scope . $digest ( ) ;
202+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . false ( ) ;
203+ } ) ;
204+
205+
206+ it ( 'returns true if $modelValue are identical' , function ( ) {
207+ $scope . confirmation = "value" ;
208+ compiled = $compile ( validTemplate ) ( $scope ) ;
209+ $scope . original = "value" ;
210+ $scope . $digest ( ) ;
211+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . false ( ) ;
212+ } ) ;
213+
214+ it ( 'returns true if $modelValue are not identical but match caselessly' , function ( ) {
215+ $scope . confirmation = "VALUE" ;
216+ compiled = $compile ( validTemplate ) ( $scope ) ;
217+ $scope . original = "value" ;
218+ $scope . $digest ( ) ;
219+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . true ( ) ;
220+ } ) ;
221+
222+ it ( 'returns false if $modelValue are not identical' , function ( ) {
223+ $scope . confirmation = false ;
224+ $scope . original = undefined ;
225+ compiled = $compile ( validTemplate ) ( $scope ) ;
226+ $scope . $digest ( ) ;
227+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . true ( ) ;
228+ } ) ;
229+
230+ } ) ;
231+
232+
233+ describe ( 'Form level validation' , function ( ) {
234+ var form ,
235+ element ,
236+ inputValue = 'testValue' ;
237+
238+ beforeEach ( function ( ) {
239+ element = angular . element (
240+ '<form name="form">' +
241+ '<input type="text" ng-model="test" name="test"></input>' +
242+ '<input type="text" match="form.test" not-match="true" ng-model="testConfirm" name="testConfirm"></input>' +
243+ '</form>'
244+ ) ;
245+ $scope . test = inputValue ;
246+ $compile ( element ) ( $scope ) ;
247+ $scope . $digest ( ) ;
248+ form = $scope . form ;
249+ } ) ;
250+
251+ it ( 'should check if $viewValues are identical' , function ( ) {
252+ form . testConfirm . $setViewValue ( inputValue ) ;
253+ $scope . $digest ( ) ;
254+ expect ( form . testConfirm . $error . match ) . to . be . true ( ) ;
255+ } ) ;
256+
257+ it ( 'should check if $viewValues are not identical' , function ( ) {
258+ form . testConfirm . $setViewValue ( inputValue . toUpperCase ( ) ) ;
259+ $scope . $digest ( ) ;
260+ expect ( form . testConfirm . $error . match ) . to . be . undefined ( ) ;
261+ } ) ;
262+
263+ it ( 'should check if $viewValues are not identical' , function ( ) {
264+ form . testConfirm . $setViewValue ( inputValue + 'extra' ) ;
265+ $scope . $digest ( ) ;
266+ expect ( form . testConfirm . $error . match ) . to . be . undefined ( ) ;
267+ } ) ;
268+
269+ } ) ;
270+
271+ } ) ;
272+
273+ describe ( 'not-match with caseless validation' , function ( ) {
274+
275+ describe ( 'behavior:' , function ( ) {
276+ var validTemplate = '<input ng-model="confirmation" match="original" match-caseless="true" not-match="true"></input>' ;
277+
278+ it ( 'returns true if no model value has been defined' , function ( ) {
279+ compiled = $compile ( validTemplate ) ( $scope ) ;
280+ expect ( $scope . confirmation ) . to . be . undefined ( ) ;
281+ $scope . $digest ( ) ;
282+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . false ( ) ;
283+ } ) ;
284+
285+
286+ it ( 'returns true if $modelValue are identical' , function ( ) {
287+ $scope . confirmation = "value" ;
288+ compiled = $compile ( validTemplate ) ( $scope ) ;
289+ $scope . original = "value" ;
290+ $scope . $digest ( ) ;
291+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . false ( ) ;
292+ } ) ;
293+
294+ it ( 'returns true if $modelValue are not identical but match caselessly' , function ( ) {
295+ $scope . confirmation = "VALUE" ;
296+ compiled = $compile ( validTemplate ) ( $scope ) ;
297+ $scope . original = "value" ;
298+ $scope . $digest ( ) ;
299+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . false ( ) ;
300+ } ) ;
301+
302+ it ( 'returns false if $modelValue are not identical' , function ( ) {
303+ $scope . confirmation = false ;
304+ $scope . original = undefined ;
305+ compiled = $compile ( validTemplate ) ( $scope ) ;
306+ $scope . $digest ( ) ;
307+ expect ( compiled . hasClass ( 'ng-valid' ) ) . to . be . true ( ) ;
308+ } ) ;
309+
310+ } ) ;
311+
312+
313+ describe ( 'Form level validation' , function ( ) {
314+ var form ,
315+ element ,
316+ inputValue = 'testValue' ;
317+
318+ beforeEach ( function ( ) {
319+ element = angular . element (
320+ '<form name="form">' +
321+ '<input type="text" ng-model="test" name="test"></input>' +
322+ '<input type="text" match="form.test" match-caseless="true" not-match="true" ng-model="testConfirm" name="testConfirm"></input>' +
323+ '</form>'
324+ ) ;
325+ $scope . test = inputValue ;
326+ $compile ( element ) ( $scope ) ;
327+ $scope . $digest ( ) ;
328+ form = $scope . form ;
329+ } ) ;
330+
331+ it ( 'should check if $viewValues are identical' , function ( ) {
332+ form . testConfirm . $setViewValue ( inputValue ) ;
333+ $scope . $digest ( ) ;
334+ expect ( form . testConfirm . $error . match ) . to . be . true ( ) ;
335+ } ) ;
336+
337+ it ( 'should check if $viewValues are not identical but match caselessly' , function ( ) {
338+ form . testConfirm . $setViewValue ( inputValue . toUpperCase ( ) ) ;
339+ $scope . $digest ( ) ;
340+ expect ( form . testConfirm . $error . match ) . to . be . true ( ) ;
341+ } ) ;
342+
343+ it ( 'should check if $viewValues are not identical' , function ( ) {
344+ form . testConfirm . $setViewValue ( inputValue + 'extra' ) ;
345+ $scope . $digest ( ) ;
346+ expect ( form . testConfirm . $error . match ) . to . be . undefined ( ) ;
347+ } ) ;
348+
183349 } ) ;
184350
185351 } ) ;
0 commit comments