spec.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. describe('api', function() {
  2. // Override the options
  3. $.extend($.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  4. feedbackIcons: {
  5. valid: 'glyphicon glyphicon-ok',
  6. invalid: 'glyphicon glyphicon-remove',
  7. validating: 'glyphicon glyphicon-refresh'
  8. }
  9. });
  10. beforeEach(function() {
  11. $([
  12. '<div class="container">',
  13. '<form class="form-horizontal" id="apiForm">',
  14. '<div class="form-group">',
  15. '<input type="text" name="username" data-bv-notempty />',
  16. '</div>',
  17. '<div class="form-group">',
  18. '<input type="text" name="email" data-bv-emailaddress />',
  19. '</div>',
  20. '</form>',
  21. '</div>'
  22. ].join('\n')).appendTo('body');
  23. $('#apiForm').bootstrapValidator();
  24. this.bv = $('#apiForm').data('bootstrapValidator');
  25. this.$email = this.bv.getFieldElements('email');
  26. });
  27. afterEach(function() {
  28. $('#apiForm').bootstrapValidator('destroy').parent().remove();
  29. });
  30. it('call revalidateField()', function() {
  31. this.$email.val('email@domain.com');
  32. this.bv.validate();
  33. expect(this.bv.isValidField('email')).toBeTruthy();
  34. this.$email.val('invalid#email.address');
  35. this.bv.revalidateField('email');
  36. expect(this.bv.isValidField(this.$email)).toEqual(false);
  37. });
  38. it('call destroy()', function() {
  39. this.bv.destroy();
  40. expect($('#apiForm').data('bootstrapValidator')).toBeUndefined();
  41. expect($('#apiForm').find('i[data-bv-icon-for]').length).toEqual(0);
  42. expect($('#apiForm').find('.help-block[data-bv-for]').length).toEqual(0);
  43. expect($('#apiForm').find('.has-feedback').length).toEqual(0);
  44. expect($('#apiForm').find('.has-success').length).toEqual(0);
  45. expect($('#apiForm').find('.has-error').length).toEqual(0);
  46. expect($('#apiForm').find('[data-bv-field]').length).toEqual(0);
  47. });
  48. });
  49. function onEmailValid(e, data) {
  50. $('#msg').html(data.field + ' is valid');
  51. };
  52. function onEmailInvalid(e, data) {
  53. $('#msg').html(data.field + ' is invalid');
  54. };
  55. describe('event field attribute callback global', function() {
  56. beforeEach(function() {
  57. var html = [
  58. '<div class="container">',
  59. '<form class="form-horizontal" id="eventForm">',
  60. '<div id="msg"></div>',
  61. '<div class="form-group">',
  62. '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" />',
  63. '</div>',
  64. '</form>',
  65. '</div>'
  66. ].join('\n');
  67. $(html).appendTo('body');
  68. $('#eventForm').bootstrapValidator();
  69. this.bv = $('#eventForm').data('bootstrapValidator');
  70. this.$email = this.bv.getFieldElements('email');
  71. });
  72. afterEach(function() {
  73. $('#eventForm').bootstrapValidator('destroy').parent().remove();
  74. });
  75. it('call data-bv-onsuccess', function() {
  76. this.$email.val('email@domain.com');
  77. this.bv.validate();
  78. expect($('#msg').html()).toEqual('email is valid');
  79. });
  80. it('call data-bv-onerror', function() {
  81. this.$email.val('email@domain');
  82. this.bv.validate();
  83. expect($('#msg').html()).toEqual('email is invalid');
  84. });
  85. });
  86. var My = {
  87. NameSpace: {
  88. onEmailValid: function(e, data) {
  89. $('#msg').html('My.NameSpace.onEmailValid() called, ' + data.field + ' is valid');
  90. },
  91. onEmailInvalid: function(e, data) {
  92. $('#msg').html('My.NameSpace.onEmailInvalid() called, ' + data.field + ' is invalid');
  93. }
  94. }
  95. };
  96. describe('event field attribute callback namespace', function() {
  97. beforeEach(function() {
  98. var html = [
  99. '<div class="container">',
  100. '<form class="form-horizontal" id="eventForm">',
  101. '<div id="msg"></div>',
  102. '<div class="form-group">',
  103. '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="My.NameSpace.onEmailValid" data-bv-onerror="My.NameSpace.onEmailInvalid" />',
  104. '</div>',
  105. '</form>',
  106. '</div>'
  107. ].join('\n');
  108. $(html).appendTo('body');
  109. $('#eventForm').bootstrapValidator();
  110. this.bv = $('#eventForm').data('bootstrapValidator');
  111. this.$email = this.bv.getFieldElements('email');
  112. });
  113. afterEach(function() {
  114. $('#eventForm').bootstrapValidator('destroy').parent().remove();
  115. });
  116. it('call data-bv-onsuccess', function() {
  117. this.$email.val('email@domain.com');
  118. this.bv.validate();
  119. expect($('#msg').html()).toEqual('My.NameSpace.onEmailValid() called, email is valid');
  120. });
  121. it('call data-bv-onerror', function() {
  122. this.$email.val('email@domain');
  123. this.bv.validate();
  124. expect($('#msg').html()).toEqual('My.NameSpace.onEmailInvalid() called, email is invalid');
  125. });
  126. });
  127. describe('event field trigger', function() {
  128. beforeEach(function() {
  129. var html = [
  130. '<div class="container">',
  131. '<form class="form-horizontal" id="eventForm">',
  132. '<div id="msg"></div>',
  133. '<div class="form-group">',
  134. '<input type="text" name="email" data-bv-emailaddress />',
  135. '</div>',
  136. '</form>',
  137. '</div>'
  138. ].join('\n');
  139. $(html).appendTo('body');
  140. $('#eventForm')
  141. .bootstrapValidator()
  142. .on('success.field.bv', '[name="email"]', function(e, data) {
  143. $('#msg').html('triggered success.field.bv on ' + data.field);
  144. })
  145. .on('error.field.bv', '[name="email"]', function(e, data) {
  146. $('#msg').html('triggered error.field.bv on ' + data.field);
  147. });
  148. this.bv = $('#eventForm').data('bootstrapValidator');
  149. this.$email = this.bv.getFieldElements('email');
  150. });
  151. afterEach(function() {
  152. $('#eventForm').bootstrapValidator('destroy').parent().remove();
  153. });
  154. it('trigger success.field.bv', function() {
  155. this.$email.val('email@domain.com');
  156. this.bv.validate();
  157. expect($('#msg').html()).toEqual('triggered success.field.bv on email');
  158. });
  159. it('trigger error.field.bv', function() {
  160. this.$email.val('email@domain');
  161. this.bv.validate();
  162. expect($('#msg').html()).toEqual('triggered error.field.bv on email');
  163. });
  164. });
  165. describe('event field programmatically', function() {
  166. beforeEach(function() {
  167. var html = [
  168. '<div class="container">',
  169. '<form class="form-horizontal" id="eventForm">',
  170. '<div id="msg"></div>',
  171. '<div class="form-group">',
  172. '<input type="text" name="email" data-bv-emailaddress />',
  173. '</div>',
  174. '</form>',
  175. '</div>'
  176. ].join('\n');
  177. $(html).appendTo('body');
  178. $('#eventForm').bootstrapValidator({
  179. fields: {
  180. email: {
  181. onSuccess: function(e, data) {
  182. $('#msg').html('onSuccess() called');
  183. },
  184. onError: function(e, data) {
  185. $('#msg').html('onError() called');
  186. },
  187. validator: {
  188. emailAddress: {}
  189. }
  190. }
  191. }
  192. });
  193. this.bv = $('#eventForm').data('bootstrapValidator');
  194. this.$email = this.bv.getFieldElements('email');
  195. });
  196. afterEach(function() {
  197. $('#eventForm').bootstrapValidator('destroy').parent().remove();
  198. });
  199. it('call onSuccess()', function() {
  200. this.$email.val('email@domain.com');
  201. this.bv.validate();
  202. expect($('#msg').html()).toEqual('onSuccess() called');
  203. });
  204. it('call onError()', function() {
  205. this.$email.val('email@domain');
  206. this.bv.validate();
  207. expect($('#msg').html()).toEqual('onError() called');
  208. });
  209. });
  210. describe('excluded', function() {
  211. beforeEach(function() {
  212. $([
  213. '<div class="container">',
  214. '<form class="form-horizontal" id="excludedForm" data-bv-excluded="[name=\'email\']">',
  215. '<div class="form-group">',
  216. '<input type="text" name="username" required />',
  217. '</div>',
  218. '<div class="form-group">',
  219. '<input type="text" name="email" required data-bv-emailaddress />',
  220. '</div>',
  221. '</form>',
  222. '</div>'
  223. ].join('')).appendTo('body');
  224. $('#excludedForm').bootstrapValidator();
  225. this.bv = $('#excludedForm').data('bootstrapValidator');
  226. this.$username = this.bv.getFieldElements('username');
  227. this.$email = this.bv.getFieldElements('email');
  228. });
  229. afterEach(function() {
  230. $('#excludedForm').bootstrapValidator('destroy').parent().remove();
  231. });
  232. it('excluded form declarative', function() {
  233. this.bv.validate();
  234. expect(this.bv.isValid()).toEqual(false);
  235. this.bv.resetForm();
  236. this.$username.val('your_user_name');
  237. this.$email.val('');
  238. this.bv.validate();
  239. expect(this.bv.isValid()).toBeTruthy();
  240. });
  241. it('excluded form programmatically', function() {
  242. this.bv.destroy();
  243. $('#excludedForm').removeAttr('data-bv-excluded');
  244. $('#excludedForm').bootstrapValidator({
  245. excluded: '[name="username"]'
  246. });
  247. this.bv = $('#excludedForm').data('bootstrapValidator');
  248. this.$username = this.bv.getFieldElements('username');
  249. this.$email = this.bv.getFieldElements('email');
  250. this.$username.val('');
  251. this.$email.val('invalid#email.com');
  252. this.bv.validate();
  253. expect(this.bv.isValid()).toEqual(false);
  254. this.bv.resetForm();
  255. this.$email.val('valid@email.com');
  256. this.bv.validate();
  257. expect(this.bv.isValid()).toBeTruthy();
  258. });
  259. it('excluded field declarative', function() {
  260. this.bv.destroy();
  261. $('#excludedForm').removeAttr('data-bv-excluded');
  262. $('#excludedForm').find('[name="username"]').attr('data-bv-excluded', 'true');
  263. $('#excludedForm').find('[name="email"]').attr('data-bv-excluded', 'false');
  264. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  265. this.$username = this.bv.getFieldElements('username');
  266. this.$email = this.bv.getFieldElements('email');
  267. this.$username.val('');
  268. this.$email.val('');
  269. this.bv.validate();
  270. expect(this.bv.isValid()).toEqual(false);
  271. this.bv.resetForm();
  272. this.$email.val('invalid#email.com');
  273. this.bv.validate();
  274. expect(this.bv.isValid()).toEqual(false);
  275. this.bv.resetForm();
  276. this.$email.val('valid@email.com');
  277. this.bv.validate();
  278. expect(this.bv.isValid()).toBeTruthy();
  279. });
  280. it('excluded field programmatically true/false', function() {
  281. this.bv.destroy();
  282. $('#excludedForm').removeAttr('data-bv-excluded');
  283. $('#excludedForm').bootstrapValidator({
  284. fields: {
  285. username: {
  286. excluded: true
  287. },
  288. email: {
  289. excluded: false
  290. }
  291. }
  292. });
  293. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  294. this.$username = this.bv.getFieldElements('username');
  295. this.$email = this.bv.getFieldElements('email');
  296. this.$username.val('');
  297. this.$email.val('');
  298. this.bv.validate();
  299. expect(this.bv.isValid()).toEqual(false);
  300. this.bv.resetForm();
  301. this.$email.val('invalid#email.com');
  302. this.bv.validate();
  303. expect(this.bv.isValid()).toEqual(false);
  304. this.bv.resetForm();
  305. this.$email.val('valid@email.com');
  306. this.bv.validate();
  307. expect(this.bv.isValid()).toBeTruthy();
  308. });
  309. it('excluded field programmatically "true"/"false"', function() {
  310. this.bv.destroy();
  311. $('#excludedForm').removeAttr('data-bv-excluded');
  312. $('#excludedForm').bootstrapValidator({
  313. fields: {
  314. username: {
  315. excluded: 'false'
  316. },
  317. email: {
  318. excluded: 'true'
  319. }
  320. }
  321. });
  322. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  323. this.$username = this.bv.getFieldElements('username');
  324. this.$email = this.bv.getFieldElements('email');
  325. this.$username.val('');
  326. this.$email.val('valid@email.com');
  327. this.bv.validate();
  328. expect(this.bv.isValid()).toEqual(false);
  329. this.bv.resetForm();
  330. this.$username.val('your_user_name');
  331. this.$email.val('invalid#email.com');
  332. this.bv.validate();
  333. expect(this.bv.isValid()).toBeTruthy();
  334. });
  335. });
  336. describe('message', function() {
  337. beforeEach(function() {
  338. var html = [
  339. '<div class="container">',
  340. '<form class="form-horizontal" id="messageForm">',
  341. '<div class="form-group">',
  342. '<input type="password" class="form-control" name="password" placeholder="Enter secure password" />',
  343. '</div>',
  344. '</form>',
  345. '</div>'
  346. ].join('\n');
  347. $(html).appendTo('body');
  348. $('#messageForm').bootstrapValidator({
  349. fields: {
  350. password: {
  351. validators: {
  352. notEmpty: {
  353. message: 'The password is required'
  354. },
  355. callback: {
  356. callback: function(value, validator) {
  357. // Check the password strength
  358. if (value.length < 6) {
  359. return {
  360. valid: false,
  361. message: 'The password must be more than 6 characters'
  362. }
  363. }
  364. if (value === value.toLowerCase()) {
  365. return {
  366. valid: false,
  367. message: 'The password must contain at least one upper case character'
  368. }
  369. }
  370. if (value === value.toUpperCase()) {
  371. return {
  372. valid: false,
  373. message: 'The password must contain at least one lower case character'
  374. }
  375. }
  376. if (value.search(/[0-9]/) < 0) {
  377. return {
  378. valid: false,
  379. message: 'The password must contain at least one digit'
  380. }
  381. }
  382. return true;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. });
  389. this.bv = $('#messageForm').data('bootstrapValidator');
  390. this.$password = this.bv.getFieldElements('password');
  391. });
  392. afterEach(function() {
  393. $('#messageForm').bootstrapValidator('destroy').parent().remove();
  394. });
  395. it('update message from callback', function() {
  396. this.bv.resetForm();
  397. this.$password.val('123');
  398. this.bv.validate();
  399. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must be more than 6 characters');
  400. this.bv.resetForm();
  401. this.$password.val('no_upper_case!@#');
  402. this.bv.validate();
  403. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one upper case character');
  404. this.bv.resetForm();
  405. this.$password.val('NO_LOWER_CASE123');
  406. this.bv.validate();
  407. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one lower case character');
  408. this.bv.resetForm();
  409. this.$password.val('NoDigits!@#');
  410. this.bv.validate();
  411. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one digit');
  412. });
  413. it('call updateMessage()', function() {
  414. this.bv.updateStatus('password', this.bv.STATUS_INVALID, 'callback');
  415. this.bv.updateMessage('password', 'callback', 'The password is weak');
  416. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password is weak');
  417. this.bv.updateMessage(this.$password, 'callback', 'The password is not strong');
  418. expect(this.bv.getMessages(this.$password, 'callback')[0]).toEqual('The password is not strong');
  419. });
  420. });
  421. function validateCaptcha(value, validator, $field) {
  422. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  423. return value === sum + '';
  424. };
  425. describe('callback', function() {
  426. beforeEach(function() {
  427. $(['<div class="container">',
  428. '<form class="form-horizontal" id="callbackForm">',
  429. '<div class="form-group">',
  430. '<label class="col-md-3 control-label" id="captchaOperation"></label>',
  431. '<div class="col-md-2">',
  432. '<input type="text" class="form-control" name="captcha" />',
  433. '</div>',
  434. '</div>',
  435. '<div class="form-group">',
  436. '<div class="col-md-2 col-md-offset-3">',
  437. '<input type="text" class="form-control" name="declarativeCaptcha" data-bv-callback data-bv-callback-callback="validateCaptcha" />',
  438. '</div>',
  439. '</div>',
  440. '</form>',
  441. '</div>'
  442. ].join('\n')).appendTo('body');
  443. $('#callbackForm').bootstrapValidator({
  444. fields: {
  445. captcha: {
  446. validators: {
  447. callback: {
  448. message: 'Wrong answer',
  449. callback: function(value, validator, $field) {
  450. return validateCaptcha(value, validator, $field);
  451. }
  452. }
  453. }
  454. }
  455. }
  456. });
  457. this.bv = $('#callbackForm').data('bootstrapValidator');
  458. this.$captcha = this.bv.getFieldElements('captcha');
  459. this.$declarativeCaptcha = this.bv.getFieldElements('declarativeCaptcha');
  460. });
  461. afterEach(function() {
  462. $('#callbackForm').bootstrapValidator('destroy').parent().remove();
  463. });
  464. it('execute the callback', function() {
  465. $('#captchaOperation').html('1 + 2');
  466. this.$captcha.val('3');
  467. this.bv.validate();
  468. expect(this.bv.isValidField('captcha')).toBeTruthy();
  469. this.bv.resetForm();
  470. this.$captcha.val('5');
  471. this.bv.validate();
  472. expect(this.bv.isValidField('captcha')).toEqual(false);
  473. });
  474. it('callback declarative', function() {
  475. $('#captchaOperation').html('10 + 20');
  476. this.$declarativeCaptcha.val('40');
  477. this.bv.validate();
  478. expect(this.bv.isValidField('declarativeCaptcha')).toEqual(false);
  479. this.bv.resetForm();
  480. this.$declarativeCaptcha.val('30');
  481. this.bv.validate();
  482. expect(this.bv.isValidField('declarativeCaptcha')).toBeTruthy();
  483. });
  484. });
  485. describe('creditCard', function() {
  486. // Get the fake credit card number at http://www.getcreditcardnumbers.com/
  487. beforeEach(function() {
  488. var html = [
  489. '<div class="container">',
  490. '<form class="form-horizontal" id="ccForm">',
  491. '<div class="form-group">',
  492. '<input type="text" name="cc" data-bv-creditcard />',
  493. '</div>',
  494. '</form>',
  495. '</div>'
  496. ].join('\n');
  497. $(html).appendTo('body');
  498. $('#ccForm').bootstrapValidator();
  499. this.bv = $('#ccForm').data('bootstrapValidator');
  500. this.$creditCard = this.bv.getFieldElements('cc');
  501. });
  502. afterEach(function() {
  503. $('#ccForm').bootstrapValidator('destroy').parent().remove();
  504. });
  505. it('accept spaces', function() {
  506. this.$creditCard.val('5267 9789 9451 9654');
  507. this.bv.validate();
  508. expect(this.bv.isValidField('cc')).toBeTruthy();
  509. });
  510. it('accept dashes', function() {
  511. this.$creditCard.val('6011-2649-6840-4521');
  512. this.bv.validate();
  513. expect(this.bv.isValidField('cc')).toBeTruthy();
  514. });
  515. it('invalid format', function() {
  516. this.$creditCard.val('4539.1870.2954.3862');
  517. this.bv.validate();
  518. expect(this.bv.isValidField('cc')).toEqual(false);
  519. });
  520. it('American Express', function() {
  521. this.$creditCard.val('340653705597107');
  522. this.bv.validate();
  523. expect(this.bv.isValidField('cc')).toBeTruthy();
  524. });
  525. it('American Express invalid length', function() {
  526. this.$creditCard.val('3744148309166730');
  527. this.bv.validate();
  528. expect(this.bv.isValidField('cc')).toEqual(false);
  529. });
  530. it('American Express invalid prefix', function() {
  531. this.$creditCard.val('356120148436654');
  532. this.bv.validate();
  533. expect(this.bv.isValidField('cc')).toEqual(false);
  534. });
  535. it('Diners Club', function() {
  536. this.$creditCard.val('30130708434187');
  537. this.bv.validate();
  538. expect(this.bv.isValidField('cc')).toBeTruthy();
  539. });
  540. it('Diners Club (US)', function() {
  541. this.$creditCard.val('5517479515603901');
  542. this.bv.validate();
  543. expect(this.bv.isValidField('cc')).toBeTruthy();
  544. });
  545. it('Discover', function() {
  546. this.$creditCard.val('6011734674929094');
  547. this.bv.validate();
  548. expect(this.bv.isValidField('cc')).toBeTruthy();
  549. });
  550. it('JCB', function() {
  551. this.$creditCard.val('3566002020360505');
  552. this.bv.validate();
  553. expect(this.bv.isValidField('cc')).toBeTruthy();
  554. });
  555. it('Laser', function() {
  556. this.$creditCard.val('6304 9000 1774 0292 441');
  557. this.bv.validate();
  558. expect(this.bv.isValidField('cc')).toBeTruthy();
  559. });
  560. it('Maestro', function() {
  561. this.$creditCard.val('6762835098779303');
  562. this.bv.validate();
  563. expect(this.bv.isValidField('cc')).toBeTruthy();
  564. });
  565. it('Mastercard', function() {
  566. this.$creditCard.val('5303765013600904');
  567. this.bv.validate();
  568. expect(this.bv.isValidField('cc')).toBeTruthy();
  569. });
  570. it('Solo', function() {
  571. this.$creditCard.val('6334580500000000');
  572. this.bv.validate();
  573. expect(this.bv.isValidField('cc')).toBeTruthy();
  574. });
  575. it('Visa', function() {
  576. this.$creditCard.val('4929248980295542');
  577. this.bv.validate();
  578. expect(this.bv.isValidField('cc')).toBeTruthy();
  579. });
  580. it('Visa invalid check digit', function() {
  581. this.$creditCard.val('4532599916257826');
  582. this.bv.validate();
  583. expect(this.bv.isValidField('cc')).toEqual(false);
  584. });
  585. });
  586. describe('ean', function() {
  587. beforeEach(function() {
  588. var html = [
  589. '<div class="container">',
  590. '<form class="form-horizontal" id="eanForm">',
  591. '<div class="form-group">',
  592. '<input type="text" name="ean" data-bv-ean />',
  593. '</div>',
  594. '</form>',
  595. '</div>'
  596. ].join('\n');
  597. $(html).appendTo('body');
  598. $('#eanForm').bootstrapValidator();
  599. this.bv = $('#eanForm').data('bootstrapValidator');
  600. this.$ean = this.bv.getFieldElements('ean');
  601. });
  602. afterEach(function() {
  603. $('#eanForm').bootstrapValidator('destroy').parent().remove();
  604. });
  605. it('valid', function() {
  606. var samples = ['73513537', '9780471117094', '4006381333931'];
  607. for (var i in samples) {
  608. this.$ean.val(samples[i]);
  609. this.bv.validate();
  610. expect(this.bv.isValidField('ean')).toBeTruthy();
  611. }
  612. });
  613. it('contains only digits', function() {
  614. this.$ean.val('123abcDEF!@#');
  615. this.bv.validate();
  616. expect(this.bv.isValidField('ean')).toEqual(false);
  617. });
  618. it('invalid length', function() {
  619. this.$ean.val('1234567');
  620. this.bv.validate();
  621. expect(this.bv.isValidField('ean')).toEqual(false);
  622. });
  623. it('invalid check digit', function() {
  624. this.$ean.val('73513536');
  625. this.bv.validate();
  626. expect(this.bv.isValidField('ean')).toEqual(false);
  627. });
  628. });
  629. describe('iban', function() {
  630. beforeEach(function() {
  631. var html = [
  632. '<div class="container">',
  633. '<form class="form-horizontal" id="ibanForm">',
  634. '<div class="form-group">',
  635. '<input type="text" name="iban" data-bv-iban />',
  636. '</div>',
  637. '</form>',
  638. '</div>'
  639. ].join('\n');
  640. $(html).appendTo('body');
  641. $('#ibanForm').bootstrapValidator();
  642. this.bv = $('#ibanForm').data('bootstrapValidator');
  643. this.$iban = this.bv.getFieldElements('iban');
  644. });
  645. afterEach(function() {
  646. $('#ibanForm').bootstrapValidator('destroy').parent().remove();
  647. });
  648. it('not supported country', function() {
  649. this.$iban.val('US123456789');
  650. this.bv.validate();
  651. expect(this.bv.isValidField('iban')).toEqual(false);
  652. });
  653. it('Albania', function() {
  654. this.$iban.val('AL47212110090000000235698741');
  655. this.bv.validate();
  656. expect(this.bv.isValidField('iban')).toBeTruthy();
  657. });
  658. it('Algeria', function() {
  659. this.$iban.val('DZ4000400174401001050486');
  660. this.bv.validate();
  661. expect(this.bv.isValidField('iban')).toBeTruthy();
  662. });
  663. it('Andorra', function() {
  664. this.$iban.val('AD1200012030200359100100');
  665. this.bv.validate();
  666. expect(this.bv.isValidField('iban')).toBeTruthy();
  667. });
  668. it('Angola', function() {
  669. this.$iban.val('AO06000600000100037131174');
  670. this.bv.validate();
  671. expect(this.bv.isValidField('iban')).toBeTruthy();
  672. });
  673. it('Austria', function() {
  674. this.$iban.val('AT611904300234573201');
  675. this.bv.validate();
  676. expect(this.bv.isValidField('iban')).toBeTruthy();
  677. });
  678. it('Azerbaijan', function() {
  679. this.$iban.val('AZ21NABZ00000000137010001944');
  680. this.bv.validate();
  681. expect(this.bv.isValidField('iban')).toBeTruthy();
  682. });
  683. it('Bahrain', function() {
  684. this.$iban.val('BH29BMAG1299123456BH00');
  685. this.bv.validate();
  686. expect(this.bv.isValidField('iban')).toBeTruthy();
  687. });
  688. it('Belgium', function() {
  689. this.$iban.val('BE68539007547034');
  690. this.bv.validate();
  691. expect(this.bv.isValidField('iban')).toBeTruthy();
  692. });
  693. it('Benin', function() {
  694. this.$iban.val('BJ11B00610100400271101192591');
  695. this.bv.validate();
  696. expect(this.bv.isValidField('iban')).toBeTruthy();
  697. });
  698. it('Brazil', function() {
  699. this.$iban.val('BR9700360305000010009795493P1');
  700. this.bv.validate();
  701. expect(this.bv.isValidField('iban')).toBeTruthy();
  702. });
  703. it('Bulgaria', function() {
  704. this.$iban.val('BG80BNBG96611020345678');
  705. this.bv.validate();
  706. expect(this.bv.isValidField('iban')).toBeTruthy();
  707. });
  708. it('Burkina Faso', function() {
  709. this.$iban.val('BF1030134020015400945000643');
  710. this.bv.validate();
  711. expect(this.bv.isValidField('iban')).toBeTruthy();
  712. });
  713. it('Burundi', function() {
  714. this.$iban.val('BI43201011067444');
  715. this.bv.validate();
  716. expect(this.bv.isValidField('iban')).toBeTruthy();
  717. });
  718. it('Cameroon', function() {
  719. this.$iban.val('CM2110003001000500000605306');
  720. this.bv.validate();
  721. expect(this.bv.isValidField('iban')).toBeTruthy();
  722. });
  723. it('Cape Verde', function() {
  724. this.$iban.val('CV64000300004547069110176');
  725. this.bv.validate();
  726. expect(this.bv.isValidField('iban')).toBeTruthy();
  727. });
  728. it('Costa Rica', function() {
  729. this.$iban.val('CR0515202001026284066');
  730. this.bv.validate();
  731. expect(this.bv.isValidField('iban')).toBeTruthy();
  732. });
  733. it('Croatia', function() {
  734. this.$iban.val('HR1210010051863000160');
  735. this.bv.validate();
  736. expect(this.bv.isValidField('iban')).toBeTruthy();
  737. });
  738. it('Cyprus', function() {
  739. this.$iban.val('CY17002001280000001200527600');
  740. this.bv.validate();
  741. expect(this.bv.isValidField('iban')).toBeTruthy();
  742. });
  743. it('Czech Republic', function() {
  744. this.$iban.val('CZ6508000000192000145399');
  745. this.bv.validate();
  746. expect(this.bv.isValidField('iban')).toBeTruthy();
  747. });
  748. it('Denmark', function() {
  749. this.$iban.val('DK5000400440116243');
  750. this.bv.validate();
  751. expect(this.bv.isValidField('iban')).toBeTruthy();
  752. });
  753. it('Dominican Republic', function() {
  754. this.$iban.val('DO28BAGR00000001212453611324');
  755. this.bv.validate();
  756. expect(this.bv.isValidField('iban')).toBeTruthy();
  757. });
  758. it('Estonia', function() {
  759. this.$iban.val('EE382200221020145685');
  760. this.bv.validate();
  761. expect(this.bv.isValidField('iban')).toBeTruthy();
  762. });
  763. it('Faroe Islands', function() {
  764. this.$iban.val('FO1464600009692713');
  765. this.bv.validate();
  766. expect(this.bv.isValidField('iban')).toBeTruthy();
  767. });
  768. it('Finland', function() {
  769. this.$iban.val('FI2112345600000785');
  770. this.bv.validate();
  771. expect(this.bv.isValidField('iban')).toBeTruthy();
  772. });
  773. it('France', function() {
  774. this.$iban.val('FR1420041010050500013M02606');
  775. this.bv.validate();
  776. expect(this.bv.isValidField('iban')).toBeTruthy();
  777. });
  778. it('Guatemala', function() {
  779. this.$iban.val('GT82TRAJ01020000001210029690');
  780. this.bv.validate();
  781. expect(this.bv.isValidField('iban')).toBeTruthy();
  782. });
  783. it('Georgia', function() {
  784. this.$iban.val('GE29NB0000000101904917');
  785. this.bv.validate();
  786. expect(this.bv.isValidField('iban')).toBeTruthy();
  787. });
  788. it('Germany', function() {
  789. this.$iban.val('DE89370400440532013000');
  790. this.bv.validate();
  791. expect(this.bv.isValidField('iban')).toBeTruthy();
  792. });
  793. it('Gibraltar', function() {
  794. this.$iban.val('GI75NWBK000000007099453');
  795. this.bv.validate();
  796. expect(this.bv.isValidField('iban')).toBeTruthy();
  797. });
  798. it('Greece', function() {
  799. this.$iban.val('GR1601101250000000012300695');
  800. this.bv.validate();
  801. expect(this.bv.isValidField('iban')).toBeTruthy();
  802. });
  803. it('Greenland', function() {
  804. this.$iban.val('GL8964710001000206');
  805. this.bv.validate();
  806. expect(this.bv.isValidField('iban')).toBeTruthy();
  807. });
  808. it('Hungary', function() {
  809. this.$iban.val('HU42117730161111101800000000');
  810. this.bv.validate();
  811. expect(this.bv.isValidField('iban')).toBeTruthy();
  812. });
  813. it('Iceland', function() {
  814. this.$iban.val('IS140159260076545510730339');
  815. this.bv.validate();
  816. expect(this.bv.isValidField('iban')).toBeTruthy();
  817. });
  818. it('Iran', function() {
  819. this.$iban.val('IR580540105180021273113007');
  820. this.bv.validate();
  821. expect(this.bv.isValidField('iban')).toBeTruthy();
  822. });
  823. it('Ireland', function() {
  824. this.$iban.val('IE29AIBK93115212345678');
  825. this.bv.validate();
  826. expect(this.bv.isValidField('iban')).toBeTruthy();
  827. });
  828. it('Israel', function() {
  829. this.$iban.val('IL620108000000099999999');
  830. this.bv.validate();
  831. expect(this.bv.isValidField('iban')).toBeTruthy();
  832. });
  833. it('Italy', function() {
  834. this.$iban.val('IT60X0542811101000000123456');
  835. this.bv.validate();
  836. expect(this.bv.isValidField('iban')).toBeTruthy();
  837. });
  838. it('Ivory Coast', function() {
  839. this.$iban.val('CI05A00060174100178530011852');
  840. this.bv.validate();
  841. expect(this.bv.isValidField('iban')).toBeTruthy();
  842. });
  843. it('Jordan', function() {
  844. this.$iban.val('JO94CBJO0010000000000131000302');
  845. this.bv.validate();
  846. expect(this.bv.isValidField('iban')).toBeTruthy();
  847. });
  848. it('Kazakhstan', function() {
  849. this.$iban.val('KZ176010251000042993');
  850. this.bv.validate();
  851. expect(this.bv.isValidField('iban')).toBeTruthy();
  852. });
  853. it('Kuwait', function() {
  854. this.$iban.val('KW74NBOK0000000000001000372151');
  855. this.bv.validate();
  856. expect(this.bv.isValidField('iban')).toBeTruthy();
  857. });
  858. it('Latvia', function() {
  859. this.$iban.val('LV80BANK0000435195001');
  860. this.bv.validate();
  861. expect(this.bv.isValidField('iban')).toBeTruthy();
  862. });
  863. it('Lebanon', function() {
  864. this.$iban.val('LB30099900000001001925579115');
  865. this.bv.validate();
  866. expect(this.bv.isValidField('iban')).toBeTruthy();
  867. });
  868. it('Liechtenstein', function() {
  869. this.$iban.val('LI21088100002324013AA');
  870. this.bv.validate();
  871. expect(this.bv.isValidField('iban')).toBeTruthy();
  872. });
  873. it('Lithuania', function() {
  874. this.$iban.val('LT121000011101001000');
  875. this.bv.validate();
  876. expect(this.bv.isValidField('iban')).toBeTruthy();
  877. });
  878. it('Luxembourg', function() {
  879. this.$iban.val('LU280019400644750000');
  880. this.bv.validate();
  881. expect(this.bv.isValidField('iban')).toBeTruthy();
  882. });
  883. it('Macedonia', function() {
  884. this.$iban.val('MK07300000000042425');
  885. this.bv.validate();
  886. expect(this.bv.isValidField('iban')).toBeTruthy();
  887. });
  888. it('Madagascar', function() {
  889. this.$iban.val('MG4600005030010101914016056');
  890. this.bv.validate();
  891. expect(this.bv.isValidField('iban')).toBeTruthy();
  892. });
  893. it('Malta', function() {
  894. this.$iban.val('MT84MALT011000012345MTLCAST001S');
  895. this.bv.validate();
  896. expect(this.bv.isValidField('iban')).toBeTruthy();
  897. });
  898. it('Mauritania', function() {
  899. this.$iban.val('MR1300012000010000002037372');
  900. this.bv.validate();
  901. expect(this.bv.isValidField('iban')).toBeTruthy();
  902. });
  903. it('Mauritius', function() {
  904. this.$iban.val('MU17BOMM0101101030300200000MUR');
  905. this.bv.validate();
  906. expect(this.bv.isValidField('iban')).toBeTruthy();
  907. });
  908. it('Mali', function() {
  909. this.$iban.val('ML03D00890170001002120000447');
  910. this.bv.validate();
  911. expect(this.bv.isValidField('iban')).toBeTruthy();
  912. });
  913. it('Moldova', function() {
  914. this.$iban.val('MD24AG000225100013104168');
  915. this.bv.validate();
  916. expect(this.bv.isValidField('iban')).toBeTruthy();
  917. });
  918. it('Monaco', function() {
  919. this.$iban.val('MC5813488000010051108001292');
  920. this.bv.validate();
  921. expect(this.bv.isValidField('iban')).toBeTruthy();
  922. });
  923. it('Montenegro', function() {
  924. this.$iban.val('ME25505000012345678951');
  925. this.bv.validate();
  926. expect(this.bv.isValidField('iban')).toBeTruthy();
  927. });
  928. it('Mozambique', function() {
  929. this.$iban.val('MZ59000100000011834194157');
  930. this.bv.validate();
  931. expect(this.bv.isValidField('iban')).toBeTruthy();
  932. });
  933. it('Netherlands', function() {
  934. this.$iban.val('NL91ABNA0417164300');
  935. this.bv.validate();
  936. expect(this.bv.isValidField('iban')).toBeTruthy();
  937. });
  938. it('Norway', function() {
  939. this.$iban.val('NO9386011117947');
  940. this.bv.validate();
  941. expect(this.bv.isValidField('iban')).toBeTruthy();
  942. });
  943. it('Pakistan', function() {
  944. this.$iban.val('PK24SCBL0000001171495101');
  945. this.bv.validate();
  946. expect(this.bv.isValidField('iban')).toBeTruthy();
  947. });
  948. it('Palestine', function() {
  949. this.$iban.val('PS92PALS000000000400123456702');
  950. this.bv.validate();
  951. expect(this.bv.isValidField('iban')).toBeTruthy();
  952. });
  953. it('Poland', function() {
  954. this.$iban.val('PL27114020040000300201355387');
  955. this.bv.validate();
  956. expect(this.bv.isValidField('iban')).toBeTruthy();
  957. });
  958. it('Portugal', function() {
  959. this.$iban.val('PT50000201231234567890154');
  960. this.bv.validate();
  961. expect(this.bv.isValidField('iban')).toBeTruthy();
  962. });
  963. it('Qatar', function() {
  964. this.$iban.val('QA58DOHB00001234567890ABCDEFG');
  965. this.bv.validate();
  966. expect(this.bv.isValidField('iban')).toBeTruthy();
  967. });
  968. it('Romania', function() {
  969. this.$iban.val('RO49AAAA1B31007593840000');
  970. this.bv.validate();
  971. expect(this.bv.isValidField('iban')).toBeTruthy();
  972. });
  973. it('San Marino', function() {
  974. this.$iban.val('SM86U0322509800000000270100');
  975. this.bv.validate();
  976. expect(this.bv.isValidField('iban')).toBeTruthy();
  977. });
  978. it('Saudi Arabia', function() {
  979. this.$iban.val('SA0380000000608010167519');
  980. this.bv.validate();
  981. expect(this.bv.isValidField('iban')).toBeTruthy();
  982. });
  983. it('Senegal', function() {
  984. this.$iban.val('SN12K00100152000025690007542');
  985. this.bv.validate();
  986. expect(this.bv.isValidField('iban')).toBeTruthy();
  987. });
  988. it('Serbia', function() {
  989. this.$iban.val('RS35260005601001611379');
  990. this.bv.validate();
  991. expect(this.bv.isValidField('iban')).toBeTruthy();
  992. });
  993. it('Slovakia', function() {
  994. this.$iban.val('SK3112000000198742637541');
  995. this.bv.validate();
  996. expect(this.bv.isValidField('iban')).toBeTruthy();
  997. });
  998. it('Slovenia', function() {
  999. this.$iban.val('SI56191000000123438');
  1000. this.bv.validate();
  1001. expect(this.bv.isValidField('iban')).toBeTruthy();
  1002. });
  1003. it('Spain', function() {
  1004. this.$iban.val('ES9121000418450200051332');
  1005. this.bv.validate();
  1006. expect(this.bv.isValidField('iban')).toBeTruthy();
  1007. });
  1008. it('Sweden', function() {
  1009. this.$iban.val('SE3550000000054910000003');
  1010. this.bv.validate();
  1011. expect(this.bv.isValidField('iban')).toBeTruthy();
  1012. });
  1013. it('Switzerland', function() {
  1014. this.$iban.val('CH9300762011623852957');
  1015. this.bv.validate();
  1016. expect(this.bv.isValidField('iban')).toBeTruthy();
  1017. });
  1018. it('Tunisia', function() {
  1019. this.$iban.val('TN5914207207100707129648');
  1020. this.bv.validate();
  1021. expect(this.bv.isValidField('iban')).toBeTruthy();
  1022. });
  1023. it('Turkey', function() {
  1024. this.$iban.val('TR330006100519786457841326');
  1025. this.bv.validate();
  1026. expect(this.bv.isValidField('iban')).toBeTruthy();
  1027. });
  1028. it('United Arab Emirates', function() {
  1029. this.$iban.val('AE260211000000230064016');
  1030. this.bv.validate();
  1031. expect(this.bv.isValidField('iban')).toBeTruthy();
  1032. });
  1033. it('United Kingdom', function() {
  1034. this.$iban.val('GB29NWBK60161331926819');
  1035. this.bv.validate();
  1036. expect(this.bv.isValidField('iban')).toBeTruthy();
  1037. });
  1038. it('Virgin Islands, British', function() {
  1039. this.$iban.val('VG96VPVG0000012345678901');
  1040. this.bv.validate();
  1041. expect(this.bv.isValidField('iban')).toBeTruthy();
  1042. });
  1043. it('invalid checksum', function() {
  1044. this.$iban.val('TR330006100519786457841325');
  1045. this.bv.validate();
  1046. expect(this.bv.isValidField('iban')).toEqual(false);
  1047. });
  1048. });
  1049. describe('isbn', function() {
  1050. beforeEach(function() {
  1051. var html = [
  1052. '<div class="container">',
  1053. '<form class="form-horizontal" id="isbnForm">',
  1054. '<div class="form-group">',
  1055. '<input type="text" name="isbn" data-bv-isbn />',
  1056. '</div>',
  1057. '</form>',
  1058. '</div>'
  1059. ].join('\n');
  1060. $(html).appendTo('body');
  1061. $('#isbnForm').bootstrapValidator();
  1062. this.bv = $('#isbnForm').data('bootstrapValidator');
  1063. this.$isbn = this.bv.getFieldElements('isbn');
  1064. });
  1065. afterEach(function() {
  1066. $('#isbnForm').bootstrapValidator('destroy').parent().remove();
  1067. });
  1068. it('isbn10 hyphen', function() {
  1069. var samples = ['99921-58-10-7', '9971-5-0210-0', '960-425-059-0', '80-902734-1-6'];
  1070. for (var i in samples) {
  1071. this.$isbn.val(samples[i]);
  1072. this.bv.validate();
  1073. expect(this.bv.isValidField('isbn')).toBeTruthy();
  1074. }
  1075. });
  1076. it('isbn10 space', function() {
  1077. var samples = ['85 359 0277 5', '1 84356 028 3', '0 684 84328 5', '0 85131 041 9', '0 943396 04 2'];
  1078. for (var i in samples) {
  1079. this.$isbn.val(samples[i]);
  1080. this.bv.validate();
  1081. expect(this.bv.isValidField('isbn')).toBeTruthy();
  1082. }
  1083. });
  1084. it('isbn10 hyphen with X', function() {
  1085. var samples = ['0-8044-2957-X', '0-9752298-0-X'];
  1086. for (var i in samples) {
  1087. this.$isbn.val(samples[i]);
  1088. this.bv.validate();
  1089. expect(this.bv.isValidField('isbn')).toBeTruthy();
  1090. }
  1091. });
  1092. it('isbn10 invalid check digit', function() {
  1093. this.$isbn.val('99921-58-10-6');
  1094. this.bv.validate();
  1095. expect(this.bv.isValidField('isbn')).toEqual(false);
  1096. });
  1097. it('isbn13', function() {
  1098. this.$isbn.val('978-0-306-40615-7');
  1099. this.bv.validate();
  1100. expect(this.bv.isValidField('isbn')).toBeTruthy();
  1101. });
  1102. it('isbn13 invalid check digit', function() {
  1103. this.$isbn.val('978-0-306-40615-6');
  1104. this.bv.validate();
  1105. expect(this.bv.isValidField('isbn')).toEqual(false);
  1106. });
  1107. });
  1108. describe('isin', function() {
  1109. beforeEach(function() {
  1110. var html = [
  1111. '<div class="container">',
  1112. '<form class="form-horizontal" id="isinForm">',
  1113. '<div class="form-group">',
  1114. '<input type="text" name="isin" data-bv-isin />',
  1115. '</div>',
  1116. '</form>',
  1117. '</div>'
  1118. ].join('\n');
  1119. $(html).appendTo('body');
  1120. $('#isinForm').bootstrapValidator();
  1121. this.bv = $('#isinForm').data('bootstrapValidator');
  1122. this.$isin = this.bv.getFieldElements('isin');
  1123. });
  1124. afterEach(function() {
  1125. $('#isinForm').bootstrapValidator('destroy').parent().remove();
  1126. });
  1127. it('valid', function() {
  1128. var samples = ['US0378331005', 'AU0000XVGZA3', 'GB0002634946'];
  1129. for (var i in samples) {
  1130. this.$isin.val(samples[i]);
  1131. this.bv.validate();
  1132. expect(this.bv.isValidField('isin')).toBeTruthy();
  1133. }
  1134. });
  1135. it('invalid country code', function() {
  1136. this.$isin.val('AA0000XVGZA3');
  1137. this.bv.validate();
  1138. expect(this.bv.isValidField('isin')).toEqual(false);
  1139. });
  1140. it('contains only digits and alphabet', function() {
  1141. this.$isin.val('US12345ABC@#$');
  1142. this.bv.validate();
  1143. expect(this.bv.isValidField('isin')).toEqual(false);
  1144. });
  1145. it('invalid length', function() {
  1146. this.$isin.val('US1234567');
  1147. this.bv.validate();
  1148. expect(this.bv.isValidField('isin')).toEqual(false);
  1149. });
  1150. it('invalid check digit', function() {
  1151. this.$isin.val('US0378331004');
  1152. this.bv.validate();
  1153. expect(this.bv.isValidField('isin')).toEqual(false);
  1154. });
  1155. });
  1156. describe('ismn', function() {
  1157. beforeEach(function() {
  1158. var html = [
  1159. '<div class="container">',
  1160. '<form class="form-horizontal" id="ismnForm">',
  1161. '<div class="form-group">',
  1162. '<input type="text" name="ismn" data-bv-ismn />',
  1163. '</div>',
  1164. '</form>',
  1165. '</div>'
  1166. ].join('\n');
  1167. $(html).appendTo('body');
  1168. $('#ismnForm').bootstrapValidator();
  1169. this.bv = $('#ismnForm').data('bootstrapValidator');
  1170. this.$ismn = this.bv.getFieldElements('ismn');
  1171. });
  1172. afterEach(function() {
  1173. $('#ismnForm').bootstrapValidator('destroy').parent().remove();
  1174. });
  1175. it('valid start with M', function() {
  1176. this.$ismn.val('M230671187');
  1177. this.bv.validate();
  1178. expect(this.bv.isValidField('ismn')).toBeTruthy();
  1179. });
  1180. it('valid start with 979', function() {
  1181. this.$ismn.val('9790060115615');
  1182. this.bv.validate();
  1183. expect(this.bv.isValidField('ismn')).toBeTruthy();
  1184. });
  1185. it('valid contains spaces', function() {
  1186. this.$ismn.val('979 0 3452 4680 5');
  1187. this.bv.validate();
  1188. expect(this.bv.isValidField('ismn')).toBeTruthy();
  1189. });
  1190. it('valid contains dashes', function() {
  1191. this.$ismn.val('979-0-0601-1561-5');
  1192. this.bv.validate();
  1193. expect(this.bv.isValidField('ismn')).toBeTruthy();
  1194. });
  1195. it('invalid format', function() {
  1196. this.$ismn.val('N123456789');
  1197. this.bv.validate();
  1198. expect(this.bv.isValidField('ismn')).toEqual(false);
  1199. });
  1200. it('invalid check digit', function() {
  1201. this.$ismn.val('9790060115614');
  1202. this.bv.validate();
  1203. expect(this.bv.isValidField('ismn')).toEqual(false);
  1204. });
  1205. });
  1206. describe('issn', function() {
  1207. beforeEach(function() {
  1208. var html = [
  1209. '<div class="container">',
  1210. '<form class="form-horizontal" id="issnForm">',
  1211. '<div class="form-group">',
  1212. '<input type="text" name="issn" data-bv-issn />',
  1213. '</div>',
  1214. '</form>',
  1215. '</div>'
  1216. ].join('\n');
  1217. $(html).appendTo('body');
  1218. $('#issnForm').bootstrapValidator();
  1219. this.bv = $('#issnForm').data('bootstrapValidator');
  1220. this.$issn = this.bv.getFieldElements('issn');
  1221. });
  1222. afterEach(function() {
  1223. $('#issnForm').bootstrapValidator('destroy').parent().remove();
  1224. });
  1225. it('valid', function() {
  1226. var samples = ['0378-5955', '0024-9319', '0032-1478'];
  1227. for (var i in samples) {
  1228. this.$issn.val(samples[i]);
  1229. this.bv.validate();
  1230. expect(this.bv.isValidField('issn')).toBeTruthy();
  1231. }
  1232. });
  1233. it('not contains hyphen', function() {
  1234. this.$issn.val('03785955');
  1235. this.bv.validate();
  1236. expect(this.bv.isValidField('issn')).toEqual(false);
  1237. });
  1238. it('contains only digits, X', function() {
  1239. this.$issn.val('1234-566A');
  1240. this.bv.validate();
  1241. expect(this.bv.isValidField('issn')).toEqual(false);
  1242. });
  1243. it('invalid check sum', function() {
  1244. this.$issn.val('0032-147X');
  1245. this.bv.validate();
  1246. expect(this.bv.isValidField('issn')).toEqual(false);
  1247. });
  1248. });