spec.js 299 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433
  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. '<form class="form-horizontal" id="apiForm">',
  13. '<div class="form-group">',
  14. '<input type="text" name="username" data-bv-notempty data-bv-stringlength data-bv-stringlength-min="8" />',
  15. '</div>',
  16. '<div class="form-group">',
  17. '<input type="text" name="email" data-bv-notempty data-bv-emailaddress />',
  18. '</div>',
  19. '</form>'
  20. ].join('\n')).appendTo('body');
  21. $('#apiForm').bootstrapValidator();
  22. this.bv = $('#apiForm').data('bootstrapValidator');
  23. this.$email = this.bv.getFieldElements('email');
  24. });
  25. afterEach(function() {
  26. $('#apiForm').bootstrapValidator('destroy').remove();
  27. });
  28. it('revalidateField()', function() {
  29. this.$email.val('email@domain.com');
  30. this.bv.validate();
  31. expect(this.bv.isValidField('email')).toBeTruthy();
  32. this.$email.val('invalid#email.address');
  33. this.bv.revalidateField('email');
  34. expect(this.bv.isValidField(this.$email)).toEqual(false);
  35. });
  36. it('destroy()', function() {
  37. this.bv.destroy();
  38. expect($('#apiForm').data('bootstrapValidator')).toBeUndefined();
  39. expect($('#apiForm').find('i[data-bv-icon-for]').length).toEqual(0);
  40. expect($('#apiForm').find('.help-block[data-bv-for]').length).toEqual(0);
  41. expect($('#apiForm').find('.has-feedback').length).toEqual(0);
  42. expect($('#apiForm').find('.has-success').length).toEqual(0);
  43. expect($('#apiForm').find('.has-error').length).toEqual(0);
  44. expect($('#apiForm').find('[data-bv-field]').length).toEqual(0);
  45. });
  46. it('getOptions()', function() {
  47. // Form options
  48. expect(this.bv.getOptions().feedbackIcons.valid).toEqual('glyphicon glyphicon-ok');
  49. // Field options
  50. expect(this.bv.getOptions('username', 'stringlength')).toBeNull();
  51. expect(this.bv.getOptions('username', 'stringlength', 'min')).toBeNull();
  52. expect(this.bv.getOptions('username', 'stringLength')).toBeDefined();
  53. expect(this.bv.getOptions('username', 'stringLength', 'min')).toEqual('8');
  54. expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
  55. });
  56. });
  57. describe('container form option', function() {
  58. beforeEach(function() {
  59. $([
  60. '<form id="containerForm" class="form-horizontal">',
  61. '<div class="form-group">',
  62. '<label class="col-lg-3 control-label">Full name</label>',
  63. '<div class="col-lg-4">',
  64. '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" />',
  65. '</div>',
  66. '<div class="col-lg-4">',
  67. '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
  68. '</div>',
  69. '</div>',
  70. '<div id="errors"></div>',
  71. '</form>'
  72. ].join('')).appendTo('body');
  73. });
  74. afterEach(function() {
  75. $('#containerForm').bootstrapValidator('destroy').remove();
  76. });
  77. it('form container declarative', function() {
  78. $('#containerForm')
  79. .attr('data-bv-container', '#errors')
  80. .bootstrapValidator();
  81. this.bv = $('#containerForm').data('bootstrapValidator');
  82. this.$firstName = this.bv.getFieldElements('firstName');
  83. this.$lastName = this.bv.getFieldElements('lastName');
  84. expect($('#errors').find('.help-block').length).toBeGreaterThan(0);
  85. this.$firstName.val('First');
  86. this.$lastName.val('');
  87. this.bv.validate();
  88. expect($('#errors').find('.help-block:visible[data-bv-for="firstName"]').length).toEqual(0);
  89. expect($('#errors').find('.help-block:visible[data-bv-for="lastName"]').length).toBeGreaterThan(0);
  90. });
  91. it('form container programmatically', function() {
  92. $('#containerForm').bootstrapValidator({
  93. container: '#errors'
  94. });
  95. this.bv = $('#containerForm').data('bootstrapValidator');
  96. this.$firstName = this.bv.getFieldElements('firstName');
  97. this.$lastName = this.bv.getFieldElements('lastName');
  98. expect($('#errors').find('.help-block').length).toBeGreaterThan(0);
  99. this.$firstName.val('');
  100. this.$lastName.val('Last');
  101. this.bv.validate();
  102. expect($('#errors').find('.help-block:visible[data-bv-for="firstName"]').length).toBeGreaterThan(0);
  103. expect($('#errors').find('.help-block:visible[data-bv-for="lastName"]').length).toEqual(0);
  104. this.bv.resetForm();
  105. this.$firstName.val('First');
  106. this.$lastName.val('Last');
  107. this.bv.validate();
  108. expect($('#errors').find('.help-block:visible').length).toEqual(0);
  109. });
  110. });
  111. describe('container field option', function() {
  112. beforeEach(function() {
  113. $([
  114. '<form id="containerForm" class="form-horizontal">',
  115. '<div class="form-group">',
  116. '<label class="col-lg-3 control-label">Full name</label>',
  117. '<div class="col-lg-4">',
  118. '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" data-bv-container="#firstNameMessage" />',
  119. '<span class="help-block" id="firstNameMessage" />',
  120. '</div>',
  121. '<div class="col-lg-4">',
  122. '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
  123. '<span class="help-block lastNameMessage" />',
  124. '</div>',
  125. '</div>',
  126. '</form>'
  127. ].join('')).appendTo('body');
  128. $('#containerForm').bootstrapValidator({
  129. feedbackIcons: {
  130. valid: 'glyphicon glyphicon-ok',
  131. invalid: 'glyphicon glyphicon-remove',
  132. validating: 'glyphicon glyphicon-refresh'
  133. },
  134. fields: {
  135. lastName: {
  136. container: '.lastNameMessage'
  137. }
  138. }
  139. });
  140. this.bv = $('#containerForm').data('bootstrapValidator');
  141. this.$firstName = this.bv.getFieldElements('firstName');
  142. this.$lastName = this.bv.getFieldElements('lastName');
  143. });
  144. afterEach(function() {
  145. $('#containerForm').bootstrapValidator('destroy').remove();
  146. });
  147. it('field container declarative', function() {
  148. expect($.trim($('#firstNameMessage').text())).toEqual('The first name is required');
  149. expect($.trim($('.lastNameMessage').text())).toEqual('The last name is required');
  150. });
  151. it('field container programmatically', function() {
  152. this.$firstName.val('First');
  153. this.$lastName.val('');
  154. this.bv.validate();
  155. expect($('#firstNameMessage').find('.help-block:visible').length).toEqual(0);
  156. expect($('.lastNameMessage').find('.help-block:visible').length).toBeGreaterThan(0);
  157. this.bv.resetForm();
  158. this.$firstName.val('');
  159. this.$lastName.val('Last');
  160. this.bv.validate();
  161. expect($('#firstNameMessage').find('.help-block:visible').length).toBeGreaterThan(0);
  162. expect($('.lastNameMessage').find('.help-block:visible').length).toEqual(0);
  163. });
  164. });
  165. describe('container tooltip/popover', function() {
  166. beforeEach(function() {
  167. $([
  168. '<form id="containerForm" class="form-horizontal">',
  169. '<div class="form-group">',
  170. '<label class="col-lg-3 control-label">Full name</label>',
  171. '<div class="col-lg-4">',
  172. '<input type="text" class="form-control" name="firstName" required placeholder="First name" data-bv-notempty-message="The first name is required" />',
  173. '</div>',
  174. '<div class="col-lg-4">',
  175. '<input type="text" class="form-control" name="lastName" required placeholder="Last name" data-bv-notempty-message="The last name is required" />',
  176. '</div>',
  177. '</div>',
  178. '<div id="errors"></div>',
  179. '</form>'
  180. ].join('')).appendTo('body');
  181. });
  182. afterEach(function() {
  183. $('#containerForm').bootstrapValidator('destroy').remove();
  184. });
  185. it('container declarative', function() {
  186. $('#containerForm')
  187. .attr('data-bv-container', 'tooltip')
  188. .find('[name="lastName"]')
  189. .attr('data-bv-container', 'popover')
  190. .end()
  191. .bootstrapValidator();
  192. this.bv = $('#containerForm').data('bootstrapValidator');
  193. this.$firstName = this.bv.getFieldElements('firstName');
  194. this.$lastName = this.bv.getFieldElements('lastName');
  195. this.bv.validate();
  196. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  197. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  198. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
  199. expect(this.$lastName.parent().find('i').data('bs.popover').type).toEqual('popover');
  200. this.bv.resetForm();
  201. this.$firstName.val('First');
  202. this.$lastName.val('Last');
  203. this.bv.validate();
  204. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  205. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
  206. });
  207. it('container programmatically', function() {
  208. $('#containerForm').bootstrapValidator({
  209. container: 'tooltip',
  210. fields: {
  211. lastName: {
  212. container: 'popover'
  213. }
  214. }
  215. });
  216. this.bv = $('#containerForm').data('bootstrapValidator');
  217. this.$firstName = this.bv.getFieldElements('firstName');
  218. this.$lastName = this.bv.getFieldElements('lastName');
  219. this.bv.validate();
  220. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  221. expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
  222. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
  223. expect(this.$lastName.parent().find('i').data('bs.popover').type).toEqual('popover');
  224. this.bv.resetForm();
  225. this.$firstName.val('First');
  226. this.$lastName.val('Last');
  227. this.bv.validate();
  228. expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
  229. expect(this.$lastName.parent().find('i').data('bs.popover')).toBeDefined();
  230. });
  231. });
  232. describe('dynamic fields', function() {
  233. beforeEach(function() {
  234. $([
  235. '<form class="form-horizontal" id="dynamicForm">',
  236. '<div class="form-group">',
  237. '<input type="text" name="fullName" class="form-control" />',
  238. '</div>',
  239. '</form>'
  240. ].join('\n')).appendTo('body');
  241. $('#dynamicForm').bootstrapValidator({
  242. fields: {
  243. fullName: {
  244. validators: {
  245. notEmpty: {
  246. message: 'The full name is required and cannot be empty'
  247. },
  248. stringLength: {
  249. min: 8,
  250. max: 40,
  251. message: 'The full name must be more than %s and less than %s characters long'
  252. },
  253. regexp: {
  254. enabled: false,
  255. regexp: /^[a-zA-Z\s]+$/,
  256. message: 'The full name can only consist of alphabetical, number, and space'
  257. }
  258. }
  259. },
  260. // #725: Note that the email field isn't available in the form yet
  261. email: {
  262. validators: {
  263. emailAddress: {
  264. message: 'The email address is not valid'
  265. }
  266. }
  267. }
  268. }
  269. });
  270. this.bv = $('#dynamicForm').data('bootstrapValidator');
  271. this.$fullName = this.bv.getFieldElements('fullName');
  272. });
  273. afterEach(function() {
  274. $('#dynamicForm').bootstrapValidator('destroy').remove();
  275. });
  276. // https://github.com/nghuuphuoc/bootstrapvalidator/pull/725
  277. it('adding field [does not exist but is already set in "fields" option]', function() {
  278. var $div = $('<div/>').addClass('form-group').appendTo($('#dynamicForm'));
  279. $email = $('<input/>')
  280. .attr('type', 'text')
  281. .addClass('form-control')
  282. .attr('name', 'email')
  283. .appendTo($div);
  284. this.bv.addField('email');
  285. this.$fullName.val('Phuoc Nguyen');
  286. $email.val('not valid@email');
  287. this.bv.validate();
  288. expect(this.bv.isValidField('email')).toBeFalsy();
  289. expect(this.bv.isValid()).toBeFalsy();
  290. this.bv.resetForm();
  291. $email.val('valid@email.com');
  292. this.bv.validate();
  293. expect(this.bv.isValidField('email')).toBeTruthy();
  294. expect(this.bv.isValid()).toBeTruthy();
  295. });
  296. });
  297. describe('enable validators', function() {
  298. beforeEach(function() {
  299. $([
  300. '<form class="form-horizontal" id="enableForm">',
  301. '<div class="form-group">',
  302. '<input type="text" name="fullName" class="form-control" />',
  303. '</div>',
  304. '</form>'
  305. ].join('\n')).appendTo('body');
  306. $('#enableForm').bootstrapValidator({
  307. fields: {
  308. fullName: {
  309. validators: {
  310. notEmpty: {
  311. message: 'The full name is required and cannot be empty'
  312. },
  313. stringLength: {
  314. min: 8,
  315. max: 40,
  316. message: 'The full name must be more than %s and less than %s characters long'
  317. },
  318. regexp: {
  319. enabled: false,
  320. regexp: /^[a-zA-Z\s]+$/,
  321. message: 'The full name can only consist of alphabetical, number, and space'
  322. }
  323. }
  324. }
  325. }
  326. });
  327. this.bv = $('#enableForm').data('bootstrapValidator');
  328. this.$fullName = this.bv.getFieldElements('fullName');
  329. });
  330. afterEach(function() {
  331. $('#enableForm').bootstrapValidator('destroy').remove();
  332. });
  333. it('enable all validators', function() {
  334. this.$fullName.val('@ $full N@m3');
  335. this.bv.validate();
  336. expect(this.bv.isValid()).toBeTruthy();
  337. this.bv.resetForm();
  338. this.$fullName.val('Contain#$@');
  339. this.bv.enableFieldValidators('fullName', true);
  340. this.bv.validate();
  341. expect(this.bv.isValidField('fullName')).toEqual(false);
  342. expect(this.bv.isValid()).toEqual(false);
  343. });
  344. it('disable all validators', function() {
  345. this.bv.resetForm();
  346. this.bv.enableFieldValidators('fullName', false);
  347. this.bv.validate();
  348. expect(this.bv.isValid()).toBeTruthy();
  349. });
  350. it('enabled option particular validator', function() {
  351. this.$fullName.val('Contain@#$');
  352. this.bv.validate();
  353. expect(this.bv.isValid()).toBeTruthy();
  354. var messages = this.bv.getMessages('fullName');
  355. expect(messages.length).toEqual(0);
  356. });
  357. it('enable particular validators', function() {
  358. // Enable stringLength validator
  359. this.bv.resetForm();
  360. this.bv.enableFieldValidators('fullName', true, 'stringLength');
  361. this.bv.enableFieldValidators('fullName', true, 'regexp');
  362. this.$fullName.val('Full@');
  363. this.bv.validate();
  364. expect(this.bv.isValid()).toEqual(false);
  365. var messages = this.bv.getMessages('fullName');
  366. expect($.inArray('The full name must be more than 8 and less than 40 characters long', messages)).toBeGreaterThan(-1);
  367. expect($.inArray('The full name can only consist of alphabetical, number, and space', messages)).toBeGreaterThan(-1);
  368. });
  369. it('disable particular validators', function() {
  370. // Disable stringLength validator
  371. this.bv.enableFieldValidators('fullName', false, 'stringLength');
  372. this.$fullName.val('Full');
  373. this.bv.validate();
  374. expect(this.bv.isValid()).toBeTruthy();
  375. var messages = this.bv.getMessages('fullName');
  376. expect($.inArray('The full name must be more than 8 and less than 40 characters long', messages)).toEqual(-1);
  377. // Disable regexp validator
  378. this.bv.enableFieldValidators('fullName', false, 'regexp');
  379. this.$fullName.val('Special@#$');
  380. this.bv.validate();
  381. expect(this.bv.isValid()).toBeTruthy();
  382. var messages = this.bv.getMessages('fullName');
  383. expect($.inArray('The full name can only consist of alphabetical, number, and space', messages)).toEqual(-1);
  384. });
  385. });
  386. TestSuite = $.extend({}, TestSuite, {
  387. Event: {
  388. onEmailValid: function(e, data) {
  389. $('#msg').html('TestSuite.Event.onEmailValid() called, ' + data.field + ' is valid');
  390. },
  391. onEmailInvalid: function(e, data) {
  392. $('#msg').html('TestSuite.Event.onEmailInvalid() called, ' + data.field + ' is invalid');
  393. },
  394. onEmailStatus: function(e, data) {
  395. $('#status').html('TestSuite.Event.onEmailStatus() called; status = ' + data.status);
  396. },
  397. onFormValid: function(e) {
  398. $('#msg').html('TestSuite.Event.onFormValid() called, form ' + $(e.target).attr('id') + ' is valid');
  399. },
  400. onFormInvalid: function(e) {
  401. $('#msg').html('TestSuite.Event.onFormInvalid() called, form ' + $(e.target).attr('id') + ' is invalid');
  402. }
  403. }
  404. });
  405. // ---
  406. // Form events
  407. // ---
  408. function onFormValid(e) {
  409. $('#msg').html('form ' + $(e.target).attr('id') + ' is valid');
  410. };
  411. function onFormInvalid(e) {
  412. $('#msg').html('form ' + $(e.target).attr('id') + ' is invalid');
  413. };
  414. describe('event form attribute callback global', function() {
  415. beforeEach(function() {
  416. $([
  417. '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="onFormValid" data-bv-onerror="onFormInvalid" >',
  418. '<div id="msg"></div>',
  419. '<div class="form-group">',
  420. '<input type="text" name="email" required data-bv-emailaddress />',
  421. '</div>',
  422. '</form>'
  423. ].join('\n')).appendTo('body');
  424. $('#eventForm').bootstrapValidator();
  425. this.bv = $('#eventForm').data('bootstrapValidator');
  426. this.$email = this.bv.getFieldElements('email');
  427. });
  428. afterEach(function() {
  429. $('#eventForm').bootstrapValidator('destroy').remove();
  430. });
  431. it('call data-bv-onsuccess', function() {
  432. this.$email.val('email@domain.com');
  433. this.bv.validate();
  434. expect($('#msg').html()).toEqual('form eventForm is valid');
  435. });
  436. it('call data-bv-onerror', function() {
  437. this.$email.val('a@b@c@example.com');
  438. this.bv.validate();
  439. expect($('#msg').html()).toEqual('form eventForm is invalid');
  440. });
  441. });
  442. describe('event form attribute callback namespace', function() {
  443. beforeEach(function() {
  444. $([
  445. '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="TestSuite.Event.onFormValid" data-bv-onerror="TestSuite.Event.onFormInvalid" >',
  446. '<div id="msg"></div>',
  447. '<div class="form-group">',
  448. '<input type="text" name="email" required data-bv-emailaddress />',
  449. '</div>',
  450. '</form>'
  451. ].join('\n')).appendTo('body');
  452. $('#eventForm').bootstrapValidator();
  453. this.bv = $('#eventForm').data('bootstrapValidator');
  454. this.$email = this.bv.getFieldElements('email');
  455. });
  456. afterEach(function() {
  457. $('#eventForm').bootstrapValidator('destroy').remove();
  458. });
  459. it('call data-bv-onsuccess', function() {
  460. this.$email.val('email@domain.com');
  461. this.bv.validate();
  462. expect($('#msg').html()).toEqual('TestSuite.Event.onFormValid() called, form eventForm is valid');
  463. });
  464. it('call data-bv-onerror', function() {
  465. this.$email.val('just"not"right@example.com');
  466. this.bv.validate();
  467. expect($('#msg').html()).toEqual('TestSuite.Event.onFormInvalid() called, form eventForm is invalid');
  468. });
  469. });
  470. describe('event form trigger', function() {
  471. beforeEach(function() {
  472. $([
  473. '<form class="form-horizontal" id="eventForm">',
  474. '<div id="msg"></div>',
  475. '<div class="form-group">',
  476. '<input type="text" name="email" data-bv-emailaddress />',
  477. '</div>',
  478. '</form>'
  479. ].join('\n')).appendTo('body');
  480. $('#eventForm')
  481. .bootstrapValidator()
  482. .on('success.form.bv', function(e) {
  483. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
  484. })
  485. .on('error.form.bv', function(e) {
  486. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
  487. });
  488. this.bv = $('#eventForm').data('bootstrapValidator');
  489. this.$email = this.bv.getFieldElements('email');
  490. });
  491. afterEach(function() {
  492. $('#eventForm').bootstrapValidator('destroy').remove();
  493. });
  494. it('trigger success.form.bv', function() {
  495. this.$email.val('email@domain.com');
  496. this.bv.validate();
  497. expect($('#msg').html()).toEqual('form eventForm triggered success.form.bv event');
  498. });
  499. it('trigger error.form.bv', function() {
  500. this.$email.val('this is"not\\allowed@example.com');
  501. this.bv.validate();
  502. expect($('#msg').html()).toEqual('form eventForm triggered error.form.bv event');
  503. });
  504. });
  505. describe('event form programmatically', function() {
  506. beforeEach(function() {
  507. $([
  508. '<form class="form-horizontal" id="eventForm">',
  509. '<div id="msg"></div>',
  510. '<div class="form-group">',
  511. '<input type="text" name="email" data-bv-emailaddress />',
  512. '</div>',
  513. '</form>'
  514. ].join('\n')).appendTo('body');
  515. $('#eventForm').bootstrapValidator({
  516. onSuccess: function(e) {
  517. $('#msg').html('onSuccess() called');
  518. },
  519. onError: function(e) {
  520. $('#msg').html('onError() called');
  521. }
  522. });
  523. this.bv = $('#eventForm').data('bootstrapValidator');
  524. this.$email = this.bv.getFieldElements('email');
  525. });
  526. afterEach(function() {
  527. $('#eventForm').bootstrapValidator('destroy').remove();
  528. });
  529. it('call onSuccess()', function() {
  530. this.$email.val('email@domain.com');
  531. this.bv.validate();
  532. expect($('#msg').html()).toEqual('onSuccess() called');
  533. });
  534. it('call onError()', function() {
  535. this.$email.val('Abc.example.com');
  536. this.bv.validate();
  537. expect($('#msg').html()).toEqual('onError() called');
  538. });
  539. });
  540. // ---
  541. // Field events
  542. // ---
  543. function onEmailValid(e, data) {
  544. $('#msg').html(data.field + ' is valid');
  545. };
  546. function onEmailInvalid(e, data) {
  547. $('#msg').html(data.field + ' is invalid');
  548. };
  549. function onEmailStatus(e, data) {
  550. $('#status').html(data.status);
  551. };
  552. describe('event field attribute callback global', function() {
  553. beforeEach(function() {
  554. $([
  555. '<form class="form-horizontal" id="eventForm">',
  556. '<div id="msg"></div>',
  557. '<div id="status"></div>',
  558. '<div class="form-group">',
  559. '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" data-bv-onstatus="onEmailStatus" />',
  560. '</div>',
  561. '</form>'
  562. ].join('\n')).appendTo('body');
  563. $('#eventForm').bootstrapValidator();
  564. this.bv = $('#eventForm').data('bootstrapValidator');
  565. this.$email = this.bv.getFieldElements('email');
  566. });
  567. afterEach(function() {
  568. $('#eventForm').bootstrapValidator('destroy').remove();
  569. });
  570. it('call data-bv-onsuccess', function() {
  571. this.$email.val('email@domain.com');
  572. this.bv.validate();
  573. expect($('#msg').html()).toEqual('email is valid');
  574. expect($('#status').html()).toEqual(this.bv.STATUS_VALID);
  575. });
  576. it('call data-bv-onerror', function() {
  577. this.$email.val('A@b@c@example.com');
  578. this.bv.validate();
  579. expect($('#msg').html()).toEqual('email is invalid');
  580. expect($('#status').html()).toEqual(this.bv.STATUS_INVALID);
  581. });
  582. });
  583. describe('event field attribute callback namespace', function() {
  584. beforeEach(function() {
  585. $([
  586. '<form class="form-horizontal" id="eventForm">',
  587. '<div id="msg"></div>',
  588. '<div id="status"></div>',
  589. '<div class="form-group">',
  590. '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="TestSuite.Event.onEmailValid" data-bv-onerror="TestSuite.Event.onEmailInvalid" data-bv-onstatus="TestSuite.Event.onEmailStatus" />',
  591. '</div>',
  592. '</form>'
  593. ].join('\n')).appendTo('body');
  594. $('#eventForm').bootstrapValidator();
  595. this.bv = $('#eventForm').data('bootstrapValidator');
  596. this.$email = this.bv.getFieldElements('email');
  597. });
  598. afterEach(function() {
  599. $('#eventForm').bootstrapValidator('destroy').remove();
  600. });
  601. it('call data-bv-onsuccess', function() {
  602. this.$email.val('email@domain.com');
  603. this.bv.validate();
  604. expect($('#msg').html()).toEqual('TestSuite.Event.onEmailValid() called, email is valid');
  605. expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_VALID);
  606. });
  607. it('call data-bv-onerror', function() {
  608. this.$email.val('a"b(c)d,e:f;gi[j\\k]l@example.com');
  609. this.bv.validate();
  610. expect($('#msg').html()).toEqual('TestSuite.Event.onEmailInvalid() called, email is invalid');
  611. expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_INVALID);
  612. });
  613. });
  614. describe('event field trigger', function() {
  615. beforeEach(function() {
  616. $([
  617. '<form class="form-horizontal" id="eventForm">',
  618. '<div id="msg"></div>',
  619. '<div class="form-group">',
  620. '<input type="text" name="email" data-bv-emailaddress />',
  621. '</div>',
  622. '</form>'
  623. ].join('\n')).appendTo('body');
  624. $('#eventForm')
  625. .bootstrapValidator()
  626. .on('success.field.bv', '[name="email"]', function(e, data) {
  627. $('#msg').html('triggered success.field.bv on ' + data.field);
  628. })
  629. .on('error.field.bv', '[name="email"]', function(e, data) {
  630. $('#msg').html('triggered error.field.bv on ' + data.field);
  631. });
  632. this.bv = $('#eventForm').data('bootstrapValidator');
  633. this.$email = this.bv.getFieldElements('email');
  634. });
  635. afterEach(function() {
  636. $('#eventForm').bootstrapValidator('destroy').remove();
  637. });
  638. it('trigger success.field.bv', function() {
  639. this.$email.val('email@domain.com');
  640. this.bv.validate();
  641. expect($('#msg').html()).toEqual('triggered success.field.bv on email');
  642. });
  643. it('trigger error.field.bv', function() {
  644. this.$email.val('just"not"right@example.com');
  645. this.bv.validate();
  646. expect($('#msg').html()).toEqual('triggered error.field.bv on email');
  647. });
  648. });
  649. describe('event field programmatically', function() {
  650. beforeEach(function() {
  651. $([
  652. '<form class="form-horizontal" id="eventForm">',
  653. '<div id="msg"></div>',
  654. '<div class="form-group">',
  655. '<input type="text" name="email" data-bv-emailaddress />',
  656. '</div>',
  657. '</form>'
  658. ].join('\n')).appendTo('body');
  659. $('#eventForm').bootstrapValidator({
  660. fields: {
  661. email: {
  662. onSuccess: function(e, data) {
  663. $('#msg').html('onSuccess() called');
  664. },
  665. onError: function(e, data) {
  666. $('#msg').html('onError() called');
  667. }
  668. }
  669. }
  670. });
  671. this.bv = $('#eventForm').data('bootstrapValidator');
  672. this.$email = this.bv.getFieldElements('email');
  673. });
  674. afterEach(function() {
  675. $('#eventForm').bootstrapValidator('destroy').remove();
  676. });
  677. it('call onSuccess()', function() {
  678. this.$email.val('email@domain.com');
  679. this.bv.validate();
  680. expect($('#msg').html()).toEqual('onSuccess() called');
  681. });
  682. it('call onError()', function() {
  683. this.$email.val('this is"not\\allowed@example.com');
  684. this.bv.validate();
  685. expect($('#msg').html()).toEqual('onError() called');
  686. });
  687. });
  688. // ---
  689. // Modifying default events
  690. // ---
  691. describe('event form trigger with default events', function() {
  692. beforeEach(function() {
  693. $([
  694. '<form class="form-horizontal" id="eventForm1">',
  695. '<div id="msg"></div>',
  696. '<div class="form-group">',
  697. '<input type="text" name="email" data-bv-emailaddress />',
  698. '</div>',
  699. '</form>'
  700. ].join('\n')).appendTo('body');
  701. $('#eventForm1')
  702. .bootstrapValidator()
  703. .on('bv.form.success', function(e) {
  704. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
  705. })
  706. .on('success.form.bv', function(e) {
  707. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
  708. })
  709. .on('bv.form.error', function(e) {
  710. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
  711. })
  712. .on('error.form.bv', function(e) {
  713. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
  714. });
  715. this.bv = $('#eventForm1').data('bootstrapValidator');
  716. this.$email = this.bv.getFieldElements('email');
  717. });
  718. afterEach(function() {
  719. $('#eventForm1').bootstrapValidator('destroy').remove();
  720. });
  721. it('does not trigger bv.form.success', function() {
  722. this.$email.val('email@domain.com');
  723. this.bv.validate();
  724. expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.success event');
  725. });
  726. it('triggers success.form.bv', function() {
  727. this.$email.val('email@domain.com');
  728. this.bv.validate();
  729. expect($('#msg').html()).toEqual('form eventForm1 triggered success.form.bv event');
  730. });
  731. it('does not trigger bv.form.error', function() {
  732. this.$email.val('A@b@c@example.com');
  733. this.bv.validate();
  734. expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.error event');
  735. });
  736. it('triggers error.form.bv', function() {
  737. this.$email.val('A@b@c@example.com');
  738. this.bv.validate();
  739. expect($('#msg').html()).toEqual('form eventForm1 triggered error.form.bv event');
  740. });
  741. });
  742. describe('event field trigger with default events', function() {
  743. beforeEach(function() {
  744. $([
  745. '<form class="form-horizontal" id="eventForm3">',
  746. '<div id="msg"></div>',
  747. '<div class="form-group">',
  748. '<input type="text" name="email" data-bv-emailaddress />',
  749. '</div>',
  750. '</form>'
  751. ].join('\n')).appendTo('body');
  752. $('#eventForm3')
  753. .bootstrapValidator()
  754. .on('success.field.bv', '[name="email"]', function(e, data) {
  755. $('#msg').html('triggered success.field.bv on ' + data.field);
  756. })
  757. .on('error.field.bv', '[name="email"]', function(e, data) {
  758. $('#msg').html('triggered error.field.bv on ' + data.field);
  759. })
  760. .on('bv.field.success', '[name="email"]', function(e, data) {
  761. $('#msg').html('triggered bv.field.success on ' + data.field);
  762. })
  763. .on('bv.field.error', '[name="email"]', function(e, data) {
  764. $('#msg').html('triggered bv.field.error on ' + data.field);
  765. });
  766. this.bv = $('#eventForm3').data('bootstrapValidator');
  767. this.$email = this.bv.getFieldElements('email');
  768. });
  769. afterEach(function() {
  770. $('#eventForm3').bootstrapValidator('destroy').remove();
  771. });
  772. it('triggers success.field.bv', function() {
  773. this.$email.val('email@domain.com');
  774. this.bv.validate();
  775. expect($('#msg').html()).toEqual('triggered success.field.bv on email');
  776. });
  777. it('does not trigger bv.field.success', function() {
  778. this.$email.val('email@domain.com');
  779. this.bv.validate();
  780. expect($('#msg').html()).not.toEqual('triggered bv.field.success on email');
  781. });
  782. it('does not trigger error.field.bv', function() {
  783. this.$email.val('just"not"right@example.com');
  784. this.bv.validate();
  785. expect($('#msg').html()).toEqual('triggered error.field.bv on email');
  786. });
  787. it('triggers bv.field.error', function() {
  788. this.$email.val('just"not"right@example.com');
  789. this.bv.validate();
  790. expect($('#msg').html()).not.toEqual('triggered bv.field.error on email');
  791. });
  792. });
  793. describe('event form trigger with events changed', function() {
  794. beforeEach(function() {
  795. $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  796. events: {
  797. formInit: 'init.form.bv',
  798. formError: 'bv.form.error',
  799. formSuccess: 'bv.form.success',
  800. fieldAdded: 'added.field.bv',
  801. fieldRemoved: 'removed.field.bv',
  802. fieldInit: 'init.field.bv',
  803. fieldError: 'bv.field.error',
  804. fieldSuccess: 'bv.field.success',
  805. fieldStatus: 'status.field.bv',
  806. validatorError: 'bv.validator.error',
  807. validatorSuccess: 'success.validator.bv'
  808. }
  809. });
  810. $([
  811. '<form class="form-horizontal" id="eventForm2">',
  812. '<div id="msg"></div>',
  813. '<div class="form-group">',
  814. '<input type="text" name="email" data-bv-emailaddress />',
  815. '</div>',
  816. '</form>'
  817. ].join('\n')).appendTo('body');
  818. $('#eventForm2')
  819. .bootstrapValidator()
  820. .on('bv.form.success', function(e) {
  821. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
  822. })
  823. .on('success.form.bv', function(e) {
  824. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
  825. })
  826. .on('bv.form.error', function(e) {
  827. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
  828. })
  829. .on('error.form.bv', function(e) {
  830. $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
  831. });
  832. this.bv = $('#eventForm2').data('bootstrapValidator');
  833. this.$email = this.bv.getFieldElements('email');
  834. });
  835. afterEach(function() {
  836. $('#eventForm2').bootstrapValidator('destroy').remove();
  837. });
  838. it('triggers bv.form.success', function() {
  839. this.$email.val('email@domain.com');
  840. this.bv.validate();
  841. expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.success event');
  842. });
  843. it('does not trigger success.form.bv', function() {
  844. this.$email.val('email@domain.com');
  845. this.bv.validate();
  846. expect($('#msg').html()).not.toEqual('form eventForm2 triggered success.form.bv event');
  847. });
  848. it('triggers bv.form.error', function() {
  849. spyOn(window, 'onerror');
  850. this.$email.val('this is"not\\allowed@example.com');
  851. this.bv.validate();
  852. expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.error event');
  853. expect(window.onerror).not.toHaveBeenCalled();
  854. });
  855. });
  856. describe('event field trigger with events changed', function() {
  857. beforeEach(function () {
  858. $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  859. events: {
  860. formInit: 'init.form.bv',
  861. formError: 'bv.form.error',
  862. formSuccess: 'bv.form.success',
  863. fieldAdded: 'added.field.bv',
  864. fieldRemoved: 'removed.field.bv',
  865. fieldInit: 'init.field.bv',
  866. fieldError: 'bv.field.error',
  867. fieldSuccess: 'bv.field.success',
  868. fieldStatus: 'status.field.bv',
  869. validatorError: 'bv.validator.error',
  870. validatorSuccess: 'success.validator.bv'
  871. }
  872. });
  873. $([
  874. '<form class="form-horizontal" id="eventForm4">',
  875. '<div id="msg"></div>',
  876. '<div class="form-group">',
  877. '<input type="text" name="email" data-bv-emailaddress />',
  878. '</div>',
  879. '</form>'
  880. ].join('\n')).appendTo('body');
  881. $('#eventForm4')
  882. .bootstrapValidator()
  883. .on('success.field.bv', '[name="email"]', function(e, data) {
  884. $('#msg').html('triggered success.field.bv on ' + data.field);
  885. })
  886. .on('error.field.bv', '[name="email"]', function(e, data) {
  887. $('#msg').html('triggered error.field.bv on ' + data.field);
  888. })
  889. .on('bv.field.success', '[name="email"]', function(e, data) {
  890. $('#msg').html('triggered bv.field.success on ' + data.field);
  891. })
  892. .on('bv.field.error', '[name="email"]', function(e, data) {
  893. $('#msg').html('triggered bv.field.error on ' + data.field);
  894. });
  895. this.bv = $('#eventForm4').data('bootstrapValidator');
  896. this.$email = this.bv.getFieldElements('email');
  897. });
  898. afterEach(function() {
  899. $('#eventForm4').bootstrapValidator('destroy').remove();
  900. });
  901. it('triggers success.field.bv', function() {
  902. this.$email.val('email@domain.com');
  903. this.bv.validate();
  904. expect($('#msg').html()).not.toEqual('triggered success.field.bv on email');
  905. });
  906. it('does not trigger bv.field.success', function() {
  907. this.$email.val('email@domain.com');
  908. this.bv.validate();
  909. expect($('#msg').html()).toEqual('triggered bv.field.success on email');
  910. });
  911. it('does not trigger error.field.bv', function() {
  912. this.$email.val('Abc.example.com');
  913. this.bv.validate();
  914. expect($('#msg').html()).not.toEqual('triggered error.field.bv on email');
  915. });
  916. it('triggers bv.field.error', function() {
  917. spyOn(window, 'onerror');
  918. this.$email.val('Abc.example.com');
  919. this.bv.validate();
  920. expect($('#msg').html()).toEqual('triggered bv.field.error on email');
  921. expect(window.onerror).not.toHaveBeenCalled();
  922. });
  923. });
  924. // ---
  925. // Validator events
  926. // ---
  927. function onEmailAddressValidatorSuccess(e, data) {
  928. $('#msg').html(data.validator + ' validator passed');
  929. };
  930. function onEmailAddressValidatorError(e, data) {
  931. $('#msg').html(data.validator + ' validator did not pass');
  932. };
  933. describe('event validator declarative', function() {
  934. beforeEach(function() {
  935. $([
  936. '<form class="form-horizontal" id="eventForm">',
  937. '<div id="msg"></div>',
  938. '<div class="form-group">',
  939. '<input type="text" name="email" data-bv-emailaddress data-bv-emailaddress-onsuccess="onEmailAddressValidatorSuccess" data-bv-emailaddress-onerror="onEmailAddressValidatorError" />',
  940. '</div>',
  941. '</form>'
  942. ].join('\n')).appendTo('body');
  943. $('#eventForm').bootstrapValidator();
  944. this.bv = $('#eventForm').data('bootstrapValidator');
  945. this.$email = this.bv.getFieldElements('email');
  946. });
  947. afterEach(function() {
  948. $('#eventForm').bootstrapValidator('destroy').remove();
  949. });
  950. it('trigger data-bv-emailaddress-onsuccess', function() {
  951. this.$email.val('email@domain.com');
  952. this.bv.validate();
  953. expect($('#msg').html()).toEqual('emailAddress validator passed');
  954. });
  955. it('trigger data-bv-emailaddress-onerror', function() {
  956. this.$email.val('A@b@c@example.com');
  957. this.bv.validate();
  958. expect($('#msg').html()).toEqual('emailAddress validator did not pass');
  959. });
  960. });
  961. describe('event validator programmatically', function() {
  962. beforeEach(function() {
  963. $([
  964. '<form class="form-horizontal" id="eventForm">',
  965. '<div id="msg"></div>',
  966. '<div class="form-group">',
  967. '<input type="text" name="email" data-bv-emailaddress />',
  968. '</div>',
  969. '</form>'
  970. ].join('\n')).appendTo('body');
  971. $('#eventForm').bootstrapValidator({
  972. fields: {
  973. email: {
  974. validators: {
  975. emailAddress: {
  976. onSuccess: function(e, data) {
  977. $('#msg').html('emailAddress validator: onSuccess() called');
  978. },
  979. onError: function(e, data) {
  980. $('#msg').html('emailAddress validator: onError() called');
  981. },
  982. message: 'The email address is not valid'
  983. }
  984. }
  985. }
  986. }
  987. });
  988. this.bv = $('#eventForm').data('bootstrapValidator');
  989. this.$email = this.bv.getFieldElements('email');
  990. });
  991. afterEach(function() {
  992. $('#eventForm').bootstrapValidator('destroy').remove();
  993. });
  994. it('call onSuccess()', function() {
  995. this.$email.val('email@domain.com');
  996. this.bv.validate();
  997. expect($('#msg').html()).toEqual('emailAddress validator: onSuccess() called');
  998. });
  999. it('call onError()', function() {
  1000. this.$email.val('A@b@c@example.com');
  1001. this.bv.validate();
  1002. expect($('#msg').html()).toEqual('emailAddress validator: onError() called');
  1003. });
  1004. });
  1005. describe('excluded', function() {
  1006. beforeEach(function() {
  1007. $([
  1008. '<div class="container">',
  1009. '<form class="form-horizontal" id="excludedForm" data-bv-excluded="[name=\'email\']">',
  1010. '<div class="form-group">',
  1011. '<input type="text" name="username" required />',
  1012. '</div>',
  1013. '<div class="form-group">',
  1014. '<input type="text" name="email" required data-bv-emailaddress />',
  1015. '</div>',
  1016. '</form>',
  1017. '</div>'
  1018. ].join('')).appendTo('body');
  1019. $('#excludedForm').bootstrapValidator();
  1020. this.bv = $('#excludedForm').data('bootstrapValidator');
  1021. this.$username = this.bv.getFieldElements('username');
  1022. this.$email = this.bv.getFieldElements('email');
  1023. });
  1024. afterEach(function() {
  1025. $('#excludedForm').bootstrapValidator('destroy').parent().remove();
  1026. });
  1027. it('excluded form declarative', function() {
  1028. this.bv.validate();
  1029. expect(this.bv.isValid()).toEqual(false);
  1030. this.bv.resetForm();
  1031. this.$username.val('your_user_name');
  1032. this.$email.val('');
  1033. this.bv.validate();
  1034. expect(this.bv.isValid()).toBeTruthy();
  1035. });
  1036. it('excluded form programmatically', function() {
  1037. this.bv.destroy();
  1038. $('#excludedForm').removeAttr('data-bv-excluded');
  1039. $('#excludedForm').bootstrapValidator({
  1040. excluded: '[name="username"]'
  1041. });
  1042. this.bv = $('#excludedForm').data('bootstrapValidator');
  1043. this.$username = this.bv.getFieldElements('username');
  1044. this.$email = this.bv.getFieldElements('email');
  1045. this.$username.val('');
  1046. this.$email.val('invalid#email.com');
  1047. this.bv.validate();
  1048. expect(this.bv.isValid()).toEqual(false);
  1049. this.bv.resetForm();
  1050. this.$email.val('valid@email.com');
  1051. this.bv.validate();
  1052. expect(this.bv.isValid()).toBeTruthy();
  1053. });
  1054. it('excluded field declarative', function() {
  1055. this.bv.destroy();
  1056. $('#excludedForm').removeAttr('data-bv-excluded');
  1057. $('#excludedForm').find('[name="username"]').attr('data-bv-excluded', 'true');
  1058. $('#excludedForm').find('[name="email"]').attr('data-bv-excluded', 'false');
  1059. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  1060. this.$username = this.bv.getFieldElements('username');
  1061. this.$email = this.bv.getFieldElements('email');
  1062. this.$username.val('');
  1063. this.$email.val('');
  1064. this.bv.validate();
  1065. expect(this.bv.isValid()).toEqual(false);
  1066. this.bv.resetForm();
  1067. this.$email.val('invalid#email.com');
  1068. this.bv.validate();
  1069. expect(this.bv.isValid()).toEqual(false);
  1070. this.bv.resetForm();
  1071. this.$email.val('valid@email.com');
  1072. this.bv.validate();
  1073. expect(this.bv.isValid()).toBeTruthy();
  1074. });
  1075. it('excluded field programmatically true/false', function() {
  1076. this.bv.destroy();
  1077. $('#excludedForm').removeAttr('data-bv-excluded');
  1078. $('#excludedForm').bootstrapValidator({
  1079. fields: {
  1080. username: {
  1081. excluded: true
  1082. },
  1083. email: {
  1084. excluded: false
  1085. }
  1086. }
  1087. });
  1088. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  1089. this.$username = this.bv.getFieldElements('username');
  1090. this.$email = this.bv.getFieldElements('email');
  1091. this.$username.val('');
  1092. this.$email.val('');
  1093. this.bv.validate();
  1094. expect(this.bv.isValid()).toEqual(false);
  1095. this.bv.resetForm();
  1096. this.$email.val('invalid#email.com');
  1097. this.bv.validate();
  1098. expect(this.bv.isValid()).toEqual(false);
  1099. this.bv.resetForm();
  1100. this.$email.val('valid@email.com');
  1101. this.bv.validate();
  1102. expect(this.bv.isValid()).toBeTruthy();
  1103. });
  1104. it('excluded field programmatically "true"/"false"', function() {
  1105. this.bv.destroy();
  1106. $('#excludedForm').removeAttr('data-bv-excluded');
  1107. $('#excludedForm').bootstrapValidator({
  1108. fields: {
  1109. username: {
  1110. excluded: 'false'
  1111. },
  1112. email: {
  1113. excluded: 'true'
  1114. }
  1115. }
  1116. });
  1117. this.bv = $('#excludedForm').bootstrapValidator().data('bootstrapValidator');
  1118. this.$username = this.bv.getFieldElements('username');
  1119. this.$email = this.bv.getFieldElements('email');
  1120. this.$username.val('');
  1121. this.$email.val('valid@email.com');
  1122. this.bv.validate();
  1123. expect(this.bv.isValid()).toEqual(false);
  1124. this.bv.resetForm();
  1125. this.$username.val('your_user_name');
  1126. this.$email.val('invalid#email.com');
  1127. this.bv.validate();
  1128. expect(this.bv.isValid()).toBeTruthy();
  1129. });
  1130. });
  1131. describe('group option', function() {
  1132. beforeEach(function() {
  1133. $([
  1134. '<form id="groupForm" method="post" class="form-horizontal">',
  1135. '<div class="form-group">',
  1136. '<div class="firstNameGroup">',
  1137. '<label class="col-sm-2 control-label">First name</label>',
  1138. '<div class="col-sm-4">',
  1139. '<input type="text" class="form-control" name="firstName" />',
  1140. '</div>',
  1141. '</div>',
  1142. '<div class="lastNameGroup">',
  1143. '<label class="col-sm-2 control-label">Last name</label>',
  1144. '<div class="col-sm-4">',
  1145. '<input type="text" class="form-control" name="lastName" data-bv-group=".lastNameGroup" />',
  1146. '</div>',
  1147. '</div>',
  1148. '</div>',
  1149. '<div class="form-group">',
  1150. '<label class="col-sm-2 control-label">Username</label>',
  1151. '<div class="col-sm-5">',
  1152. '<input type="text" class="form-control" name="username" />',
  1153. '</div>',
  1154. '</div>',
  1155. '</form>'
  1156. ].join('')).appendTo('body');
  1157. $('#groupForm').bootstrapValidator({
  1158. fields: {
  1159. firstName: {
  1160. group: '.firstNameGroup',
  1161. validators: {
  1162. notEmpty: {
  1163. message: 'The first name is required and cannot be empty'
  1164. }
  1165. }
  1166. },
  1167. lastName: {
  1168. validators: {
  1169. notEmpty: {
  1170. message: 'The last name is required and cannot be empty'
  1171. }
  1172. }
  1173. },
  1174. username: {
  1175. validators: {
  1176. notEmpty: {
  1177. message: 'The username is required and cannot be empty'
  1178. },
  1179. stringLength: {
  1180. min: 6,
  1181. max: 30,
  1182. message: 'The username must be more than 6 and less than 30 characters long'
  1183. },
  1184. regexp: {
  1185. regexp: /^[a-zA-Z0-9_\.]+$/,
  1186. message: 'The username can only consist of alphabetical, number, dot and underscore'
  1187. }
  1188. }
  1189. }
  1190. }
  1191. });
  1192. this.bv = $('#groupForm').data('bootstrapValidator');
  1193. this.$firstName = this.bv.getFieldElements('firstName');
  1194. this.$lastName = this.bv.getFieldElements('lastName');
  1195. this.$username = this.bv.getFieldElements('username');
  1196. });
  1197. afterEach(function() {
  1198. $('#groupForm').bootstrapValidator('destroy').remove();
  1199. });
  1200. it('group default', function() {
  1201. this.$username.val('123@#$');
  1202. this.bv.validate();
  1203. expect(this.$username.parents('.form-group').hasClass('has-error')).toBeTruthy();
  1204. expect(this.$username.parents('.form-group').hasClass('has-success')).toEqual(false);
  1205. this.bv.resetForm();
  1206. this.$username.val('validUser.Name');
  1207. this.bv.validate();
  1208. expect(this.$username.parents('.form-group').hasClass('has-success')).toBeTruthy();
  1209. expect(this.$username.parents('.form-group').hasClass('has-error')).toEqual(false);
  1210. });
  1211. it('group programmatically', function() {
  1212. this.$firstName.val('');
  1213. this.bv.validate();
  1214. expect(this.$firstName.parents('.firstNameGroup').hasClass('has-error')).toBeTruthy();
  1215. expect(this.$firstName.parents('.firstNameGroup').hasClass('has-success')).toEqual(false);
  1216. expect(this.$firstName.parents('.form-group').hasClass('has-error')).toEqual(false);
  1217. });
  1218. it('group declarative', function() {
  1219. this.$firstName.val('First');
  1220. this.$lastName.val('Last');
  1221. this.bv.validate();
  1222. expect(this.$lastName.parents('.lastNameGroup').hasClass('has-success')).toBeTruthy();
  1223. expect(this.$lastName.parents('.lastNameGroup').hasClass('has-error')).toEqual(false);
  1224. expect(this.$lastName.parents('.form-group').hasClass('has-success')).toEqual(false);
  1225. expect(this.$lastName.parents('.form-group').hasClass('has-error')).toEqual(false);
  1226. });
  1227. });
  1228. describe('i18n', function() {
  1229. beforeEach(function() {
  1230. $([
  1231. '<form id="i18nForm" class="form-horizontal">',
  1232. '<div class="form-group">',
  1233. '<label class="col-lg-3 control-label">Full name</label>',
  1234. '<div class="col-lg-5">',
  1235. '<input type="text" class="form-control" name="fullName" />',
  1236. '</div>',
  1237. '</div>',
  1238. '<div class="form-group">',
  1239. '<label class="col-lg-3 control-label">Username</label>',
  1240. '<div class="col-lg-5">',
  1241. '<input type="text" class="form-control" name="username" />',
  1242. '</div>',
  1243. '</div>',
  1244. '<div class="form-group">',
  1245. '<label class="col-lg-3 control-label">Email address</label>',
  1246. '<div class="col-lg-5">',
  1247. '<input type="text" class="form-control" name="email" />',
  1248. '</div>',
  1249. '</div>',
  1250. '<div class="form-group">',
  1251. '<label class="col-lg-3 control-label">Password</label>',
  1252. '<div class="col-lg-5">',
  1253. '<input type="password" class="form-control" name="password" />',
  1254. '</div>',
  1255. '</div>',
  1256. '<div class="form-group">',
  1257. '<label class="col-lg-3 control-label">Retype password</label>',
  1258. '<div class="col-lg-5">',
  1259. '<input type="password" class="form-control" name="confirmPassword" />',
  1260. '</div>',
  1261. '</div>',
  1262. '<div class="form-group">',
  1263. '<label class="col-lg-3 control-label">Gender</label>',
  1264. '<div class="col-lg-5">',
  1265. '<div class="radio">',
  1266. '<label><input type="radio" name="gender" value="male" /> Male</label>',
  1267. '</div>',
  1268. '<div class="radio">',
  1269. '<label><input type="radio" name="gender" value="female" /> Female</label>',
  1270. '</div>',
  1271. '<div class="radio">',
  1272. '<label><input type="radio" name="gender" value="other" /> Other</label>',
  1273. '</div>',
  1274. '</div>',
  1275. '</div>',
  1276. '<div class="form-group">',
  1277. '<label class="col-lg-3 control-label">Age</label>',
  1278. '<div class="col-lg-3">',
  1279. '<input type="text" class="form-control" name="age" />',
  1280. '</div>',
  1281. '</div>',
  1282. '<div class="form-group">',
  1283. '<label class="col-lg-3 control-label">Website</label>',
  1284. '<div class="col-lg-5">',
  1285. '<input type="text" class="form-control" name="website" />',
  1286. '</div>',
  1287. '</div>',
  1288. '<div class="form-group">',
  1289. '<label class="col-lg-3 control-label">Phone number</label>',
  1290. '<div class="col-lg-5">',
  1291. '<input type="text" class="form-control" name="phoneNumber" />',
  1292. '</div>',
  1293. '</div>',
  1294. '<div class="form-group">',
  1295. '<label class="col-lg-3 control-label">Languages</label>',
  1296. '<div class="col-lg-5">',
  1297. '<div class="checkbox">',
  1298. '<label><input type="checkbox" name="languages[]" value="english" /> English</label>',
  1299. '</div>',
  1300. '<div class="checkbox">',
  1301. '<label><input type="checkbox" name="languages[]" value="french" /> French</label>',
  1302. '</div>',
  1303. '<div class="checkbox">',
  1304. '<label><input type="checkbox" name="languages[]" value="german" /> German</label>',
  1305. '</div>',
  1306. '<div class="checkbox">',
  1307. '<label><input type="checkbox" name="languages[]" value="russian" /> Russian</label>',
  1308. '</div>',
  1309. '<div class="checkbox">',
  1310. '<label><input type="checkbox" name="languages[]" value="other" /> Other</label>',
  1311. '</div>',
  1312. '</div>',
  1313. '</div>',
  1314. '<div class="form-group">',
  1315. '<label class="col-lg-3 control-label">Programming Languages</label>',
  1316. '<div class="col-lg-5">',
  1317. '<div class="checkbox">',
  1318. '<label><input type="checkbox" name="programs[]" value="net" /> .Net</label>',
  1319. '</div>',
  1320. '<div class="checkbox">',
  1321. '<label><input type="checkbox" name="programs[]" value="java" /> Java</label>',
  1322. '</div>',
  1323. '<div class="checkbox">',
  1324. '<label><input type="checkbox" name="programs[]" value="c" /> C/C++</label>',
  1325. '</div>',
  1326. '<div class="checkbox">',
  1327. '<label><input type="checkbox" name="programs[]" value="php" /> PHP</label>',
  1328. '</div>',
  1329. '<div class="checkbox">',
  1330. '<label><input type="checkbox" name="programs[]" value="perl" /> Perl</label>',
  1331. '</div>',
  1332. '<div class="checkbox">',
  1333. '<label><input type="checkbox" name="programs[]" value="ruby" /> Ruby</label>',
  1334. '</div>',
  1335. '<div class="checkbox">',
  1336. '<label><input type="checkbox" name="programs[]" value="python" /> Python</label>',
  1337. '</div>',
  1338. '<div class="checkbox">',
  1339. '<label><input type="checkbox" name="programs[]" value="javascript" /> Javascript</label>',
  1340. '</div>',
  1341. '</div>',
  1342. '</div>',
  1343. '</form>'
  1344. ].join('')).appendTo('body');
  1345. $('#i18nForm').bootstrapValidator({
  1346. feedbackIcons: {
  1347. valid: 'glyphicon glyphicon-ok',
  1348. invalid: 'glyphicon glyphicon-remove',
  1349. validating: 'glyphicon glyphicon-refresh'
  1350. },
  1351. fields: {
  1352. fullName: {
  1353. validators: {
  1354. notEmpty: {},
  1355. stringCase: {
  1356. 'case': 'upper'
  1357. }
  1358. }
  1359. },
  1360. username: {
  1361. validators: {
  1362. notEmpty: {},
  1363. stringLength: {
  1364. min: 6,
  1365. max: 20
  1366. },
  1367. regexp: {
  1368. regexp: /^[a-zA-Z0-9_\.]+$/
  1369. },
  1370. different: {
  1371. field: 'password'
  1372. }
  1373. }
  1374. },
  1375. email: {
  1376. validators: {
  1377. emailAddress: {}
  1378. }
  1379. },
  1380. password: {
  1381. validators: {
  1382. notEmpty: {},
  1383. identical: {
  1384. field: 'confirmPassword'
  1385. },
  1386. different: {
  1387. field: 'username'
  1388. }
  1389. }
  1390. },
  1391. confirmPassword: {
  1392. validators: {
  1393. notEmpty: {},
  1394. identical: {
  1395. field: 'password'
  1396. },
  1397. different: {
  1398. field: 'username'
  1399. }
  1400. }
  1401. },
  1402. age: {
  1403. validators: {
  1404. notEmpty: {},
  1405. digits: {},
  1406. greaterThan: {
  1407. value: 18
  1408. },
  1409. lessThan: {
  1410. value: 100
  1411. }
  1412. }
  1413. },
  1414. website: {
  1415. validators: {
  1416. notEmpty: {},
  1417. uri: {}
  1418. }
  1419. },
  1420. phoneNumber: {
  1421. validators: {
  1422. notEmpty: {},
  1423. digits: {},
  1424. phone: {
  1425. country: 'US'
  1426. }
  1427. }
  1428. },
  1429. gender: {
  1430. validators: {
  1431. notEmpty: {}
  1432. }
  1433. },
  1434. 'languages[]': {
  1435. validators: {
  1436. notEmpty: {}
  1437. }
  1438. },
  1439. 'programs[]': {
  1440. validators: {
  1441. choice: {
  1442. min: 2,
  1443. max: 4
  1444. }
  1445. }
  1446. }
  1447. }
  1448. });
  1449. this.bv = $('#i18nForm').data('bootstrapValidator');
  1450. this.$fullName = this.bv.getFieldElements('fullName');
  1451. this.$email = this.bv.getFieldElements('email');
  1452. this.$userName = this.bv.getFieldElements('username');
  1453. this.$password = this.bv.getFieldElements('password');
  1454. this.$confirm = this.bv.getFieldElements('confirmPassword');
  1455. this.$age = this.bv.getFieldElements('age');
  1456. this.$website = this.bv.getFieldElements('website');
  1457. this.$phone = this.bv.getFieldElements('phoneNumber');
  1458. this.$program = this.bv.getFieldElements('programs[]');
  1459. });
  1460. afterEach(function() {
  1461. $('#i18nForm').bootstrapValidator('destroy').remove();
  1462. });
  1463. it('default message', function() {
  1464. var format = $.fn.bootstrapValidator.helpers.format,
  1465. i18n = $.fn.bootstrapValidator.i18n;
  1466. this.bv.validate();
  1467. expect(this.bv.getMessages(this.$fullName, 'notEmpty')[0]).toEqual(i18n.notEmpty['default']);
  1468. this.$fullName.val('lowerName');
  1469. this.bv.revalidateField('fullName');
  1470. expect(this.bv.getMessages('fullName', 'stringCase')[0]).toEqual(i18n.stringCase.upper);
  1471. this.bv.resetForm();
  1472. this.$userName.val('123');
  1473. this.bv.validate();
  1474. expect(this.bv.getMessages('username', 'stringLength')[0]).toEqual(format(i18n.stringLength.between, [6, 20]));
  1475. this.bv.resetForm();
  1476. this.$userName.val('contain@#$');
  1477. this.bv.validate();
  1478. expect(this.bv.getMessages(this.$userName, 'regexp')[0]).toEqual(i18n.regexp['default']);
  1479. this.bv.resetForm();
  1480. this.$userName.val('validUserName');
  1481. this.$password.val('validUserName');
  1482. this.bv.validate();
  1483. expect(this.bv.getMessages('username', 'different')[0]).toEqual(i18n.different['default']);
  1484. this.bv.resetForm();
  1485. this.$email.val('A@b@c@example.com');
  1486. this.bv.validate();
  1487. expect(this.bv.getMessages(this.$email, 'emailAddress')[0]).toEqual(i18n.emailAddress['default']);
  1488. this.bv.resetForm();
  1489. this.$password.val('@S3cur3P@@w0rd');
  1490. this.$confirm.val('notMatch');
  1491. this.bv.validate();
  1492. expect(this.bv.getMessages('password', 'identical')[0]).toEqual(i18n.identical['default']);
  1493. this.bv.resetForm();
  1494. this.$age.val('notDigit');
  1495. this.bv.validate();
  1496. expect(this.bv.getMessages('age', 'digits')[0]).toEqual(i18n.digits['default']);
  1497. this.bv.resetForm();
  1498. this.$age.val(10);
  1499. this.bv.validate();
  1500. expect(this.bv.getMessages(this.$age, 'greaterThan')[0]).toEqual(format(i18n.greaterThan['default'], 18));
  1501. this.bv.resetForm();
  1502. this.$age.val(120);
  1503. this.bv.validate();
  1504. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual(format(i18n.lessThan['default'], 100));
  1505. this.bv.resetForm();
  1506. this.$website.val('http://invalidWebsite');
  1507. this.bv.validate();
  1508. expect(this.bv.getMessages('website', 'uri')[0]).toEqual(i18n.uri['default']);
  1509. this.bv.resetForm();
  1510. this.$phone.val('123456');
  1511. this.bv.validate();
  1512. expect(this.bv.getMessages('phoneNumber', 'phone')[0]).toEqual(format(i18n.phone.country, i18n.phone.countries['US']));
  1513. this.bv.resetForm();
  1514. this.$program.eq(0).prop('checked', 'checked');
  1515. this.bv.validate();
  1516. expect(this.bv.getMessages(this.$program, 'choice')[0]).toEqual(format(i18n.choice.between, [2, 4]));
  1517. this.bv.resetForm();
  1518. this.$program.prop('checked', 'checked');
  1519. this.bv.validate();
  1520. expect(this.bv.getMessages('programs[]', 'choice')[0]).toEqual(format(i18n.choice.between, [2, 4]));
  1521. });
  1522. });
  1523. describe('message', function() {
  1524. beforeEach(function() {
  1525. var html = [
  1526. '<div class="container">',
  1527. '<form class="form-horizontal" id="messageForm">',
  1528. '<div class="form-group">',
  1529. '<input type="password" class="form-control" name="password" placeholder="Enter secure password" />',
  1530. '</div>',
  1531. '</form>',
  1532. '</div>'
  1533. ].join('\n');
  1534. $(html).appendTo('body');
  1535. $('#messageForm').bootstrapValidator({
  1536. fields: {
  1537. password: {
  1538. validators: {
  1539. notEmpty: {
  1540. message: 'The password is required'
  1541. },
  1542. callback: {
  1543. callback: function(value, validator) {
  1544. // Check the password strength
  1545. if (value.length < 6) {
  1546. return {
  1547. valid: false,
  1548. message: 'The password must be more than 6 characters'
  1549. }
  1550. }
  1551. if (value === value.toLowerCase()) {
  1552. return {
  1553. valid: false,
  1554. message: 'The password must contain at least one upper case character'
  1555. }
  1556. }
  1557. if (value === value.toUpperCase()) {
  1558. return {
  1559. valid: false,
  1560. message: 'The password must contain at least one lower case character'
  1561. }
  1562. }
  1563. if (value.search(/[0-9]/) < 0) {
  1564. return {
  1565. valid: false,
  1566. message: 'The password must contain at least one digit'
  1567. }
  1568. }
  1569. return true;
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. });
  1576. this.bv = $('#messageForm').data('bootstrapValidator');
  1577. this.$password = this.bv.getFieldElements('password');
  1578. });
  1579. afterEach(function() {
  1580. $('#messageForm').bootstrapValidator('destroy').parent().remove();
  1581. });
  1582. it('update message from callback', function() {
  1583. this.bv.resetForm();
  1584. this.$password.val('123');
  1585. this.bv.validate();
  1586. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must be more than 6 characters');
  1587. this.bv.resetForm();
  1588. this.$password.val('no_upper_case!@#');
  1589. this.bv.validate();
  1590. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one upper case character');
  1591. this.bv.resetForm();
  1592. this.$password.val('NO_LOWER_CASE123');
  1593. this.bv.validate();
  1594. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one lower case character');
  1595. this.bv.resetForm();
  1596. this.$password.val('NoDigits!@#');
  1597. this.bv.validate();
  1598. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password must contain at least one digit');
  1599. });
  1600. it('call updateMessage()', function() {
  1601. this.bv.updateStatus('password', this.bv.STATUS_INVALID, 'callback');
  1602. this.bv.updateMessage('password', 'callback', 'The password is weak');
  1603. expect(this.bv.getMessages('password', 'callback')[0]).toEqual('The password is weak');
  1604. this.bv.updateMessage(this.$password, 'callback', 'The password is not strong');
  1605. expect(this.bv.getMessages(this.$password, 'callback')[0]).toEqual('The password is not strong');
  1606. });
  1607. });
  1608. describe('verbose option', function() {
  1609. beforeEach(function() {
  1610. $([
  1611. '<form class="form-horizontal" id="verboseForm">',
  1612. '<div class="form-group">',
  1613. '<input type="text" name="fullName" class="form-control" ',
  1614. 'required data-bv-notempty-message="The full name is required and cannot be empty" ',
  1615. 'data-bv-regexp="true" data-bv-regexp-regexp="^[a-zA-Z\\s]+$" data-bv-regexp-message="The full name can only consist of alphabetical, number, and space" ',
  1616. 'data-bv-stringlength="true" data-bv-stringlength-min="8" data-bv-stringlength-max="40" data-bv-stringlength-message="The full name must be more than 8 and less than 40 characters long" ',
  1617. '/>',
  1618. '</div>',
  1619. '</form>'
  1620. ].join('\n')).appendTo('body');
  1621. // The order of validators are alphabetical:
  1622. // - notEmpty
  1623. // - regexp
  1624. // - stringLength
  1625. });
  1626. afterEach(function() {
  1627. $('#verboseForm').bootstrapValidator('destroy').remove();
  1628. });
  1629. it('set data-bv-verbose="false" for form', function() {
  1630. var bv = $('#verboseForm').attr('data-bv-verbose', 'false').bootstrapValidator().data('bootstrapValidator'),
  1631. $fullName = bv.getFieldElements('fullName'),
  1632. messages;
  1633. $fullName.val('');
  1634. bv.validate();
  1635. messages = bv.getMessages('fullName');
  1636. expect(messages.length).toEqual(1);
  1637. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1638. bv.resetForm();
  1639. $fullName.val('Special@#$');
  1640. bv.validate();
  1641. messages = bv.getMessages('fullName');
  1642. expect(messages.length).toEqual(1);
  1643. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1644. bv.resetForm();
  1645. $fullName.val('Full');
  1646. bv.validate();
  1647. messages = bv.getMessages('fullName');
  1648. expect(messages.length).toEqual(1);
  1649. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1650. });
  1651. it('set data-bv-verbose="false" for field', function() {
  1652. var bv = $('#verboseForm')
  1653. .attr('data-bv-verbose', 'true')
  1654. .find('[name="fullName"]')
  1655. .attr('data-bv-verbose', 'false')
  1656. .end()
  1657. .bootstrapValidator().data('bootstrapValidator'),
  1658. $fullName = bv.getFieldElements('fullName'),
  1659. messages;
  1660. $fullName.val('');
  1661. bv.validate();
  1662. messages = bv.getMessages('fullName');
  1663. expect(messages.length).toEqual(1);
  1664. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1665. bv.resetForm();
  1666. $fullName.val('Special@#$');
  1667. bv.validate();
  1668. messages = bv.getMessages('fullName');
  1669. expect(messages.length).toEqual(1);
  1670. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1671. bv.resetForm();
  1672. $fullName.val('Full');
  1673. bv.validate();
  1674. messages = bv.getMessages('fullName');
  1675. expect(messages.length).toEqual(1);
  1676. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1677. });
  1678. it('set verbose: "false" for form', function() {
  1679. var bv = $('#verboseForm').bootstrapValidator({ verbose: false }).data('bootstrapValidator'),
  1680. $fullName = bv.getFieldElements('fullName'),
  1681. messages;
  1682. $fullName.val('');
  1683. bv.validate();
  1684. messages = bv.getMessages('fullName');
  1685. expect(messages.length).toEqual(1);
  1686. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1687. bv.resetForm();
  1688. $fullName.val('Special@#$');
  1689. bv.validate();
  1690. messages = bv.getMessages('fullName');
  1691. expect(messages.length).toEqual(1);
  1692. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1693. bv.resetForm();
  1694. $fullName.val('Full');
  1695. bv.validate();
  1696. messages = bv.getMessages('fullName');
  1697. expect(messages.length).toEqual(1);
  1698. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1699. });
  1700. it('set verbose: "false" for field', function() {
  1701. var bv = $('#verboseForm')
  1702. .attr('data-bv-verbose', 'true')
  1703. .bootstrapValidator({
  1704. verbose: true,
  1705. fields: {
  1706. fullName: {
  1707. verbose: false
  1708. }
  1709. }
  1710. })
  1711. .data('bootstrapValidator'),
  1712. $fullName = bv.getFieldElements('fullName'),
  1713. messages;
  1714. $fullName.val('');
  1715. bv.validate();
  1716. messages = bv.getMessages('fullName');
  1717. expect(messages.length).toEqual(1);
  1718. expect(messages[0]).toEqual($fullName.attr('data-bv-notempty-message'));
  1719. bv.resetForm();
  1720. $fullName.val('Special@#$');
  1721. bv.validate();
  1722. messages = bv.getMessages('fullName');
  1723. expect(messages.length).toEqual(1);
  1724. expect(messages[0]).toEqual($fullName.attr('data-bv-regexp-message'));
  1725. bv.resetForm();
  1726. $fullName.val('Full');
  1727. bv.validate();
  1728. messages = bv.getMessages('fullName');
  1729. expect(messages.length).toEqual(1);
  1730. expect(messages[0]).toEqual($fullName.attr('data-bv-stringlength-message'));
  1731. });
  1732. });
  1733. function betweenCompareMin() {
  1734. var compareTo = $('#betweenForm').find('[name="minAge"]').val();
  1735. $('#msgMin').html('betweenCompareMin() called; compare to ' + compareTo);
  1736. return compareTo;
  1737. };
  1738. function betweenCompareMax() {
  1739. var compareTo = $('#betweenForm').find('[name="maxAge"]').val();
  1740. $('#msgMax').html('betweenCompareMax() called; compare to ' + compareTo);
  1741. return compareTo;
  1742. };
  1743. TestSuite = $.extend({}, TestSuite, {
  1744. between: {
  1745. compareToMin: function(value, validator, $field) {
  1746. var compareTo = $('#betweenForm').find('[name="minAge"]').val();
  1747. $('#msgMin').html('TestSuite.between.compareToMin() called; compare to ' + compareTo);
  1748. return compareTo;
  1749. },
  1750. compareToMax: function(value, validator, $field) {
  1751. var compareTo = $('#betweenForm').find('[name="maxAge"]').val();
  1752. $('#msgMax').html('TestSuite.between.compareToMax() called; compare to ' + compareTo);
  1753. return compareTo;
  1754. }
  1755. }
  1756. });
  1757. describe('between', function() {
  1758. beforeEach(function() {
  1759. $([
  1760. '<form class="form-horizontal" id="betweenForm">',
  1761. '<div id="msgMin"></div>',
  1762. '<div id="msgMax"></div>',
  1763. '<div class="form-group">',
  1764. '<input type="text" name="minAge" />',
  1765. '</div>',
  1766. '<div class="form-group">',
  1767. '<input type="text" name="maxAge" />',
  1768. '</div>',
  1769. '<div class="form-group">',
  1770. '<input type="text" name="age" data-bv-between data-bv-between-min="18" data-bv-between-max="100" />',
  1771. '</div>',
  1772. '</form>'
  1773. ].join('\n')).appendTo('body');
  1774. $('#betweenForm').bootstrapValidator();
  1775. this.bv = $('#betweenForm').data('bootstrapValidator');
  1776. this.$minAge = this.bv.getFieldElements('minAge');
  1777. this.$maxAge = this.bv.getFieldElements('maxAge');
  1778. this.$age = this.bv.getFieldElements('age');
  1779. });
  1780. afterEach(function() {
  1781. $('#betweenForm').bootstrapValidator('destroy').remove();
  1782. });
  1783. it('not a number', function() {
  1784. this.$age.val('50abc');
  1785. this.bv.validate();
  1786. expect(this.bv.isValid()).toEqual(false);
  1787. });
  1788. it('compare to value', function() {
  1789. this.$age.val(10);
  1790. this.bv.validate();
  1791. expect(this.bv.isValid()).toEqual(false);
  1792. this.bv.resetForm();
  1793. this.$age.val(120);
  1794. this.bv.validate();
  1795. expect(this.bv.isValid()).toEqual(false);
  1796. this.bv.resetForm();
  1797. this.$age.val(30);
  1798. this.bv.validate();
  1799. expect(this.bv.isValid()).toBeTruthy();
  1800. });
  1801. it('compare to other field', function() {
  1802. this.$age.attr('data-bv-between-min', 'minAge')
  1803. .attr('data-bv-between-max', 'maxAge');
  1804. this.bv.destroy();
  1805. this.bv = $('#betweenForm').bootstrapValidator().data('bootstrapValidator');
  1806. this.$minAge.val(2);
  1807. this.$maxAge.val(10);
  1808. this.$age.val(5);
  1809. this.bv.validate();
  1810. expect(this.bv.isValid()).toBeTruthy();
  1811. this.bv.resetForm();
  1812. this.$minAge.val(20);
  1813. this.$maxAge.val(40);
  1814. this.$age.val(50);
  1815. this.bv.validate();
  1816. expect(this.bv.isValid()).toEqual(false);
  1817. expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
  1818. });
  1819. it('compare to return value of a function', function() {
  1820. this.$age.attr('data-bv-between-min', 'betweenCompareMin')
  1821. .attr('data-bv-between-max', 'betweenCompareMax');
  1822. this.bv.destroy();
  1823. this.bv = $('#betweenForm').bootstrapValidator().data('bootstrapValidator');
  1824. this.$minAge.val(20);
  1825. this.$maxAge.val(30);
  1826. this.$age.val(18);
  1827. this.bv.validate();
  1828. expect($('#msgMin').html()).toEqual('betweenCompareMin() called; compare to 20');
  1829. expect($('#msgMax').html()).toEqual('betweenCompareMax() called; compare to 30');
  1830. expect(this.bv.isValid()).toEqual(false);
  1831. expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
  1832. this.bv.resetForm();
  1833. this.$minAge.val(2);
  1834. this.$maxAge.val(10);
  1835. this.$age.val(6);
  1836. this.bv.validate();
  1837. expect($('#msgMin').html()).toEqual('betweenCompareMin() called; compare to 2');
  1838. expect($('#msgMax').html()).toEqual('betweenCompareMax() called; compare to 10');
  1839. expect(this.bv.isValid()).toBeTruthy();
  1840. });
  1841. it('compare to return value of a namespace function', function() {
  1842. this.$age.attr('data-bv-between-min', 'TestSuite.between.compareToMin')
  1843. .attr('data-bv-between-max', 'TestSuite.between.compareToMax');
  1844. this.bv.destroy();
  1845. this.bv = $('#betweenForm').bootstrapValidator().data('bootstrapValidator');
  1846. this.$minAge.val(20);
  1847. this.$maxAge.val(30);
  1848. this.$age.val(40);
  1849. this.bv.validate();
  1850. expect($('#msgMin').html()).toEqual('TestSuite.between.compareToMin() called; compare to 20');
  1851. expect($('#msgMax').html()).toEqual('TestSuite.between.compareToMax() called; compare to 30');
  1852. expect(this.bv.isValid()).toEqual(false);
  1853. expect(this.bv.getMessages('age', 'between')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.between['default'], [this.$minAge.val(), this.$maxAge.val()]));
  1854. this.bv.resetForm();
  1855. this.$minAge.val(2);
  1856. this.$maxAge.val(10);
  1857. this.$age.val(5);
  1858. this.bv.validate();
  1859. expect($('#msgMin').html()).toEqual('TestSuite.between.compareToMin() called; compare to 2');
  1860. expect($('#msgMax').html()).toEqual('TestSuite.between.compareToMax() called; compare to 10');
  1861. expect(this.bv.isValid()).toBeTruthy();
  1862. });
  1863. });
  1864. function validateCaptcha(value, validator, $field) {
  1865. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  1866. return value === sum + '';
  1867. };
  1868. describe('callback', function() {
  1869. beforeEach(function() {
  1870. $([
  1871. '<form class="form-horizontal" id="callbackForm">',
  1872. '<div class="form-group">',
  1873. '<label class="col-md-3 control-label" id="captchaOperation"></label>',
  1874. '<div class="col-md-2">',
  1875. '<input type="text" class="form-control" name="captcha" />',
  1876. '</div>',
  1877. '</div>',
  1878. '<div class="form-group">',
  1879. '<div class="col-md-2 col-md-offset-3">',
  1880. '<input type="text" class="form-control" name="declarativeCaptcha" data-bv-callback data-bv-callback-callback="validateCaptcha" />',
  1881. '</div>',
  1882. '</div>',
  1883. '</form>'
  1884. ].join('\n')).appendTo('body');
  1885. $('#callbackForm').bootstrapValidator({
  1886. fields: {
  1887. captcha: {
  1888. validators: {
  1889. callback: {
  1890. message: 'Wrong answer',
  1891. callback: function(value, validator, $field) {
  1892. return validateCaptcha(value, validator, $field);
  1893. }
  1894. }
  1895. }
  1896. }
  1897. }
  1898. });
  1899. this.bv = $('#callbackForm').data('bootstrapValidator');
  1900. this.$captcha = this.bv.getFieldElements('captcha');
  1901. this.$declarativeCaptcha = this.bv.getFieldElements('declarativeCaptcha');
  1902. });
  1903. afterEach(function() {
  1904. $('#callbackForm').bootstrapValidator('destroy').remove();
  1905. });
  1906. it('execute the callback', function() {
  1907. $('#captchaOperation').html('1 + 2');
  1908. this.$captcha.val('3');
  1909. this.bv.validate();
  1910. expect(this.bv.isValidField('captcha')).toBeTruthy();
  1911. this.bv.resetForm();
  1912. this.$captcha.val('5');
  1913. this.bv.validate();
  1914. expect(this.bv.isValidField('captcha')).toEqual(false);
  1915. });
  1916. it('callback declarative', function() {
  1917. $('#captchaOperation').html('10 + 20');
  1918. this.$declarativeCaptcha.val('40');
  1919. this.bv.validate();
  1920. expect(this.bv.isValidField('declarativeCaptcha')).toEqual(false);
  1921. this.bv.resetForm();
  1922. this.$declarativeCaptcha.val('30');
  1923. this.bv.validate();
  1924. expect(this.bv.isValidField('declarativeCaptcha')).toBeTruthy();
  1925. });
  1926. });
  1927. describe('color', function() {
  1928. beforeEach(function() {
  1929. var html = [
  1930. '<div class="container">',
  1931. '<form class="form-horizontal" id="colorForm">',
  1932. '<div class="form-group">',
  1933. '<input type="text" name="color" data-bv-color />',
  1934. '<input type="text" name="colorMultiple" data-bv-color />',
  1935. '<input type="text" name="colorHex" data-bv-color />',
  1936. '<input type="text" name="colorRgb" data-bv-color />',
  1937. '<input type="text" name="colorRgba" data-bv-color />',
  1938. '<input type="text" name="colorHsl" data-bv-color />',
  1939. '<input type="text" name="colorHsla" data-bv-color />',
  1940. '<input type="text" name="colorKeyword" data-bv-color />',
  1941. '</div>',
  1942. '</form>',
  1943. '</div>'
  1944. ].join('\n');
  1945. $(html).appendTo('body');
  1946. $('#colorForm').bootstrapValidator({
  1947. colorMultiple: {
  1948. validators: {
  1949. color: {
  1950. type: [
  1951. "hex",
  1952. "rgb"
  1953. ]
  1954. }
  1955. }
  1956. },
  1957. colorHex: {
  1958. validators: {
  1959. color: {
  1960. type: ["hex"]
  1961. }
  1962. }
  1963. },
  1964. colorRgb: {
  1965. validators: {
  1966. color: {
  1967. type: ["rgb"]
  1968. }
  1969. }
  1970. },
  1971. colorRgba: {
  1972. validators: {
  1973. color: {
  1974. type: ["rgba"]
  1975. }
  1976. }
  1977. },
  1978. colorHsl: {
  1979. validators: {
  1980. color: {
  1981. type: ["hsl"]
  1982. }
  1983. }
  1984. },
  1985. colorHsla: {
  1986. validators: {
  1987. color: {
  1988. type: ["hsla"]
  1989. }
  1990. }
  1991. },
  1992. colorKeyword: {
  1993. validators: {
  1994. color: {
  1995. type: ["keyword"]
  1996. }
  1997. }
  1998. }
  1999. });
  2000. this.bv = $('#colorForm').data('bootstrapValidator');
  2001. this.$color = this.bv.getFieldElements('color');
  2002. this.$colorHex = this.bv.getFieldElements('colorHex');
  2003. this.$colorRgb = this.bv.getFieldElements('colorRgb');
  2004. this.$colorRgba = this.bv.getFieldElements('colorRgba');
  2005. this.$colorHsl = this.bv.getFieldElements('colorHsl');
  2006. this.$colorHsla = this.bv.getFieldElements('colorHsla');
  2007. this.$colorKeyword = this.bv.getFieldElements('colorKeyword');
  2008. });
  2009. afterEach(function() {
  2010. $('#colorForm').bootstrapValidator('destroy').parent().remove();
  2011. });
  2012. /* First run all color tests in the color field*/
  2013. // Start hsla() tests
  2014. it('hsla(): accept hsla()', function() {
  2015. this.$color.val('hsla(120,50%,50%,1)');
  2016. this.bv.validate();
  2017. expect(this.bv.isValidField('color')).toBeTruthy();
  2018. });
  2019. it('hsla(): accept spaces around values', function() {
  2020. this.$color.val('hsla( 120 , 50% , 50%, 1 )');
  2021. this.bv.validate();
  2022. expect(this.bv.isValidField('color')).toBeTruthy();
  2023. });
  2024. it('hsla(): accept multiple spaces around values', function() {
  2025. this.$color.val('hsla( 120, 50%, 50% , 1 )');
  2026. this.bv.validate();
  2027. expect(this.bv.isValidField('color')).toBeTruthy();
  2028. });
  2029. it('hsla(): accept negative hue value', function() {
  2030. this.$color.val('hsla(-120,50%,50%,1)');
  2031. this.bv.validate();
  2032. expect(this.bv.isValidField('color')).toBeTruthy();
  2033. });
  2034. it('hsla(): accept hue values larger than 360', function() {
  2035. this.$color.val('hsla(480,50%,50%,1)');
  2036. this.bv.validate();
  2037. expect(this.bv.isValidField('color')).toBeTruthy();
  2038. });
  2039. it('hsla(): accept integer alpha channel value of 0', function() {
  2040. this.$color.val('hsla(120,50%,100%,0)');
  2041. this.bv.validate();
  2042. expect(this.bv.isValidField('color')).toBeTruthy();
  2043. });
  2044. it('hsla(): accept integer alpha channel value of 1', function() {
  2045. this.$color.val('hsla(120,50%,100%,1)');
  2046. this.bv.validate();
  2047. expect(this.bv.isValidField('color')).toBeTruthy();
  2048. });
  2049. it('hsla(): accept floating alpha channel with leading 0', function() {
  2050. this.$color.val('hsla(120,50%,100%,0.5)');
  2051. this.bv.validate();
  2052. expect(this.bv.isValidField('color')).toBeTruthy();
  2053. });
  2054. it('hsla(): accept floating alpha channel without leading 0', function() {
  2055. this.$color.val('hsla(120,50%,100%,.5)');
  2056. this.bv.validate();
  2057. expect(this.bv.isValidField('color')).toBeTruthy();
  2058. });
  2059. it('hsla(): accept floating alpha channel with more than 1 decimal place', function() {
  2060. this.$color.val('hsla(120,50%,100%,.524141)');
  2061. this.bv.validate();
  2062. expect(this.bv.isValidField('color')).toBeTruthy();
  2063. });
  2064. it('hsla(): reject percentage value for alpha channel', function() {
  2065. this.$color.val('hsla(120,50%,100%,50%)');
  2066. this.bv.validate();
  2067. expect(this.bv.isValidField('color')).toEqual(false);
  2068. });
  2069. it('hsla(): reject integers larger than 1 for alpha channel', function() {
  2070. this.$color.val('hsla(120,50%,100%,2)');
  2071. this.bv.validate();
  2072. expect(this.bv.isValidField('color')).toEqual(false);
  2073. });
  2074. it('hsla(): reject negative integers for alpha channel', function() {
  2075. this.$color.val('hsla(120,50%,100%,-1)');
  2076. this.bv.validate();
  2077. expect(this.bv.isValidField('color')).toEqual(false);
  2078. });
  2079. it('hsla(): reject floats larger than 1 for alpha channel', function() {
  2080. this.$color.val('hsla(120,50%,100%,1.000000000001)');
  2081. this.bv.validate();
  2082. expect(this.bv.isValidField('color')).toEqual(false);
  2083. });
  2084. it('hsla(): reject negative floats for alpha channel', function() {
  2085. this.$color.val('hsla(120,50%,100%,-0.5)');
  2086. this.bv.validate();
  2087. expect(this.bv.isValidField('color')).toEqual(false);
  2088. });
  2089. it('hsla(): reject more floats larger than 1 for alpha channel', function() {
  2090. this.$color.val('hsla(120,50%,100%,2.3)');
  2091. this.bv.validate();
  2092. expect(this.bv.isValidField('color')).toEqual(false);
  2093. });
  2094. it('hsla(): reject negative saturation value', function() {
  2095. this.$color.val('hsla(10,-50%,50%,1)');
  2096. this.bv.validate();
  2097. expect(this.bv.isValidField('color')).toEqual(false);
  2098. });
  2099. it('hsla(): reject negative lightness', function() {
  2100. this.$color.val('hsla(10,50%,-50%,1)');
  2101. this.bv.validate();
  2102. expect(this.bv.isValidField('color')).toEqual(false);
  2103. });
  2104. it('hsla(): require hsla()', function() {
  2105. this.$color.val('120,50%,50%,1');
  2106. this.bv.validate();
  2107. expect(this.bv.isValidField('color')).toEqual(false);
  2108. });
  2109. it('hsla(): reject percentages above 100%', function() {
  2110. this.$color.val('hsla(120,100%,101%,1)');
  2111. this.bv.validate();
  2112. expect(this.bv.isValidField('color')).toEqual(false);
  2113. });
  2114. it('hsla(): reject space between hsla and (', function() {
  2115. this.$color.val('hsla (120,50%,50%,1)');
  2116. this.bv.validate();
  2117. expect(this.bv.isValidField('color')).toEqual(false);
  2118. });
  2119. it('hsla(): reject leading space', function() {
  2120. this.$color.val(' hsla(120,50%,50%,1)');
  2121. this.bv.validate();
  2122. expect(this.bv.isValidField('color')).toEqual(false);
  2123. });
  2124. it('hsla(): reject trailing space', function() {
  2125. this.$color.val('hsla(120,50%,50%,1) ');
  2126. this.bv.validate();
  2127. expect(this.bv.isValidField('color')).toEqual(false);
  2128. });
  2129. it('hsla(): reject percentages in hue value', function() {
  2130. this.$color.val('hsla(50%, 50%, 100%,1)');
  2131. this.bv.validate();
  2132. expect(this.bv.isValidField('color')).toEqual(false);
  2133. });
  2134. it('hsla(): reject integers in saturation value', function() {
  2135. this.$color.val('hsla(120, 50, 100%,1)');
  2136. this.bv.validate();
  2137. expect(this.bv.isValidField('color')).toEqual(false);
  2138. });
  2139. it('hsla(): reject integers in lightness value', function() {
  2140. this.$color.val('hsla(120, 50%, 100,1)');
  2141. this.bv.validate();
  2142. expect(this.bv.isValidField('color')).toEqual(false);
  2143. });
  2144. // Start hsl() tests
  2145. it('hsl(): accept hsl()', function() {
  2146. this.$color.val('hsl(120,50%,50%)');
  2147. this.bv.validate();
  2148. expect(this.bv.isValidField('color')).toBeTruthy();
  2149. });
  2150. it('hsl(): accept spaces around values', function() {
  2151. this.$color.val('hsl( 120 , 50% , 50% )');
  2152. this.bv.validate();
  2153. expect(this.bv.isValidField('color')).toBeTruthy();
  2154. });
  2155. it('hsl(): accept multiple spaces around values', function() {
  2156. this.$color.val('hsl( 120, 50%, 50% )');
  2157. this.bv.validate();
  2158. expect(this.bv.isValidField('color')).toBeTruthy();
  2159. });
  2160. it('hsl(): accept negative hue value', function() {
  2161. this.$color.val('hsl(-120,50%,50%)');
  2162. this.bv.validate();
  2163. expect(this.bv.isValidField('color')).toBeTruthy();
  2164. });
  2165. it('hsl(): accept hue values larger than 360', function() {
  2166. this.$color.val('hsl(480,50%,50%)');
  2167. this.bv.validate();
  2168. expect(this.bv.isValidField('color')).toBeTruthy();
  2169. });
  2170. it('hsl(): reject negative saturation value', function() {
  2171. this.$color.val('hsl(10,-50%,50%)');
  2172. this.bv.validate();
  2173. expect(this.bv.isValidField('color')).toEqual(false);
  2174. });
  2175. it('hsl(): reject negative lightness', function() {
  2176. this.$color.val('hsl(10,50%,-50%)');
  2177. this.bv.validate();
  2178. expect(this.bv.isValidField('color')).toEqual(false);
  2179. });
  2180. it('hsl(): require hsl()', function() {
  2181. this.$color.val('120,50%,50%');
  2182. this.bv.validate();
  2183. expect(this.bv.isValidField('color')).toEqual(false);
  2184. });
  2185. it('hsl(): reject percentages above 100%', function() {
  2186. this.$color.val('hsl(120,100%,101%)');
  2187. this.bv.validate();
  2188. expect(this.bv.isValidField('color')).toEqual(false);
  2189. });
  2190. it('hsl(): reject space between hsl and (', function() {
  2191. this.$color.val('hsl (120,50%,50%)');
  2192. this.bv.validate();
  2193. expect(this.bv.isValidField('color')).toEqual(false);
  2194. });
  2195. it('hsl(): reject leading space', function() {
  2196. this.$color.val(' hsl(120,50%,50%)');
  2197. this.bv.validate();
  2198. expect(this.bv.isValidField('color')).toEqual(false);
  2199. });
  2200. it('hsl(): reject trailing space', function() {
  2201. this.$color.val('hsl(120,50%,50%) ');
  2202. this.bv.validate();
  2203. expect(this.bv.isValidField('color')).toEqual(false);
  2204. });
  2205. it('hsl(): reject percentages in hue value', function() {
  2206. this.$color.val('hsl(50%, 50%, 100%)');
  2207. this.bv.validate();
  2208. expect(this.bv.isValidField('color')).toEqual(false);
  2209. });
  2210. it('hsl(): reject integers in saturation value', function() {
  2211. this.$color.val('hsl(120, 50, 100%)');
  2212. this.bv.validate();
  2213. expect(this.bv.isValidField('color')).toEqual(false);
  2214. });
  2215. it('hsl(): reject integers in lightness value', function() {
  2216. this.$color.val('hsl(120, 50%, 100)');
  2217. this.bv.validate();
  2218. expect(this.bv.isValidField('color')).toEqual(false);
  2219. });
  2220. // Start keyword test
  2221. it('keyword: accept transparent', function() {
  2222. this.$color.val('transparent');
  2223. this.bv.validate();
  2224. expect(this.bv.isValidField('color')).toBeTruthy();
  2225. });
  2226. it('keyword: accept blueviolet', function() {
  2227. this.$color.val('transparent');
  2228. this.bv.validate();
  2229. expect(this.bv.isValidField('color')).toBeTruthy();
  2230. });
  2231. it('keyword: reject combined keywords', function() {
  2232. this.$color.val('blueviolet red');
  2233. this.bv.validate();
  2234. expect(this.bv.isValidField('color')).toEqual(false);
  2235. });
  2236. it('keyword: reject shady', function() {
  2237. this.$color.val('shady');
  2238. this.bv.validate();
  2239. expect(this.bv.isValidField('color')).toEqual(false);
  2240. });
  2241. it('keyword: reject blueish', function() {
  2242. this.$color.val('blueish');
  2243. this.bv.validate();
  2244. expect(this.bv.isValidField('color')).toEqual(false);
  2245. });
  2246. // Start rgba() test
  2247. it('rgba(): accept rgba()', function() {
  2248. this.$color.val('rgba(255,255,255,1)');
  2249. this.bv.validate();
  2250. expect(this.bv.isValidField('color')).toBeTruthy();
  2251. });
  2252. it('rgba(): accept spaces around numeric values', function() {
  2253. this.$color.val('rgba( 255 , 255 , 255 , 1 )');
  2254. this.bv.validate();
  2255. expect(this.bv.isValidField('color')).toBeTruthy();
  2256. });
  2257. it('rgba(): accept multiple spaces around numeric values', function() {
  2258. this.$color.val('rgba( 255 , 255 , 255 , 1 )');
  2259. this.bv.validate();
  2260. expect(this.bv.isValidField('color')).toBeTruthy();
  2261. });
  2262. it('rgba(): accept interger values', function() {
  2263. this.$color.val('rgba(255,255,255,1)');
  2264. this.bv.validate();
  2265. expect(this.bv.isValidField('color')).toBeTruthy();
  2266. });
  2267. it('rgba(): accept percent values', function() {
  2268. this.$color.val('rgba(100%,100%,100%,1)');
  2269. this.bv.validate();
  2270. expect(this.bv.isValidField('color')).toBeTruthy();
  2271. });
  2272. it('rgba(): accept integer alpha channel value of 0', function() {
  2273. this.$color.val('rgba(255,255,255,0)');
  2274. this.bv.validate();
  2275. expect(this.bv.isValidField('color')).toBeTruthy();
  2276. });
  2277. it('rgba(): accept integer alpha channel value of 1', function() {
  2278. this.$color.val('rgba(255,255,255,1)');
  2279. this.bv.validate();
  2280. expect(this.bv.isValidField('color')).toBeTruthy();
  2281. });
  2282. it('rgba(): accept floating alpha channel with leading 0', function() {
  2283. this.$color.val('rgba(255,255,255,0.5)');
  2284. this.bv.validate();
  2285. expect(this.bv.isValidField('color')).toBeTruthy();
  2286. });
  2287. it('rgba(): accept floating alpha channel without leading 0', function() {
  2288. this.$color.val('rgba(255,255,255,.5)');
  2289. this.bv.validate();
  2290. expect(this.bv.isValidField('color')).toBeTruthy();
  2291. });
  2292. it('rgba(): accept floating alpha channel with more than 1 decimal place', function() {
  2293. this.$color.val('rgba(255,255,255,.524141)');
  2294. this.bv.validate();
  2295. expect(this.bv.isValidField('color')).toBeTruthy();
  2296. });
  2297. it('rgba(): accept integer alpha channel value of 0 with percentage rgb values', function() {
  2298. this.$color.val('rgba(100%,100%,100%,0)');
  2299. this.bv.validate();
  2300. expect(this.bv.isValidField('color')).toBeTruthy();
  2301. });
  2302. it('rgba(): accept integer alpha channel value of 1 with percentage rgb values', function() {
  2303. this.$color.val('rgba(100%,100%,100%,1)');
  2304. this.bv.validate();
  2305. expect(this.bv.isValidField('color')).toBeTruthy();
  2306. });
  2307. it('rgba(): accept floating alpha channel with leading 0 with percentage rgb values', function() {
  2308. this.$color.val('rgba(100%,100%,100%,0.5)');
  2309. this.bv.validate();
  2310. expect(this.bv.isValidField('color')).toBeTruthy();
  2311. });
  2312. it('rgba(): accept floating alpha channel without leading 0 with percentage rgb values', function() {
  2313. this.$color.val('rgba(100%,100%,100%,.5)');
  2314. this.bv.validate();
  2315. expect(this.bv.isValidField('color')).toBeTruthy();
  2316. });
  2317. it('rgba(): accept floating alpha channel with more than 1 decimal place with percentage rgb values', function() {
  2318. this.$color.val('rgba(100%,100%,100%,.524141)');
  2319. this.bv.validate();
  2320. expect(this.bv.isValidField('color')).toBeTruthy();
  2321. });
  2322. it('rgba(): reject percentage value for alpha channel', function() {
  2323. this.$color.val('rgba(100%,100%,100%,50%)');
  2324. this.bv.validate();
  2325. expect(this.bv.isValidField('color')).toEqual(false);
  2326. });
  2327. it('rgba(): reject integers larger than 1 for alpha channel', function() {
  2328. this.$color.val('rgba(255,255,255,2)');
  2329. this.bv.validate();
  2330. expect(this.bv.isValidField('color')).toEqual(false);
  2331. });
  2332. it('rgba(): reject negative integers for alpha channel', function() {
  2333. this.$color.val('rgba(255,255,255,-1)');
  2334. this.bv.validate();
  2335. expect(this.bv.isValidField('color')).toEqual(false);
  2336. });
  2337. it('rgba(): reject floats larger than 1 for alpha channel', function() {
  2338. this.$color.val('rgba(255,255,255,1.000000000001)');
  2339. this.bv.validate();
  2340. expect(this.bv.isValidField('color')).toEqual(false);
  2341. });
  2342. it('rgba(): reject negative floats for alpha channel', function() {
  2343. this.$color.val('rgba(255,255,255,-0.5)');
  2344. this.bv.validate();
  2345. expect(this.bv.isValidField('color')).toEqual(false);
  2346. });
  2347. it('rgba(): reject more floats larger than 1 for alpha channel', function() {
  2348. this.$color.val('rgba(255,255,255,2.3)');
  2349. this.bv.validate();
  2350. expect(this.bv.isValidField('color')).toEqual(false);
  2351. });
  2352. it('rgba(): reject mixed intergers and percentile input', function() {
  2353. this.$color.val('rgba(255,255,100%,1)');
  2354. this.bv.validate();
  2355. expect(this.bv.isValidField('color')).toEqual(false);
  2356. });
  2357. it('rgba(): reject negative integers', function() {
  2358. this.$color.val('rgba(-10,255,255,1)');
  2359. this.bv.validate();
  2360. expect(this.bv.isValidField('color')).toEqual(false);
  2361. });
  2362. it('rgba(): reject negative percentages', function() {
  2363. this.$color.val('rgba(-10%,100%,100%,1)');
  2364. this.bv.validate();
  2365. expect(this.bv.isValidField('color')).toEqual(false);
  2366. });
  2367. it('rgba(): require rgba()', function() {
  2368. this.$color.val('255,255,255,1');
  2369. this.bv.validate();
  2370. expect(this.bv.isValidField('color')).toEqual(false);
  2371. });
  2372. it('rgba(): reject intergers above 255', function() {
  2373. this.$color.val('rgba(255,255,256),1');
  2374. this.bv.validate();
  2375. expect(this.bv.isValidField('color')).toEqual(false);
  2376. });
  2377. it('rgba(): reject percentages above 100%', function() {
  2378. this.$color.val('rgba(100%,100%,101%,1)');
  2379. this.bv.validate();
  2380. expect(this.bv.isValidField('color')).toEqual(false);
  2381. });
  2382. it('rgba(): reject space between rgba and (', function() {
  2383. this.$color.val('rgba (255,255,255,1)');
  2384. this.bv.validate();
  2385. expect(this.bv.isValidField('color')).toEqual(false);
  2386. });
  2387. it('rgba(): reject leading space', function() {
  2388. this.$color.val(' rgba(255,255,255,1)');
  2389. this.bv.validate();
  2390. expect(this.bv.isValidField('color')).toEqual(false);
  2391. });
  2392. it('rgba(): reject trailing space', function() {
  2393. this.$color.val('rgba(255,255,255,1) ');
  2394. this.bv.validate();
  2395. expect(this.bv.isValidField('color')).toEqual(false);
  2396. });
  2397. // Start rgb() test
  2398. it('rgb(): accept rgb()', function() {
  2399. this.$color.val('rgb(255,255,255)');
  2400. this.bv.validate();
  2401. expect(this.bv.isValidField('color')).toBeTruthy();
  2402. });
  2403. it('rgb(): accept spaces around numeric values', function() {
  2404. this.$color.val('rgb( 255 , 255 , 255 )');
  2405. this.bv.validate();
  2406. expect(this.bv.isValidField('color')).toBeTruthy();
  2407. });
  2408. it('rgb(): accept multiple spaces around numeric values', function() {
  2409. this.$color.val('rgb( 255, 255, 255 )');
  2410. this.bv.validate();
  2411. expect(this.bv.isValidField('color')).toBeTruthy();
  2412. });
  2413. it('rgb(): accept interger values', function() {
  2414. this.$color.val('rgb(255,255,255)');
  2415. this.bv.validate();
  2416. expect(this.bv.isValidField('color')).toBeTruthy();
  2417. });
  2418. it('rgb(): accept percent values', function() {
  2419. this.$color.val('rgb(100%,100%,100%)');
  2420. this.bv.validate();
  2421. expect(this.bv.isValidField('color')).toBeTruthy();
  2422. });
  2423. it('rgb(): reject mixed intergers and percentile input', function() {
  2424. this.$color.val('rgb(255,255,100%)');
  2425. this.bv.validate();
  2426. expect(this.bv.isValidField('color')).toEqual(false);
  2427. });
  2428. it('rgb(): reject negative integers', function() {
  2429. this.$color.val('rgb(-10,255,255)');
  2430. this.bv.validate();
  2431. expect(this.bv.isValidField('color')).toEqual(false);
  2432. });
  2433. it('rgb(): reject negative percentages', function() {
  2434. this.$color.val('rgb(-10%,100%,100%)');
  2435. this.bv.validate();
  2436. expect(this.bv.isValidField('color')).toEqual(false);
  2437. });
  2438. it('rgb(): require rgb()', function() {
  2439. this.$color.val('255,255,255');
  2440. this.bv.validate();
  2441. expect(this.bv.isValidField('color')).toEqual(false);
  2442. });
  2443. it('rgb(): reject intergers above 255', function() {
  2444. this.$color.val('rgb(255,255,256)');
  2445. this.bv.validate();
  2446. expect(this.bv.isValidField('color')).toEqual(false);
  2447. });
  2448. it('rgb(): reject percentages above 100%', function() {
  2449. this.$color.val('rgb(100%,100%,101%)');
  2450. this.bv.validate();
  2451. expect(this.bv.isValidField('color')).toEqual(false);
  2452. });
  2453. it('rgb(): reject space between rgb and (', function() {
  2454. this.$color.val('rgb (255,255,255)');
  2455. this.bv.validate();
  2456. expect(this.bv.isValidField('color')).toEqual(false);
  2457. });
  2458. it('rgb(): reject leading space', function() {
  2459. this.$color.val(' rgb(255,255,255)');
  2460. this.bv.validate();
  2461. expect(this.bv.isValidField('color')).toEqual(false);
  2462. });
  2463. it('rgb(): reject trailing space', function() {
  2464. this.$color.val('rgb(255,255,255) ');
  2465. this.bv.validate();
  2466. expect(this.bv.isValidField('color')).toEqual(false);
  2467. });
  2468. /* Run individual tests */
  2469. it('Individual field keyword: accept keyword', function() {
  2470. this.$colorKeyword.val('blue');
  2471. this.bv.validate();
  2472. expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
  2473. });
  2474. it('Individual field keyword: reject rgb', function() {
  2475. this.$colorKeyword.val('rgb(255,255,255)');
  2476. this.bv.validate();
  2477. expect(this.bv.isValidField('colorKeyword')).toBeTruthy();
  2478. });
  2479. it('Individual field hex: accept 6 char hex', function() {
  2480. this.$colorHex.val('#0000FF');
  2481. this.bv.validate();
  2482. expect(this.bv.isValidField('colorHex')).toBeTruthy();
  2483. });
  2484. it('Individual field hex: reject keyword', function() {
  2485. this.$colorHex.val('blue');
  2486. this.bv.validate();
  2487. expect(this.bv.isValidField('colorHex')).toBeTruthy();
  2488. });
  2489. it('Individual field rgb(): accept rgb()', function() {
  2490. this.$colorRgb.val('rgb(255,255,255)');
  2491. this.bv.validate();
  2492. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2493. });
  2494. it('Individual field rgb(): reject hex', function() {
  2495. this.$colorRgb.val('#0000FF');
  2496. this.bv.validate();
  2497. expect(this.bv.isValidField('colorRgb')).toBeTruthy();
  2498. });
  2499. it('Individual field rgba(): accept rgba()', function() {
  2500. this.$colorRgba.val('rgba(255,255,255,1)');
  2501. this.bv.validate();
  2502. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2503. });
  2504. it('Individual field rgba(): reject rgb()', function() {
  2505. this.$colorRgba.val('rgb(255,255,255)');
  2506. this.bv.validate();
  2507. expect(this.bv.isValidField('colorRgba')).toBeTruthy();
  2508. });
  2509. it('Individual field hsl(): accept hsl()', function() {
  2510. this.$colorHsl.val('hsl(120,50%,50%)');
  2511. this.bv.validate();
  2512. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2513. });
  2514. it('Individual field hsl(): reject rgba()', function() {
  2515. this.$colorHsl.val('rgba(255,255,255,1)');
  2516. this.bv.validate();
  2517. expect(this.bv.isValidField('colorHsl')).toBeTruthy();
  2518. });
  2519. it('Individual field hsla(): accept hsla()', function() {
  2520. this.$colorHsla.val('hsla(120,50%,50%,1)');
  2521. this.bv.validate();
  2522. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2523. });
  2524. it('Individual field hsla(): reject hsl()', function() {
  2525. this.$colorHsla.val('hsl(120,50%,50%)');
  2526. this.bv.validate();
  2527. expect(this.bv.isValidField('colorHsla')).toBeTruthy();
  2528. });
  2529. });
  2530. describe('creditCard', function() {
  2531. // Get the fake credit card number at http://www.getcreditcardnumbers.com/
  2532. beforeEach(function() {
  2533. var html = [
  2534. '<div class="container">',
  2535. '<form class="form-horizontal" id="ccForm">',
  2536. '<div class="form-group">',
  2537. '<input type="text" name="cc" data-bv-creditcard />',
  2538. '</div>',
  2539. '</form>',
  2540. '</div>'
  2541. ].join('\n');
  2542. $(html).appendTo('body');
  2543. $('#ccForm').bootstrapValidator();
  2544. this.bv = $('#ccForm').data('bootstrapValidator');
  2545. this.$creditCard = this.bv.getFieldElements('cc');
  2546. });
  2547. afterEach(function() {
  2548. $('#ccForm').bootstrapValidator('destroy').parent().remove();
  2549. });
  2550. it('accept spaces', function() {
  2551. this.$creditCard.val('5267 9789 9451 9654');
  2552. this.bv.validate();
  2553. expect(this.bv.isValidField('cc')).toBeTruthy();
  2554. });
  2555. it('accept dashes', function() {
  2556. this.$creditCard.val('6011-2649-6840-4521');
  2557. this.bv.validate();
  2558. expect(this.bv.isValidField('cc')).toBeTruthy();
  2559. });
  2560. it('invalid format', function() {
  2561. this.$creditCard.val('4539.1870.2954.3862');
  2562. this.bv.validate();
  2563. expect(this.bv.isValidField('cc')).toEqual(false);
  2564. });
  2565. it('American Express', function() {
  2566. this.$creditCard.val('340653705597107');
  2567. this.bv.validate();
  2568. expect(this.bv.isValidField('cc')).toBeTruthy();
  2569. });
  2570. it('American Express invalid length', function() {
  2571. this.$creditCard.val('3744148309166730');
  2572. this.bv.validate();
  2573. expect(this.bv.isValidField('cc')).toEqual(false);
  2574. });
  2575. it('American Express invalid prefix', function() {
  2576. this.$creditCard.val('356120148436654');
  2577. this.bv.validate();
  2578. expect(this.bv.isValidField('cc')).toEqual(false);
  2579. });
  2580. it('Diners Club', function() {
  2581. this.$creditCard.val('30130708434187');
  2582. this.bv.validate();
  2583. expect(this.bv.isValidField('cc')).toBeTruthy();
  2584. });
  2585. it('Diners Club (US)', function() {
  2586. this.$creditCard.val('5517479515603901');
  2587. this.bv.validate();
  2588. expect(this.bv.isValidField('cc')).toBeTruthy();
  2589. });
  2590. it('Discover', function() {
  2591. this.$creditCard.val('6011734674929094');
  2592. this.bv.validate();
  2593. expect(this.bv.isValidField('cc')).toBeTruthy();
  2594. });
  2595. it('JCB', function() {
  2596. this.$creditCard.val('3566002020360505');
  2597. this.bv.validate();
  2598. expect(this.bv.isValidField('cc')).toBeTruthy();
  2599. });
  2600. it('Laser', function() {
  2601. this.$creditCard.val('6304 9000 1774 0292 441');
  2602. this.bv.validate();
  2603. expect(this.bv.isValidField('cc')).toBeTruthy();
  2604. });
  2605. it('Maestro', function() {
  2606. this.$creditCard.val('6762835098779303');
  2607. this.bv.validate();
  2608. expect(this.bv.isValidField('cc')).toBeTruthy();
  2609. });
  2610. it('Mastercard', function() {
  2611. this.$creditCard.val('5303765013600904');
  2612. this.bv.validate();
  2613. expect(this.bv.isValidField('cc')).toBeTruthy();
  2614. });
  2615. it('Solo', function() {
  2616. this.$creditCard.val('6334580500000000');
  2617. this.bv.validate();
  2618. expect(this.bv.isValidField('cc')).toBeTruthy();
  2619. });
  2620. it('Visa', function() {
  2621. this.$creditCard.val('4929248980295542');
  2622. this.bv.validate();
  2623. expect(this.bv.isValidField('cc')).toBeTruthy();
  2624. });
  2625. it('Visa invalid check digit', function() {
  2626. this.$creditCard.val('4532599916257826');
  2627. this.bv.validate();
  2628. expect(this.bv.isValidField('cc')).toEqual(false);
  2629. });
  2630. });
  2631. function getDate(value, validator, $field) {
  2632. return validator.getFieldElements('date').val();
  2633. };
  2634. TestSuite = $.extend({}, TestSuite, {
  2635. Date: {
  2636. getDate: function(value, validator, $field) {
  2637. return validator.getFieldElements('date').val();
  2638. }
  2639. }
  2640. });
  2641. describe('date', function() {
  2642. beforeEach(function() {
  2643. $([
  2644. '<form class="form-horizontal" id="dateForm">',
  2645. '<div id="msg"></div>',
  2646. '<div class="form-group">',
  2647. '<input type="text" name="date" data-bv-date />',
  2648. '</div>',
  2649. '<div class="form-group">',
  2650. '<input type="text" name="minDate" data-bv-date data-bv-date-min="" />',
  2651. '</div>',
  2652. '<div class="form-group">',
  2653. '<input type="text" name="maxDate" data-bv-date data-bv-date-max="" />',
  2654. '</div>',
  2655. '<div class="form-group">',
  2656. '<input type="text" name="range" data-bv-date data-bv-date-min="" data-bv-date-max="" />',
  2657. '</div>',
  2658. '</form>'
  2659. ].join('\n')).appendTo('body');
  2660. $('#dateForm').bootstrapValidator();
  2661. this.bv = $('#dateForm').data('bootstrapValidator');
  2662. this.$date = this.bv.getFieldElements('date');
  2663. this.$minDate = this.bv.getFieldElements('minDate');
  2664. this.$maxDate = this.bv.getFieldElements('maxDate');
  2665. this.$range = this.bv.getFieldElements('range');
  2666. });
  2667. afterEach(function() {
  2668. $('#dateForm').bootstrapValidator('destroy').remove();
  2669. });
  2670. it('YYYY/MM/DD', function() {
  2671. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
  2672. this.$date.val('2000/01/30');
  2673. this.bv.validate();
  2674. expect(this.bv.isValid()).toBeTruthy();
  2675. // Invalid year
  2676. this.bv.resetForm();
  2677. this.$date.val('100/10/20');
  2678. this.bv.validate();
  2679. expect(this.bv.isValid()).toEqual(false);
  2680. // Invalid month
  2681. this.bv.resetForm();
  2682. this.$date.val('2000/00/10');
  2683. this.bv.validate();
  2684. expect(this.bv.isValid()).toEqual(false);
  2685. this.bv.resetForm();
  2686. this.$date.val('2000/15/10');
  2687. this.bv.validate();
  2688. expect(this.bv.isValid()).toEqual(false);
  2689. // Invalid day
  2690. this.bv.resetForm();
  2691. this.$date.val('2000/03/00');
  2692. this.bv.validate();
  2693. expect(this.bv.isValid()).toEqual(false);
  2694. this.bv.resetForm();
  2695. this.$date.val('2000/10/32');
  2696. this.bv.validate();
  2697. expect(this.bv.isValid()).toEqual(false);
  2698. // Negative number
  2699. this.bv.resetForm();
  2700. this.$date.val('-2000/10/20');
  2701. this.bv.validate();
  2702. expect(this.bv.isValid()).toEqual(false);
  2703. this.bv.resetForm();
  2704. this.$date.val('2000/-10/20');
  2705. this.bv.validate();
  2706. expect(this.bv.isValid()).toEqual(false);
  2707. this.bv.resetForm();
  2708. this.$date.val('2000/10/-20');
  2709. this.bv.validate();
  2710. expect(this.bv.isValid()).toEqual(false);
  2711. // Consist invalid characters
  2712. // Issue #310
  2713. this.bv.resetForm();
  2714. this.$date.val('aaaa/');
  2715. this.bv.validate();
  2716. expect(this.bv.isValid()).toEqual(false);
  2717. this.bv.resetForm();
  2718. this.$date.val('2004df/1dd1/5ffg');
  2719. this.bv.validate();
  2720. expect(this.bv.isValid()).toEqual(false);
  2721. // Issue #475
  2722. this.bv.resetForm();
  2723. this.$date.val('2014/09');
  2724. this.bv.validate();
  2725. expect(this.bv.isValid()).toEqual(false);
  2726. this.bv.resetForm();
  2727. this.$date.val('2014/09/');
  2728. this.bv.validate();
  2729. expect(this.bv.isValid()).toEqual(false);
  2730. this.bv.resetForm();
  2731. this.$date.val('2014//15');
  2732. this.bv.validate();
  2733. expect(this.bv.isValid()).toEqual(false);
  2734. this.bv.resetForm();
  2735. this.$date.val('/09/15');
  2736. this.bv.validate();
  2737. expect(this.bv.isValid()).toEqual(false);
  2738. });
  2739. it('MM/DD/YYYY', function() {
  2740. this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
  2741. this.$date.val('09/15/2020');
  2742. this.bv.validate();
  2743. expect(this.bv.isValid()).toBeTruthy();
  2744. this.bv.resetForm();
  2745. this.$date.val('09/15');
  2746. this.bv.validate();
  2747. expect(this.bv.isValid()).toEqual(false);
  2748. this.bv.resetForm();
  2749. this.$date.val('09/15/');
  2750. this.bv.validate();
  2751. expect(this.bv.isValid()).toEqual(false);
  2752. });
  2753. it('number of days in February', function() {
  2754. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
  2755. this.$date.val('2000/02/28');
  2756. this.bv.validate();
  2757. expect(this.bv.isValid()).toBeTruthy();
  2758. this.bv.resetForm();
  2759. this.$date.val('2000/02/29');
  2760. this.bv.validate();
  2761. expect(this.bv.isValid()).toBeTruthy();
  2762. this.bv.resetForm();
  2763. this.$date.val('2001/02/29');
  2764. this.bv.validate();
  2765. expect(this.bv.isValid()).toEqual(false);
  2766. });
  2767. // Issue #681
  2768. it('date, month, year are prefixed by zero', function() {
  2769. this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
  2770. this.$date.val('0012/08/2014');
  2771. this.bv.validate();
  2772. expect(this.bv.isValid()).toEqual(false);
  2773. this.bv.resetForm();
  2774. this.$date.val('12/0008/2014');
  2775. this.bv.validate();
  2776. expect(this.bv.isValid()).toEqual(false);
  2777. this.bv.resetForm();
  2778. this.$date.val('12/08/002014');
  2779. this.bv.validate();
  2780. expect(this.bv.isValid()).toEqual(false);
  2781. this.bv.resetForm();
  2782. this.$date.val('12/08/2014');
  2783. this.bv.validate();
  2784. expect(this.bv.isValid()).toBeTruthy();
  2785. });
  2786. it('hours, minutes, seconds are prefixed by zero', function() {
  2787. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD h:m:s');
  2788. this.$date.val('2014/08/17 0007:30:00');
  2789. this.bv.validate();
  2790. expect(this.bv.isValid()).toEqual(false);
  2791. this.bv.resetForm();
  2792. this.$date.val('2014/08/17 07:030:00');
  2793. this.bv.validate();
  2794. expect(this.bv.isValid()).toEqual(false);
  2795. this.bv.resetForm();
  2796. this.$date.val('2014/08/17 07:30:0000');
  2797. this.bv.validate();
  2798. expect(this.bv.isValid()).toEqual(false);
  2799. this.bv.resetForm();
  2800. this.$date.val('2014/08/17 07:30:00');
  2801. this.bv.validate();
  2802. expect(this.bv.isValid()).toBeTruthy();
  2803. });
  2804. // min test suite
  2805. it('min date format YYYY/MM/DD', function() {
  2806. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  2807. this.bv.updateOption('minDate', 'date', 'min', '2010/01/01');
  2808. this.$minDate.val('2010/01/02');
  2809. this.bv.validate();
  2810. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2811. this.bv.resetForm();
  2812. this.$minDate.val('2010/01/002'); // day prefexid by 0 not allowed
  2813. this.bv.validate();
  2814. expect(this.bv.isValidField('minDate')).toEqual(false);
  2815. this.bv.resetForm();
  2816. this.$minDate.val('2014/08/17');
  2817. this.bv.validate();
  2818. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2819. this.bv.resetForm();
  2820. this.$minDate.val('2009/12/31');
  2821. this.bv.validate();
  2822. expect(this.bv.isValidField('minDate')).toEqual(false);
  2823. this.bv.resetForm();
  2824. this.$minDate.val('2000/01/01');
  2825. this.bv.validate();
  2826. expect(this.bv.isValidField('minDate')).toEqual(false);
  2827. });
  2828. it('min date format YYYY-MM-DD', function() {
  2829. this.bv.updateOption('minDate', 'date', 'format', 'YYYY-MM-DD');
  2830. this.bv.updateOption('minDate', 'date', 'min', '2010-01-01');
  2831. this.$minDate.val('2010-01-02');
  2832. this.bv.validate();
  2833. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2834. this.bv.resetForm();
  2835. this.$minDate.val('2010-001-02'); // month prefexid by 0 not allowed
  2836. this.bv.validate();
  2837. expect(this.bv.isValidField('minDate')).toEqual(false);
  2838. this.bv.resetForm();
  2839. this.$minDate.val('2014-08-17');
  2840. this.bv.validate();
  2841. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2842. this.bv.resetForm();
  2843. this.$minDate.val('2009-12-31');
  2844. this.bv.validate();
  2845. expect(this.bv.isValidField('minDate')).toEqual(false);
  2846. this.bv.resetForm();
  2847. this.$minDate.val('2000-01-01');
  2848. this.bv.validate();
  2849. expect(this.bv.isValidField('minDate')).toEqual(false);
  2850. });
  2851. it('min date format DD/MM/YYYY', function() {
  2852. this.bv.updateOption('minDate', 'date', 'format', 'DD/MM/YYYY');
  2853. this.bv.updateOption('minDate', 'date', 'min', '01/01/2010');
  2854. this.$minDate.val('02/01/2010');
  2855. this.bv.validate();
  2856. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2857. this.bv.resetForm();
  2858. this.$minDate.val('17/08/2014');
  2859. this.bv.validate();
  2860. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2861. this.bv.resetForm();
  2862. this.$minDate.val('02/01/02010'); // year prefixed by 0 not allowed
  2863. this.bv.validate();
  2864. expect(this.bv.isValidField('minDate')).toEqual(false);
  2865. this.bv.resetForm();
  2866. this.$minDate.val('31/12/2009');
  2867. this.bv.validate();
  2868. expect(this.bv.isValidField('minDate')).toEqual(false);
  2869. this.bv.resetForm();
  2870. this.$minDate.val('01/01/2000');
  2871. this.bv.validate();
  2872. expect(this.bv.isValidField('minDate')).toEqual(false);
  2873. });
  2874. it('min date format YYYY-MM-DD h:m:s', function() {
  2875. this.bv.updateOption('minDate', 'date', 'format', 'YYYY-MM-DD h:m:s');
  2876. this.bv.updateOption('minDate', 'date', 'min', '2010-01-01 01:00:00');
  2877. this.bv.resetForm();
  2878. this.$minDate.val('2010-01-01 01:00:01');
  2879. this.bv.validate();
  2880. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2881. this.$minDate.val('2010-01-02 01:00:01');
  2882. this.bv.validate();
  2883. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2884. this.bv.resetForm();
  2885. this.$minDate.val('2014-08-17 12:00:00');
  2886. this.bv.validate();
  2887. expect(this.bv.isValidField('minDate')).toBeTruthy();
  2888. this.bv.resetForm();
  2889. this.$minDate.val('2009-12-31 00:00:00');
  2890. this.bv.validate();
  2891. expect(this.bv.isValidField('minDate')).toEqual(false);
  2892. this.bv.resetForm();
  2893. this.$minDate.val('2009-12-31 010:00:00'); // hours prefixed by 0 not allowed
  2894. this.bv.validate();
  2895. expect(this.bv.isValidField('minDate')).toEqual(false);
  2896. this.bv.resetForm();
  2897. this.$minDate.val('2009-12-31 10:001:00'); // minutes prefixed by 0 not allowed
  2898. this.bv.validate();
  2899. expect(this.bv.isValidField('minDate')).toEqual(false);
  2900. this.bv.resetForm();
  2901. this.$minDate.val('2009-12-31 10:01:012'); // seconds prefixed by 0 not allowed
  2902. this.bv.validate();
  2903. expect(this.bv.isValidField('minDate')).toEqual(false);
  2904. this.bv.resetForm();
  2905. this.$minDate.val('2009-12-31 00:00:00');
  2906. this.bv.validate();
  2907. expect(this.bv.isValidField('minDate')).toEqual(false);
  2908. this.bv.resetForm();
  2909. this.$minDate.val('2000-01-01 23:00:12');
  2910. this.bv.validate();
  2911. expect(this.bv.isValidField('minDate')).toEqual(false);
  2912. });
  2913. // max test suite
  2914. it('max date format YYYY/MM/DD', function() {
  2915. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  2916. this.bv.updateOption('maxDate', 'date', 'max', '2014/09/10');
  2917. this.$maxDate.val('2014/09/09');
  2918. this.bv.validate();
  2919. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2920. this.bv.resetForm();
  2921. this.$maxDate.val('2014/08/17');
  2922. this.bv.validate();
  2923. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2924. this.bv.resetForm();
  2925. this.$maxDate.val('02014/012/031'); // year, month or day prefixed by 0 not allowed
  2926. this.bv.validate();
  2927. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2928. this.bv.resetForm();
  2929. this.$maxDate.val('2014/12/31');
  2930. this.bv.validate();
  2931. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2932. this.bv.resetForm();
  2933. this.$maxDate.val('2015/01/01');
  2934. this.bv.validate();
  2935. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2936. });
  2937. it('max date format YYYY-MM-DD', function() {
  2938. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY-MM-DD');
  2939. this.bv.updateOption('maxDate', 'date', 'max', '2014-09-10');
  2940. this.$maxDate.val('2014-09-09');
  2941. this.bv.validate();
  2942. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2943. this.bv.resetForm();
  2944. this.$maxDate.val('2014-08-17');
  2945. this.bv.validate();
  2946. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2947. this.bv.resetForm();
  2948. this.$maxDate.val('02014-012-031'); // year, month or day prefixed by 0 not allowed
  2949. this.bv.validate();
  2950. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2951. this.bv.resetForm();
  2952. this.$maxDate.val('2014-12-31');
  2953. this.bv.validate();
  2954. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2955. this.bv.resetForm();
  2956. this.$maxDate.val('2015-01-01');
  2957. this.bv.validate();
  2958. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2959. });
  2960. it('max date format DD/MM/YYYY', function() {
  2961. this.bv.updateOption('maxDate', 'date', 'format', 'DD/MM/YYYY');
  2962. this.bv.updateOption('maxDate', 'date', 'max', '10/09/2014');
  2963. this.$maxDate.val('09/09/2014');
  2964. this.bv.validate();
  2965. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2966. this.bv.resetForm();
  2967. this.$maxDate.val('17/08/2014');
  2968. this.bv.validate();
  2969. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2970. this.bv.resetForm();
  2971. this.$maxDate.val('031/012/02014'); // year, month or day prefixed by 0 not allowed
  2972. this.bv.validate();
  2973. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2974. this.bv.resetForm();
  2975. this.$maxDate.val('31/12/2014');
  2976. this.bv.validate();
  2977. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2978. this.bv.resetForm();
  2979. this.$maxDate.val('01/01/2015');
  2980. this.bv.validate();
  2981. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2982. });
  2983. it('max date format YYYY-MM-DD h:m:s', function() {
  2984. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY-MM-DD h:m:s');
  2985. this.bv.updateOption('maxDate', 'date', 'max', '2014-09-10 01:00:00');
  2986. this.$maxDate.val('2014-09-09 01:00:01');
  2987. this.bv.validate();
  2988. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2989. this.bv.resetForm();
  2990. this.$maxDate.val('2014-08-17 12:00:00');
  2991. this.bv.validate();
  2992. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  2993. this.bv.resetForm();
  2994. this.$maxDate.val('2014-09-09 001:001:001'); // hours, minutes or seconds prefixed by 0 not allowed
  2995. this.bv.validate();
  2996. expect(this.bv.isValidField('maxDate')).toEqual(false);
  2997. this.bv.resetForm();
  2998. this.$maxDate.val('2014-12-31 00:00:00');
  2999. this.bv.validate();
  3000. expect(this.bv.isValidField('maxDate')).toEqual(false);
  3001. this.bv.resetForm();
  3002. this.$maxDate.val('2015-01-01 23:00:12');
  3003. this.bv.validate();
  3004. expect(this.bv.isValidField('maxDate')).toEqual(false);
  3005. });
  3006. // range test suite
  3007. it('range format YYYY/MM/DD', function() {
  3008. this.bv.updateOption('range', 'date', 'format', 'YYYY/MM/DD');
  3009. this.bv.updateOption('range', 'date', 'min', '2010/09/10');
  3010. this.bv.updateOption('range', 'date', 'max', '2014/09/10');
  3011. this.$range.val('2011/01/01');
  3012. this.bv.validate();
  3013. expect(this.bv.isValidField('range')).toBeTruthy();
  3014. this.bv.resetForm();
  3015. this.$range.val('2014/09/09');
  3016. this.bv.validate();
  3017. expect(this.bv.isValidField('range')).toBeTruthy();
  3018. this.bv.resetForm();
  3019. this.$range.val('02014/001/031'); // year, month or day prefixed by 0 not allowed
  3020. this.bv.validate();
  3021. expect(this.bv.isValidField('range')).toEqual(false);
  3022. this.bv.resetForm();
  3023. this.$range.val('2010/09/09');
  3024. this.bv.validate();
  3025. expect(this.bv.isValidField('range')).toEqual(false);
  3026. this.bv.resetForm();
  3027. this.$range.val('2014/09/11');
  3028. this.bv.validate();
  3029. expect(this.bv.isValidField('range')).toEqual(false);
  3030. });
  3031. it('range format YYYY-MM-DD', function() {
  3032. this.bv.updateOption('range', 'date', 'format', 'YYYY-MM-DD');
  3033. this.bv.updateOption('range', 'date', 'min', '2010-09-10');
  3034. this.bv.updateOption('range', 'date', 'max', '2014-09-10');
  3035. this.$range.val('2012-01-12');
  3036. this.bv.validate();
  3037. expect(this.bv.isValidField('range')).toBeTruthy();
  3038. this.bv.resetForm();
  3039. this.$range.val('2014-09-09');
  3040. this.bv.validate();
  3041. expect(this.bv.isValidField('range')).toBeTruthy();
  3042. this.bv.resetForm();
  3043. this.$range.val('02014-003-031'); // year, month or day prefixed by 0 not allowed
  3044. this.bv.validate();
  3045. expect(this.bv.isValidField('range')).toEqual(false);
  3046. this.bv.resetForm();
  3047. this.$range.val('2009-12-31');
  3048. this.bv.validate();
  3049. expect(this.bv.isValidField('range')).toEqual(false);
  3050. this.bv.resetForm();
  3051. this.$range.val('2015-01-01');
  3052. this.bv.validate();
  3053. expect(this.bv.isValidField('range')).toEqual(false);
  3054. });
  3055. it('range format DD/MM/YYYY', function() {
  3056. this.bv.updateOption('range', 'date', 'format', 'DD/MM/YYYY');
  3057. this.bv.updateOption('range', 'date', 'min', '10/09/2010');
  3058. this.bv.updateOption('range', 'date', 'max', '10/09/2014');
  3059. this.$range.val('11/11/2011');
  3060. this.bv.validate();
  3061. expect(this.bv.isValidField('range')).toBeTruthy();
  3062. this.bv.resetForm();
  3063. this.$range.val('17/08/2014');
  3064. this.bv.validate();
  3065. expect(this.bv.isValidField('range')).toBeTruthy();
  3066. this.bv.resetForm();
  3067. this.$range.val('031/012/02013'); // year, month or day prefixed by 0 not allowed
  3068. this.bv.validate();
  3069. expect(this.bv.isValidField('range')).toEqual(false);
  3070. this.bv.resetForm();
  3071. this.$range.val('31/01/2010');
  3072. this.bv.validate();
  3073. expect(this.bv.isValidField('range')).toEqual(false);
  3074. this.bv.resetForm();
  3075. this.$range.val('25/03/2015');
  3076. this.bv.validate();
  3077. expect(this.bv.isValidField('range')).toEqual(false);
  3078. });
  3079. it('range format YYYY-MM-DD h:m:s', function() {
  3080. this.bv.updateOption('range', 'date', 'format', 'YYYY-MM-DD h:m:s');
  3081. this.bv.updateOption('range', 'date', 'min', '2010-05-15 22:00:00');
  3082. this.bv.updateOption('range', 'date', 'max', '2015-05-15 22:00:00');
  3083. this.$range.val('2012-07-17 01:00:01');
  3084. this.bv.validate();
  3085. expect(this.bv.isValidField('range')).toBeTruthy();
  3086. this.bv.resetForm();
  3087. this.$range.val('2013-08-17 12:00:00');
  3088. this.bv.validate();
  3089. expect(this.bv.isValidField('range')).toBeTruthy();
  3090. this.bv.resetForm();
  3091. this.$range.val('2011-06-19 001:001:001'); // hours, minutes or seconds prefixed by 0 not allowed
  3092. this.bv.validate();
  3093. expect(this.bv.isValidField('range')).toEqual(false);
  3094. this.bv.resetForm();
  3095. this.$range.val('2008-11-27 23:15:00');
  3096. this.bv.validate();
  3097. expect(this.bv.isValidField('range')).toEqual(false);
  3098. this.bv.resetForm();
  3099. this.$range.val('2015-05-15 22:00:01');
  3100. this.bv.validate();
  3101. expect(this.bv.isValidField('range')).toEqual(false);
  3102. });
  3103. // dynamic min option
  3104. it('dynamic min: name of field', function() {
  3105. this.$minDate.attr('data-bv-date-min', 'date');
  3106. this.bv.destroy();
  3107. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3108. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3109. this.$date.val('2014/09/08');
  3110. this.$minDate.val('2014/09/09');
  3111. this.bv.validate();
  3112. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3113. this.bv.resetForm();
  3114. this.$date.val('2014/09/08');
  3115. this.$minDate.val('2014/08/17');
  3116. this.bv.validate();
  3117. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3118. });
  3119. it('dynamic min: callback declarative function', function() {
  3120. this.$minDate.attr('data-bv-date-min', 'getDate');
  3121. this.bv.destroy();
  3122. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3123. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3124. this.$date.val('2014/09/08');
  3125. this.$minDate.val('2014/09/09');
  3126. this.bv.validate();
  3127. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3128. this.bv.resetForm();
  3129. this.$date.val('2014/10/01');
  3130. this.$minDate.val('2014/08/17');
  3131. this.bv.validate();
  3132. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3133. });
  3134. it('dynamic min: callback declarative function()', function() {
  3135. this.$minDate.attr('data-bv-date-min', 'getDate()');
  3136. this.bv.destroy();
  3137. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3138. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3139. this.$date.val('2014/09/08');
  3140. this.$minDate.val('2014/09/09');
  3141. this.bv.validate();
  3142. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3143. this.bv.resetForm();
  3144. this.$date.val('2014/10/01');
  3145. this.$minDate.val('2014/08/17');
  3146. this.bv.validate();
  3147. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3148. });
  3149. it('dynamic min: callback declarative A.B.C', function() {
  3150. this.$minDate.attr('data-bv-date-min', 'TestSuite.Date.getDate');
  3151. this.bv.destroy();
  3152. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3153. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3154. this.$date.val('2014/09/08');
  3155. this.$minDate.val('2014/09/09');
  3156. this.bv.validate();
  3157. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3158. this.bv.resetForm();
  3159. this.$date.val('2014/10/01');
  3160. this.$minDate.val('2014/08/17');
  3161. this.bv.validate();
  3162. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3163. });
  3164. it('dynamic min: callback declarative A.B.C()', function() {
  3165. this.$minDate.attr('data-bv-date-min', 'TestSuite.Date.getDate()');
  3166. this.bv.destroy();
  3167. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3168. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3169. this.$date.val('2014/09/08');
  3170. this.$minDate.val('2014/09/09');
  3171. this.bv.validate();
  3172. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3173. this.bv.resetForm();
  3174. this.$date.val('2014/10/01');
  3175. this.$minDate.val('2014/08/17');
  3176. this.bv.validate();
  3177. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3178. });
  3179. it('dynamic min: callback programmatically', function() {
  3180. this.$minDate.removeAttr('data-bv-date-min');
  3181. this.bv.destroy();
  3182. this.bv = $('#dateForm')
  3183. .bootstrapValidator({
  3184. fields: {
  3185. minDate: {
  3186. validators: {
  3187. date: {
  3188. min: function(value, validator, $field) {
  3189. return getDate(value, validator, $field);
  3190. }
  3191. }
  3192. }
  3193. }
  3194. }
  3195. })
  3196. .data('bootstrapValidator');
  3197. this.bv.updateOption('minDate', 'date', 'format', 'YYYY/MM/DD');
  3198. this.$date.val('2014/09/08');
  3199. this.$minDate.val('2014/09/09');
  3200. this.bv.validate();
  3201. expect(this.bv.isValidField('minDate')).toBeTruthy();
  3202. this.bv.resetForm();
  3203. this.$date.val('2014/10/01');
  3204. this.$minDate.val('2014/08/17');
  3205. this.bv.validate();
  3206. expect(this.bv.isValidField('minDate')).toBeFalsy();
  3207. });
  3208. // dynamic max option
  3209. it('dynamic max: name of field', function() {
  3210. this.$maxDate.attr('data-bv-date-max', 'date');
  3211. this.bv.destroy();
  3212. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3213. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3214. this.$date.val('2015/01/01');
  3215. this.$maxDate.val('2014/09/09');
  3216. this.bv.validate();
  3217. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3218. this.bv.resetForm();
  3219. this.$date.val('2014/01/01');
  3220. this.$maxDate.val('2014/08/17');
  3221. this.bv.validate();
  3222. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3223. });
  3224. it('dynamic max: callback declarative function', function() {
  3225. this.$maxDate.attr('data-bv-date-max', 'getDate');
  3226. this.bv.destroy();
  3227. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3228. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3229. this.$date.val('2015/01/01');
  3230. this.$maxDate.val('2014/09/09');
  3231. this.bv.validate();
  3232. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3233. this.bv.resetForm();
  3234. this.$date.val('2014/01/01');
  3235. this.$maxDate.val('2014/08/17');
  3236. this.bv.validate();
  3237. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3238. });
  3239. it('dynamic max: callback declarative function()', function() {
  3240. this.$maxDate.attr('data-bv-date-max', 'getDate()');
  3241. this.bv.destroy();
  3242. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3243. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3244. this.$date.val('2015/01/01');
  3245. this.$maxDate.val('2014/09/09');
  3246. this.bv.validate();
  3247. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3248. this.bv.resetForm();
  3249. this.$date.val('2014/01/01');
  3250. this.$maxDate.val('2014/08/17');
  3251. this.bv.validate();
  3252. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3253. });
  3254. it('dynamic max: callback declarative A.B.C', function() {
  3255. this.$maxDate.attr('data-bv-date-max', 'TestSuite.Date.getDate');
  3256. this.bv.destroy();
  3257. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3258. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3259. this.$date.val('2015/01/01');
  3260. this.$maxDate.val('2014/09/09');
  3261. this.bv.validate();
  3262. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3263. this.bv.resetForm();
  3264. this.$date.val('2014/01/01');
  3265. this.$maxDate.val('2014/08/17');
  3266. this.bv.validate();
  3267. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3268. });
  3269. it('dynamic max: callback declarative A.B.C()', function() {
  3270. this.$maxDate.attr('data-bv-date-max', 'TestSuite.Date.getDate()');
  3271. this.bv.destroy();
  3272. this.bv = $('#dateForm').bootstrapValidator().data('bootstrapValidator');
  3273. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3274. this.$date.val('2015/01/01');
  3275. this.$maxDate.val('2014/09/09');
  3276. this.bv.validate();
  3277. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3278. this.bv.resetForm();
  3279. this.$date.val('2014/01/01');
  3280. this.$maxDate.val('2014/08/17');
  3281. this.bv.validate();
  3282. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3283. });
  3284. it('dynamic max: callback programmatically', function() {
  3285. this.$maxDate.removeAttr('data-bv-date-max');
  3286. this.bv.destroy();
  3287. this.bv = $('#dateForm')
  3288. .bootstrapValidator({
  3289. fields: {
  3290. maxDate: {
  3291. validators: {
  3292. date: {
  3293. max: function(value, validator, $field) {
  3294. return getDate(value, validator, $field);
  3295. }
  3296. }
  3297. }
  3298. }
  3299. }
  3300. })
  3301. .data('bootstrapValidator');
  3302. this.bv.updateOption('maxDate', 'date', 'format', 'YYYY/MM/DD');
  3303. this.$date.val('2015/01/01');
  3304. this.$maxDate.val('2014/09/09');
  3305. this.bv.validate();
  3306. expect(this.bv.isValidField('maxDate')).toBeTruthy();
  3307. this.bv.resetForm();
  3308. this.$date.val('2014/01/01');
  3309. this.$maxDate.val('2014/08/17');
  3310. this.bv.validate();
  3311. expect(this.bv.isValidField('maxDate')).toBeFalsy();
  3312. });
  3313. });
  3314. describe('ean', function() {
  3315. beforeEach(function() {
  3316. var html = [
  3317. '<div class="container">',
  3318. '<form class="form-horizontal" id="eanForm">',
  3319. '<div class="form-group">',
  3320. '<input type="text" name="ean" data-bv-ean />',
  3321. '</div>',
  3322. '</form>',
  3323. '</div>'
  3324. ].join('\n');
  3325. $(html).appendTo('body');
  3326. $('#eanForm').bootstrapValidator();
  3327. this.bv = $('#eanForm').data('bootstrapValidator');
  3328. this.$ean = this.bv.getFieldElements('ean');
  3329. });
  3330. afterEach(function() {
  3331. $('#eanForm').bootstrapValidator('destroy').parent().remove();
  3332. });
  3333. it('valid', function() {
  3334. var samples = ['73513537', '9780471117094', '4006381333931'];
  3335. for (var i in samples) {
  3336. this.$ean.val(samples[i]);
  3337. this.bv.validate();
  3338. expect(this.bv.isValidField('ean')).toBeTruthy();
  3339. }
  3340. });
  3341. it('contains only digits', function() {
  3342. this.$ean.val('123abcDEF!@#');
  3343. this.bv.validate();
  3344. expect(this.bv.isValidField('ean')).toEqual(false);
  3345. });
  3346. it('invalid length', function() {
  3347. this.$ean.val('1234567');
  3348. this.bv.validate();
  3349. expect(this.bv.isValidField('ean')).toEqual(false);
  3350. });
  3351. it('invalid check digit', function() {
  3352. this.$ean.val('73513536');
  3353. this.bv.validate();
  3354. expect(this.bv.isValidField('ean')).toEqual(false);
  3355. });
  3356. });
  3357. describe('emailAddress', function() {
  3358. beforeEach(function() {
  3359. $([
  3360. '<form class="form-horizontal" id="emailAddressForm">',
  3361. '<div id="msg"></div>',
  3362. '<div class="form-group">',
  3363. '<input type="text" name="email-address-or-addresses" data-bv-emailaddress />',
  3364. '</div>',
  3365. '</form>'
  3366. ].join('\n')).appendTo('body');
  3367. $('#emailAddressForm').bootstrapValidator();
  3368. this.bv = $('#emailAddressForm').data('bootstrapValidator');
  3369. this.$emailAddressOrAddresses = this.bv.getFieldElements('email-address-or-addresses');
  3370. });
  3371. afterEach(function() {
  3372. $('#emailAddressForm').bootstrapValidator('destroy').remove();
  3373. });
  3374. var validEmailAddresses = [
  3375. 'admin@mailserver1',
  3376. 'niceandsimple@example.com',
  3377. 'very.common@example.com',
  3378. 'a.little.lengthy.but.fine@dept.example.com',
  3379. 'disposable.style.email.with+symbol@example.com',
  3380. 'other.email-with-dash@example.com',
  3381. '"much.more unusual"@example.com',
  3382. '"very.unusual.@.unusual.com"@example.com',
  3383. '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
  3384. '" "@example.org',
  3385. 'üñîçøðé@example.com'
  3386. ];
  3387. var invalidEmailAddresses = [
  3388. // "!#$%&'*+-/=?^_`{}|~@example.org", // This is actually passing validation; see https://github.com/nghuuphuoc/bootstrapvalidator/issues/673
  3389. 'üñîçøðé@üñîçøðé.com',
  3390. 'Abc.example.com',
  3391. 'A@b@c@example.com',
  3392. 'a"b(c)d,e:f;gi[j\k]l@example.com',
  3393. 'just"not"right@example.com',
  3394. 'this is"not\allowed@example.com',
  3395. 'this\ still\"not\\allowed@example.com'
  3396. ];
  3397. var validMultipleEmailAddressesForDefaultSeparators = [
  3398. 'niceandsimple@example.com,very.common@example.com',
  3399. 'niceandsimple@example.com;very.common@example.com',
  3400. 'niceandsimple@example.com;very.common@example.com,a.little.lengthy.but.fine@dept.example.com'
  3401. ];
  3402. var invalidMultipleEmailAddressesForDefaultSeparators = [
  3403. 'niceandsimple@example.com+very.common@example.com',
  3404. 'niceandsimple@example.com|very.common@example.com'
  3405. ];
  3406. var validMultipleEmailAddressesForCommaOrDollarSignSeparators = [
  3407. 'niceandsimple@example.com,very.common@example.com',
  3408. 'niceandsimple@example.com$very.common@example.com',
  3409. 'niceandsimple@example.com,very.common@example.com$a.little.lengthy.but.fine@dept.example.com'
  3410. ];
  3411. var invalidMultipleEmailAddressesForCommaOrDollarSignSeparators = [
  3412. 'niceandsimple@example.com;very.common@example.com',
  3413. 'niceandsimple@example.com;very.common@example.com,a.little.lengthy.but.fine@dept.example.com'
  3414. ];
  3415. it('Valid email addresses (multiple=false)', function() {
  3416. var that = this;
  3417. $.each(validEmailAddresses, function(index, emailAddress) {
  3418. that.bv.resetForm();
  3419. that.$emailAddressOrAddresses.val(emailAddress);
  3420. that.bv.validate();
  3421. expect(that.bv.isValid()).toBeTruthy();
  3422. });
  3423. });
  3424. it('Invalid email addresses (multiple=false)', function() {
  3425. var that = this;
  3426. var addresses = invalidEmailAddresses
  3427. .concat(validMultipleEmailAddressesForDefaultSeparators)
  3428. .concat(invalidMultipleEmailAddressesForDefaultSeparators)
  3429. .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators)
  3430. .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3431. $.each(addresses, function(index, emailAddress) {
  3432. that.bv.resetForm();
  3433. that.$emailAddressOrAddresses.val(emailAddress);
  3434. that.bv.validate();
  3435. expect(that.bv.isValid()).toEqual(false);
  3436. });
  3437. });
  3438. it('Invalid email addresses (multiple=false,separator=/[,\$]/)', function() {
  3439. var that = this;
  3440. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,;]/);
  3441. var addresses = invalidEmailAddresses
  3442. .concat(validMultipleEmailAddressesForDefaultSeparators)
  3443. .concat(invalidMultipleEmailAddressesForDefaultSeparators)
  3444. .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators)
  3445. .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3446. $.each(addresses, function(index, emailAddress) {
  3447. that.bv.resetForm();
  3448. that.$emailAddressOrAddresses.val(emailAddress);
  3449. that.bv.validate();
  3450. expect(that.bv.isValid()).toEqual(false);
  3451. });
  3452. });
  3453. it('Valid email addresses (multiple=true)', function() {
  3454. var that = this;
  3455. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3456. var addresses = validEmailAddresses
  3457. .concat(validMultipleEmailAddressesForDefaultSeparators);
  3458. $.each(addresses, function(index, emailAddress) {
  3459. that.bv.resetForm();
  3460. that.$emailAddressOrAddresses.val(emailAddress);
  3461. that.bv.validate();
  3462. expect(that.bv.isValid()).toBeTruthy();
  3463. });
  3464. });
  3465. it('Invalid email addresses (multiple=true)', function() {
  3466. var that = this;
  3467. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3468. var addresses = invalidEmailAddresses
  3469. .concat(invalidMultipleEmailAddressesForDefaultSeparators);
  3470. $.each(addresses, function(index, emailAddress) {
  3471. that.bv.resetForm();
  3472. that.$emailAddressOrAddresses.val(emailAddress);
  3473. that.bv.validate();
  3474. expect(that.bv.isValid()).toEqual(false);
  3475. });
  3476. });
  3477. it('Valid email addresses (multiple=true,separator=/[,\$]/)', function() {
  3478. var that = this;
  3479. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3480. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,\$]/);
  3481. var addresses = validEmailAddresses
  3482. .concat(validMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3483. $.each(addresses, function(index, emailAddress) {
  3484. that.bv.resetForm();
  3485. that.$emailAddressOrAddresses.val(emailAddress);
  3486. that.bv.validate();
  3487. expect(that.bv.isValid()).toBeTruthy();
  3488. });
  3489. });
  3490. it('Invalid email addresses (multiple=true,separator=/[,\$]/)', function() {
  3491. var that = this;
  3492. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'multiple', true);
  3493. that.bv.updateOption('email-address-or-addresses', 'emailAddress', 'separator', /[,\$]/);
  3494. var addresses = invalidEmailAddresses
  3495. .concat(invalidMultipleEmailAddressesForCommaOrDollarSignSeparators);
  3496. $.each(addresses, function(index, emailAddress) {
  3497. that.bv.resetForm();
  3498. that.$emailAddressOrAddresses.val(emailAddress);
  3499. that.bv.validate();
  3500. expect(that.bv.isValid()).toEqual(false);
  3501. });
  3502. });
  3503. });
  3504. function greaterThanCompare() {
  3505. var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
  3506. $('#msg').html('greaterThanCompare() called; compare to ' + compareTo);
  3507. return compareTo;
  3508. };
  3509. TestSuite = $.extend({}, TestSuite, {
  3510. greaterThan: {
  3511. compareTo: function(value, validator, $field) {
  3512. var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
  3513. $('#msg').html('TestSuite.greaterThan.compareTo() called; compare to ' + compareTo);
  3514. return compareTo;
  3515. }
  3516. }
  3517. });
  3518. describe('greaterThan', function() {
  3519. beforeEach(function() {
  3520. $([
  3521. '<form class="form-horizontal" id="greaterThanForm">',
  3522. '<div id="msg"></div>',
  3523. '<div class="form-group">',
  3524. '<input type="text" name="minAge" />',
  3525. '</div>',
  3526. '<div class="form-group">',
  3527. '<input type="text" name="age" data-bv-greaterthan data-bv-greaterthan-value="18" />',
  3528. '</div>',
  3529. '</form>'
  3530. ].join('\n')).appendTo('body');
  3531. $('#greaterThanForm').bootstrapValidator();
  3532. this.bv = $('#greaterThanForm').data('bootstrapValidator');
  3533. this.$minAge = this.bv.getFieldElements('minAge');
  3534. this.$age = this.bv.getFieldElements('age');
  3535. });
  3536. afterEach(function() {
  3537. $('#greaterThanForm').bootstrapValidator('destroy').remove();
  3538. });
  3539. it('not a number', function() {
  3540. this.$age.val('20abc');
  3541. this.bv.validate();
  3542. expect(this.bv.isValid()).toEqual(false);
  3543. });
  3544. it('compare to value', function() {
  3545. this.$age.val(10);
  3546. this.bv.validate();
  3547. expect(this.bv.isValid()).toEqual(false);
  3548. this.bv.resetForm();
  3549. this.$age.val(20);
  3550. this.bv.validate();
  3551. expect(this.bv.isValid()).toBeTruthy();
  3552. });
  3553. it('compare to other field', function() {
  3554. this.$age.attr('data-bv-greaterthan-value', 'minAge');
  3555. this.bv.destroy();
  3556. this.bv = $('#greaterThanForm').bootstrapValidator().data('bootstrapValidator');
  3557. this.$minAge.val(10);
  3558. this.$age.val(20);
  3559. this.bv.validate();
  3560. expect(this.bv.isValid()).toBeTruthy();
  3561. this.bv.resetForm();
  3562. this.$minAge.val(20);
  3563. this.$age.val(10);
  3564. this.bv.validate();
  3565. expect(this.bv.isValid()).toEqual(false);
  3566. expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
  3567. });
  3568. it('compare to return value of a function', function() {
  3569. this.$age.attr('data-bv-greaterthan-value', 'greaterThanCompare');
  3570. this.bv.destroy();
  3571. this.bv = $('#greaterThanForm').bootstrapValidator().data('bootstrapValidator');
  3572. this.$minAge.val(20);
  3573. this.$age.val(18);
  3574. this.bv.validate();
  3575. expect($('#msg').html()).toEqual('greaterThanCompare() called; compare to 20');
  3576. expect(this.bv.isValid()).toEqual(false);
  3577. expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
  3578. this.bv.resetForm();
  3579. this.$minAge.val(18);
  3580. this.$age.val(20);
  3581. this.bv.validate();
  3582. expect($('#msg').html()).toEqual('greaterThanCompare() called; compare to 18');
  3583. expect(this.bv.isValid()).toBeTruthy();
  3584. });
  3585. it('compare to return value of a namespace function', function() {
  3586. this.$age.attr('data-bv-greaterthan-value', 'TestSuite.greaterThan.compareTo');
  3587. this.bv.destroy();
  3588. this.bv = $('#greaterThanForm').bootstrapValidator().data('bootstrapValidator');
  3589. this.$minAge.val(20);
  3590. this.$age.val(18);
  3591. this.bv.validate();
  3592. expect($('#msg').html()).toEqual('TestSuite.greaterThan.compareTo() called; compare to 20');
  3593. expect(this.bv.isValid()).toEqual(false);
  3594. expect(this.bv.getMessages('age', 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.greaterThan['default'], this.$minAge.val()));
  3595. this.bv.resetForm();
  3596. this.$minAge.val(18);
  3597. this.$age.val(20);
  3598. this.bv.validate();
  3599. expect($('#msg').html()).toEqual('TestSuite.greaterThan.compareTo() called; compare to 18');
  3600. expect(this.bv.isValid()).toBeTruthy();
  3601. });
  3602. });
  3603. describe('hslColor', function() {
  3604. beforeEach(function() {
  3605. var html = [
  3606. '<div class="container">',
  3607. '<form class="form-horizontal" id="hslColorForm">',
  3608. '<div class="form-group">',
  3609. '<input type="text" name="hsl" data-bv-hslcolor />',
  3610. '</div>',
  3611. '</form>',
  3612. '</div>'
  3613. ].join('\n');
  3614. $(html).appendTo('body');
  3615. $('#hslColorForm').bootstrapValidator();
  3616. this.bv = $('#hslColorForm').data('bootstrapValidator');
  3617. this.$hslColor = this.bv.getFieldElements('hsl');
  3618. });
  3619. afterEach(function() {
  3620. $('#hslColorForm').bootstrapValidator('destroy').parent().remove();
  3621. });
  3622. it('accept hsl()', function() {
  3623. this.$hslColor.val('hsl(120,50%,50%)');
  3624. this.bv.validate();
  3625. expect(this.bv.isValidField('hsl')).toBeTruthy();
  3626. });
  3627. it('accept spaces around values', function() {
  3628. this.$hslColor.val('hsl( 120 , 50% , 50% )');
  3629. this.bv.validate();
  3630. expect(this.bv.isValidField('hsl')).toBeTruthy();
  3631. });
  3632. it('accept multiple spaces around values', function() {
  3633. this.$hslColor.val('hsl( 120, 50%, 50% )');
  3634. this.bv.validate();
  3635. expect(this.bv.isValidField('hsl')).toBeTruthy();
  3636. });
  3637. it('accept negative hue value', function() {
  3638. this.$hslColor.val('hsl(-120,50%,50%)');
  3639. this.bv.validate();
  3640. expect(this.bv.isValidField('hsl')).toBeTruthy();
  3641. });
  3642. it('accept hue values larger than 360', function() {
  3643. this.$hslColor.val('hsl(480,50%,50%)');
  3644. this.bv.validate();
  3645. expect(this.bv.isValidField('hsl')).toBeTruthy();
  3646. });
  3647. it('reject negative saturation value', function() {
  3648. this.$hslColor.val('hsl(10,-50%,50%)');
  3649. this.bv.validate();
  3650. expect(this.bv.isValidField('hsl')).toEqual(false);
  3651. });
  3652. it('reject negative lightness', function() {
  3653. this.$hslColor.val('hsl(10,50%,-50%)');
  3654. this.bv.validate();
  3655. expect(this.bv.isValidField('hsl')).toEqual(false);
  3656. });
  3657. it('require hsl()', function() {
  3658. this.$hslColor.val('120,50%,50%');
  3659. this.bv.validate();
  3660. expect(this.bv.isValidField('hsl')).toEqual(false);
  3661. });
  3662. it('reject percentages above 100%', function() {
  3663. this.$hslColor.val('hsl(120,100%,101%)');
  3664. this.bv.validate();
  3665. expect(this.bv.isValidField('hsl')).toEqual(false);
  3666. });
  3667. it('reject space between hsl and (', function() {
  3668. this.$hslColor.val('hsl (120,50%,50%)');
  3669. this.bv.validate();
  3670. expect(this.bv.isValidField('hsl')).toEqual(false);
  3671. });
  3672. it('reject leading space', function() {
  3673. this.$hslColor.val(' hsl(120,50%,50%)');
  3674. this.bv.validate();
  3675. expect(this.bv.isValidField('hsl')).toEqual(false);
  3676. });
  3677. it('reject trailing space', function() {
  3678. this.$hslColor.val('hsl(120,50%,50%) ');
  3679. this.bv.validate();
  3680. expect(this.bv.isValidField('hsl')).toEqual(false);
  3681. });
  3682. it('reject percentages in hue value', function() {
  3683. this.$hslColor.val('hsl(50%, 50%, 100%)');
  3684. this.bv.validate();
  3685. expect(this.bv.isValidField('hsl')).toEqual(false);
  3686. });
  3687. it('reject integers in saturation value', function() {
  3688. this.$hslColor.val('hsl(120, 50, 100%)');
  3689. this.bv.validate();
  3690. expect(this.bv.isValidField('hsl')).toEqual(false);
  3691. });
  3692. it('reject integers in lightness value', function() {
  3693. this.$hslColor.val('hsl(120, 50%, 100)');
  3694. this.bv.validate();
  3695. expect(this.bv.isValidField('hsl')).toEqual(false);
  3696. });
  3697. });
  3698. describe('hslaColor', function() {
  3699. beforeEach(function() {
  3700. var html = [
  3701. '<div class="container">',
  3702. '<form class="form-horizontal" id="hslaColorForm">',
  3703. '<div class="form-group">',
  3704. '<input type="text" name="hsla" data-bv-hslacolor />',
  3705. '</div>',
  3706. '</form>',
  3707. '</div>'
  3708. ].join('\n');
  3709. $(html).appendTo('body');
  3710. $('#hslaColorForm').bootstrapValidator();
  3711. this.bv = $('#hslaColorForm').data('bootstrapValidator');
  3712. this.$hslaColor = this.bv.getFieldElements('hsla');
  3713. });
  3714. afterEach(function() {
  3715. $('#hslaColorForm').bootstrapValidator('destroy').parent().remove();
  3716. });
  3717. it('accept hsla()', function() {
  3718. this.$hslaColor.val('hsla(120,50%,50%,1)');
  3719. this.bv.validate();
  3720. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3721. });
  3722. it('accept spaces around values', function() {
  3723. this.$hslaColor.val('hsla( 120 , 50% , 50%, 1 )');
  3724. this.bv.validate();
  3725. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3726. });
  3727. it('accept multiple spaces around values', function() {
  3728. this.$hslaColor.val('hsla( 120, 50%, 50% , 1 )');
  3729. this.bv.validate();
  3730. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3731. });
  3732. it('accept negative hue value', function() {
  3733. this.$hslaColor.val('hsla(-120,50%,50%,1)');
  3734. this.bv.validate();
  3735. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3736. });
  3737. it('accept hue values larger than 360', function() {
  3738. this.$hslaColor.val('hsla(480,50%,50%,1)');
  3739. this.bv.validate();
  3740. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3741. });
  3742. it('accept integer alpha channel value of 0', function() {
  3743. this.$hslaColor.val('hsla(120,50%,100%,0)');
  3744. this.bv.validate();
  3745. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3746. });
  3747. it('accept integer alpha channel value of 1', function() {
  3748. this.$hslaColor.val('hsla(120,50%,100%,1)');
  3749. this.bv.validate();
  3750. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3751. });
  3752. it('accept floating alpha channel with leading 0', function() {
  3753. this.$hslaColor.val('hsla(120,50%,100%,0.5)');
  3754. this.bv.validate();
  3755. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3756. });
  3757. it('accept floating alpha channel without leading 0', function() {
  3758. this.$hslaColor.val('hsla(120,50%,100%,.5)');
  3759. this.bv.validate();
  3760. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3761. });
  3762. it('accept floating alpha channel with more than 1 decimal place', function() {
  3763. this.$hslaColor.val('hsla(120,50%,100%,.524141)');
  3764. this.bv.validate();
  3765. expect(this.bv.isValidField('hsla')).toBeTruthy();
  3766. });
  3767. it('reject percentage value for alpha channel', function() {
  3768. this.$hslaColor.val('hsla(120,50%,100%,50%)');
  3769. this.bv.validate();
  3770. expect(this.bv.isValidField('hsla')).toEqual(false);
  3771. });
  3772. it('reject integers larger than 1 for alpha channel', function() {
  3773. this.$hslaColor.val('hsla(120,50%,100%,2)');
  3774. this.bv.validate();
  3775. expect(this.bv.isValidField('hsla')).toEqual(false);
  3776. });
  3777. it('reject negative integers for alpha channel', function() {
  3778. this.$hslaColor.val('hsla(120,50%,100%,-1)');
  3779. this.bv.validate();
  3780. expect(this.bv.isValidField('hsla')).toEqual(false);
  3781. });
  3782. it('reject floats larger than 1 for alpha channel', function() {
  3783. this.$hslaColor.val('hsla(120,50%,100%,1.000000000001)');
  3784. this.bv.validate();
  3785. expect(this.bv.isValidField('hsla')).toEqual(false);
  3786. });
  3787. it('reject negative floats for alpha channel', function() {
  3788. this.$hslaColor.val('hsla(120,50%,100%,-0.5)');
  3789. this.bv.validate();
  3790. expect(this.bv.isValidField('hsla')).toEqual(false);
  3791. });
  3792. it('reject more floats larger than 1 for alpha channel', function() {
  3793. this.$hslaColor.val('hsla(120,50%,100%,2.3)');
  3794. this.bv.validate();
  3795. expect(this.bv.isValidField('hsla')).toEqual(false);
  3796. });
  3797. it('reject negative saturation value', function() {
  3798. this.$hslaColor.val('hsla(10,-50%,50%,1)');
  3799. this.bv.validate();
  3800. expect(this.bv.isValidField('hsla')).toEqual(false);
  3801. });
  3802. it('reject negative lightness', function() {
  3803. this.$hslaColor.val('hsla(10,50%,-50%,1)');
  3804. this.bv.validate();
  3805. expect(this.bv.isValidField('hsla')).toEqual(false);
  3806. });
  3807. it('require hsla()', function() {
  3808. this.$hslaColor.val('120,50%,50%,1');
  3809. this.bv.validate();
  3810. expect(this.bv.isValidField('hsla')).toEqual(false);
  3811. });
  3812. it('reject percentages above 100%', function() {
  3813. this.$hslaColor.val('hsla(120,100%,101%,1)');
  3814. this.bv.validate();
  3815. expect(this.bv.isValidField('hsla')).toEqual(false);
  3816. });
  3817. it('reject space between hsla and (', function() {
  3818. this.$hslaColor.val('hsla (120,50%,50%,1)');
  3819. this.bv.validate();
  3820. expect(this.bv.isValidField('hsla')).toEqual(false);
  3821. });
  3822. it('reject leading space', function() {
  3823. this.$hslaColor.val(' hsla(120,50%,50%,1)');
  3824. this.bv.validate();
  3825. expect(this.bv.isValidField('hsla')).toEqual(false);
  3826. });
  3827. it('reject trailing space', function() {
  3828. this.$hslaColor.val('hsla(120,50%,50%,1) ');
  3829. this.bv.validate();
  3830. expect(this.bv.isValidField('hsla')).toEqual(false);
  3831. });
  3832. it('reject percentages in hue value', function() {
  3833. this.$hslaColor.val('hsla(50%, 50%, 100%,1)');
  3834. this.bv.validate();
  3835. expect(this.bv.isValidField('hsla')).toEqual(false);
  3836. });
  3837. it('reject integers in saturation value', function() {
  3838. this.$hslaColor.val('hsla(120, 50, 100%,1)');
  3839. this.bv.validate();
  3840. expect(this.bv.isValidField('hsla')).toEqual(false);
  3841. });
  3842. it('reject integers in lightness value', function() {
  3843. this.$hslaColor.val('hsla(120, 50%, 100,1)');
  3844. this.bv.validate();
  3845. expect(this.bv.isValidField('hsla')).toEqual(false);
  3846. });
  3847. });
  3848. describe('iban', function() {
  3849. beforeEach(function() {
  3850. $([
  3851. '<form class="form-horizontal" id="ibanForm">',
  3852. '<div class="form-group">',
  3853. '<select class="form-control" name="country">',
  3854. '<option value="AD">Andorra</option>',
  3855. '<option value="AE">United Arab Emirates</option>',
  3856. '<option value="AL">Albania</option>',
  3857. '<option value="AO">Angola</option>',
  3858. '<option value="AT">Austria</option>',
  3859. '<option value="AZ">Azerbaijan</option>',
  3860. '<option value="BA">Bosnia and Herzegovina</option>',
  3861. '<option value="BE">Belgium</option>',
  3862. '<option value="BF">Burkina Faso</option>',
  3863. '<option value="BG">Bulgaria</option>',
  3864. '<option value="BH">Bahrain</option>',
  3865. '<option value="BI">Burundi</option>',
  3866. '<option value="BJ">Benin</option>',
  3867. '<option value="BR">Brazil</option>',
  3868. '<option value="CH">Switzerland</option>',
  3869. '<option value="CM">Cameroon</option>',
  3870. '<option value="CR">Costa Rica</option>',
  3871. '<option value="CV">Cape Verde</option>',
  3872. '<option value="CY">Cyprus</option>',
  3873. '<option value="CZ">Czech Republic</option>',
  3874. '<option value="DE">Germany</option>',
  3875. '<option value="DK">Denmark</option>',
  3876. '<option value="DO">Dominican Republic</option>',
  3877. '<option value="DZ">Algeria</option>',
  3878. '<option value="EE">Estonia</option>',
  3879. '<option value="ES">Spain</option>',
  3880. '<option value="FI">Finland</option>',
  3881. '<option value="FO">Faroe Islands</option>',
  3882. '<option value="FR">France</option>',
  3883. '<option value="GB">United Kingdom</option>',
  3884. '<option value="GE">Georgia</option>',
  3885. '<option value="GI">Gibraltar</option>',
  3886. '<option value="GL">Greenland</option>',
  3887. '<option value="GR">Greece</option>',
  3888. '<option value="GT">Guatemala</option>',
  3889. '<option value="HR">Croatia</option>',
  3890. '<option value="HU">Hungary</option>',
  3891. '<option value="IE">Ireland</option>',
  3892. '<option value="IL">Israel</option>',
  3893. '<option value="IR">Iran</option>',
  3894. '<option value="IS">Iceland</option>',
  3895. '<option value="IT">Italy</option>',
  3896. '<option value="JO">Jordan</option>',
  3897. '<option value="KW">Kuwait</option>',
  3898. '<option value="KZ">Kazakhstan</option>',
  3899. '<option value="LB">Lebanon</option>',
  3900. '<option value="LI">Liechtenstein</option>',
  3901. '<option value="LT">Lithuania</option>',
  3902. '<option value="LU">Luxembourg</option>',
  3903. '<option value="LV">Latvia</option>',
  3904. '<option value="MC">Monaco</option>',
  3905. '<option value="MD">Moldova</option>',
  3906. '<option value="ME">Montenegro</option>',
  3907. '<option value="MG">Madagascar</option>',
  3908. '<option value="MK">Macedonia</option>',
  3909. '<option value="ML">Mali</option>',
  3910. '<option value="MR">Mauritania</option>',
  3911. '<option value="MT">Malta</option>',
  3912. '<option value="MU">Mauritius</option>',
  3913. '<option value="MZ">Mozambique</option>',
  3914. '<option value="NL">Netherlands</option>',
  3915. '<option value="NO">Norway</option>',
  3916. '<option value="PK">Pakistan</option>',
  3917. '<option value="PL">Poland</option>',
  3918. '<option value="PS">Palestinian</option>',
  3919. '<option value="PT">Portugal</option>',
  3920. '<option value="QA">Qatar</option>',
  3921. '<option value="RO">Romania</option>',
  3922. '<option value="RS">Serbia</option>',
  3923. '<option value="SA">Saudi Arabia</option>',
  3924. '<option value="SE">Sweden</option>',
  3925. '<option value="SE">Slovenia</option>',
  3926. '<option value="SK">Slovakia</option>',
  3927. '<option value="SM">San Marino</option>',
  3928. '<option value="SN">Senegal</option>',
  3929. '<option value="TN">Tunisia</option>',
  3930. '<option value="TR">Turkey</option>',
  3931. '<option value="VG">Virgin Islands, British</option>',
  3932. '</select>',
  3933. '</div>',
  3934. '<div class="form-group">',
  3935. '<input type="text" name="iban" data-bv-iban />',
  3936. '</div>',
  3937. '</form>'
  3938. ].join('\n')).appendTo('body');
  3939. $('#ibanForm').bootstrapValidator();
  3940. this.bv = $('#ibanForm').data('bootstrapValidator');
  3941. this.$country = this.bv.getFieldElements('country');
  3942. this.$iban = this.bv.getFieldElements('iban');
  3943. });
  3944. afterEach(function() {
  3945. $('#ibanForm').bootstrapValidator('destroy').remove();
  3946. });
  3947. it('not supported country', function() {
  3948. this.$iban.val('US123456789');
  3949. this.bv.validate();
  3950. expect(this.bv.isValidField('iban')).toEqual(false);
  3951. });
  3952. it('dynamic country', function() {
  3953. this.$iban.attr('data-bv-iban-country', 'country');
  3954. this.bv.destroy();
  3955. this.bv = $('#ibanForm').bootstrapValidator().data('bootstrapValidator');
  3956. this.$country.val('AT');
  3957. this.$iban.val('AT611904300234573201');
  3958. this.bv.validate();
  3959. expect(this.bv.isValid()).toBeTruthy();
  3960. this.bv.resetForm();
  3961. this.$country.val('BG');
  3962. this.$iban.val('HR1210010051863000160');
  3963. this.bv.validate();
  3964. expect(this.bv.isValid()).toEqual(false);
  3965. });
  3966. it('Albania', function() {
  3967. this.$iban.val('AL47212110090000000235698741');
  3968. this.bv.validate();
  3969. expect(this.bv.isValidField('iban')).toBeTruthy();
  3970. });
  3971. it('Algeria', function() {
  3972. this.$iban.val('DZ4000400174401001050486');
  3973. this.bv.validate();
  3974. expect(this.bv.isValidField('iban')).toBeTruthy();
  3975. });
  3976. it('Andorra', function() {
  3977. this.$iban.val('AD1200012030200359100100');
  3978. this.bv.validate();
  3979. expect(this.bv.isValidField('iban')).toBeTruthy();
  3980. });
  3981. it('Angola', function() {
  3982. this.$iban.val('AO06000600000100037131174');
  3983. this.bv.validate();
  3984. expect(this.bv.isValidField('iban')).toBeTruthy();
  3985. });
  3986. it('Austria', function() {
  3987. this.$iban.val('AT611904300234573201');
  3988. this.bv.validate();
  3989. expect(this.bv.isValidField('iban')).toBeTruthy();
  3990. });
  3991. it('Azerbaijan', function() {
  3992. this.$iban.val('AZ21NABZ00000000137010001944');
  3993. this.bv.validate();
  3994. expect(this.bv.isValidField('iban')).toBeTruthy();
  3995. });
  3996. it('Bahrain', function() {
  3997. this.$iban.val('BH29BMAG1299123456BH00');
  3998. this.bv.validate();
  3999. expect(this.bv.isValidField('iban')).toBeTruthy();
  4000. });
  4001. it('Belgium', function() {
  4002. this.$iban.val('BE68539007547034');
  4003. this.bv.validate();
  4004. expect(this.bv.isValidField('iban')).toBeTruthy();
  4005. });
  4006. it('Benin', function() {
  4007. this.$iban.val('BJ11B00610100400271101192591');
  4008. this.bv.validate();
  4009. expect(this.bv.isValidField('iban')).toBeTruthy();
  4010. });
  4011. it('Brazil', function() {
  4012. this.$iban.val('BR9700360305000010009795493P1');
  4013. this.bv.validate();
  4014. expect(this.bv.isValidField('iban')).toBeTruthy();
  4015. });
  4016. it('Bulgaria', function() {
  4017. this.$iban.val('BG80BNBG96611020345678');
  4018. this.bv.validate();
  4019. expect(this.bv.isValidField('iban')).toBeTruthy();
  4020. });
  4021. it('Burkina Faso', function() {
  4022. this.$iban.val('BF1030134020015400945000643');
  4023. this.bv.validate();
  4024. expect(this.bv.isValidField('iban')).toBeTruthy();
  4025. });
  4026. it('Burundi', function() {
  4027. this.$iban.val('BI43201011067444');
  4028. this.bv.validate();
  4029. expect(this.bv.isValidField('iban')).toBeTruthy();
  4030. });
  4031. it('Cameroon', function() {
  4032. this.$iban.val('CM2110003001000500000605306');
  4033. this.bv.validate();
  4034. expect(this.bv.isValidField('iban')).toBeTruthy();
  4035. });
  4036. it('Cape Verde', function() {
  4037. this.$iban.val('CV64000300004547069110176');
  4038. this.bv.validate();
  4039. expect(this.bv.isValidField('iban')).toBeTruthy();
  4040. });
  4041. it('Costa Rica', function() {
  4042. this.$iban.val('CR0515202001026284066');
  4043. this.bv.validate();
  4044. expect(this.bv.isValidField('iban')).toBeTruthy();
  4045. });
  4046. it('Croatia', function() {
  4047. this.$iban.val('HR1210010051863000160');
  4048. this.bv.validate();
  4049. expect(this.bv.isValidField('iban')).toBeTruthy();
  4050. });
  4051. it('Cyprus', function() {
  4052. this.$iban.val('CY17002001280000001200527600');
  4053. this.bv.validate();
  4054. expect(this.bv.isValidField('iban')).toBeTruthy();
  4055. });
  4056. it('Czech Republic', function() {
  4057. this.$iban.val('CZ6508000000192000145399');
  4058. this.bv.validate();
  4059. expect(this.bv.isValidField('iban')).toBeTruthy();
  4060. });
  4061. it('Denmark', function() {
  4062. this.$iban.val('DK5000400440116243');
  4063. this.bv.validate();
  4064. expect(this.bv.isValidField('iban')).toBeTruthy();
  4065. });
  4066. it('Dominican Republic', function() {
  4067. this.$iban.val('DO28BAGR00000001212453611324');
  4068. this.bv.validate();
  4069. expect(this.bv.isValidField('iban')).toBeTruthy();
  4070. });
  4071. it('Estonia', function() {
  4072. this.$iban.val('EE382200221020145685');
  4073. this.bv.validate();
  4074. expect(this.bv.isValidField('iban')).toBeTruthy();
  4075. });
  4076. it('Faroe Islands', function() {
  4077. this.$iban.val('FO1464600009692713');
  4078. this.bv.validate();
  4079. expect(this.bv.isValidField('iban')).toBeTruthy();
  4080. });
  4081. it('Finland', function() {
  4082. this.$iban.val('FI2112345600000785');
  4083. this.bv.validate();
  4084. expect(this.bv.isValidField('iban')).toBeTruthy();
  4085. });
  4086. it('France', function() {
  4087. this.$iban.val('FR1420041010050500013M02606');
  4088. this.bv.validate();
  4089. expect(this.bv.isValidField('iban')).toBeTruthy();
  4090. });
  4091. it('Guatemala', function() {
  4092. this.$iban.val('GT82TRAJ01020000001210029690');
  4093. this.bv.validate();
  4094. expect(this.bv.isValidField('iban')).toBeTruthy();
  4095. });
  4096. it('Georgia', function() {
  4097. this.$iban.val('GE29NB0000000101904917');
  4098. this.bv.validate();
  4099. expect(this.bv.isValidField('iban')).toBeTruthy();
  4100. });
  4101. it('Germany', function() {
  4102. this.$iban.val('DE89370400440532013000');
  4103. this.bv.validate();
  4104. expect(this.bv.isValidField('iban')).toBeTruthy();
  4105. });
  4106. it('Gibraltar', function() {
  4107. this.$iban.val('GI75NWBK000000007099453');
  4108. this.bv.validate();
  4109. expect(this.bv.isValidField('iban')).toBeTruthy();
  4110. });
  4111. it('Greece', function() {
  4112. this.$iban.val('GR1601101250000000012300695');
  4113. this.bv.validate();
  4114. expect(this.bv.isValidField('iban')).toBeTruthy();
  4115. });
  4116. it('Greenland', function() {
  4117. this.$iban.val('GL8964710001000206');
  4118. this.bv.validate();
  4119. expect(this.bv.isValidField('iban')).toBeTruthy();
  4120. });
  4121. it('Hungary', function() {
  4122. this.$iban.val('HU42117730161111101800000000');
  4123. this.bv.validate();
  4124. expect(this.bv.isValidField('iban')).toBeTruthy();
  4125. });
  4126. it('Iceland', function() {
  4127. this.$iban.val('IS140159260076545510730339');
  4128. this.bv.validate();
  4129. expect(this.bv.isValidField('iban')).toBeTruthy();
  4130. });
  4131. it('Iran', function() {
  4132. this.$iban.val('IR580540105180021273113007');
  4133. this.bv.validate();
  4134. expect(this.bv.isValidField('iban')).toBeTruthy();
  4135. });
  4136. it('Ireland', function() {
  4137. this.$iban.val('IE29AIBK93115212345678');
  4138. this.bv.validate();
  4139. expect(this.bv.isValidField('iban')).toBeTruthy();
  4140. });
  4141. it('Israel', function() {
  4142. this.$iban.val('IL620108000000099999999');
  4143. this.bv.validate();
  4144. expect(this.bv.isValidField('iban')).toBeTruthy();
  4145. });
  4146. it('Italy', function() {
  4147. this.$iban.val('IT60X0542811101000000123456');
  4148. this.bv.validate();
  4149. expect(this.bv.isValidField('iban')).toBeTruthy();
  4150. });
  4151. it('Ivory Coast', function() {
  4152. this.$iban.val('CI05A00060174100178530011852');
  4153. this.bv.validate();
  4154. expect(this.bv.isValidField('iban')).toBeTruthy();
  4155. });
  4156. it('Jordan', function() {
  4157. this.$iban.val('JO94CBJO0010000000000131000302');
  4158. this.bv.validate();
  4159. expect(this.bv.isValidField('iban')).toBeTruthy();
  4160. });
  4161. it('Kazakhstan', function() {
  4162. this.$iban.val('KZ176010251000042993');
  4163. this.bv.validate();
  4164. expect(this.bv.isValidField('iban')).toBeTruthy();
  4165. });
  4166. it('Kuwait', function() {
  4167. this.$iban.val('KW74NBOK0000000000001000372151');
  4168. this.bv.validate();
  4169. expect(this.bv.isValidField('iban')).toBeTruthy();
  4170. });
  4171. it('Latvia', function() {
  4172. this.$iban.val('LV80BANK0000435195001');
  4173. this.bv.validate();
  4174. expect(this.bv.isValidField('iban')).toBeTruthy();
  4175. });
  4176. it('Lebanon', function() {
  4177. this.$iban.val('LB30099900000001001925579115');
  4178. this.bv.validate();
  4179. expect(this.bv.isValidField('iban')).toBeTruthy();
  4180. });
  4181. it('Liechtenstein', function() {
  4182. this.$iban.val('LI21088100002324013AA');
  4183. this.bv.validate();
  4184. expect(this.bv.isValidField('iban')).toBeTruthy();
  4185. });
  4186. it('Lithuania', function() {
  4187. this.$iban.val('LT121000011101001000');
  4188. this.bv.validate();
  4189. expect(this.bv.isValidField('iban')).toBeTruthy();
  4190. });
  4191. it('Luxembourg', function() {
  4192. this.$iban.val('LU280019400644750000');
  4193. this.bv.validate();
  4194. expect(this.bv.isValidField('iban')).toBeTruthy();
  4195. });
  4196. it('Macedonia', function() {
  4197. this.$iban.val('MK07300000000042425');
  4198. this.bv.validate();
  4199. expect(this.bv.isValidField('iban')).toBeTruthy();
  4200. });
  4201. it('Madagascar', function() {
  4202. this.$iban.val('MG4600005030010101914016056');
  4203. this.bv.validate();
  4204. expect(this.bv.isValidField('iban')).toBeTruthy();
  4205. });
  4206. it('Malta', function() {
  4207. this.$iban.val('MT84MALT011000012345MTLCAST001S');
  4208. this.bv.validate();
  4209. expect(this.bv.isValidField('iban')).toBeTruthy();
  4210. });
  4211. it('Mauritania', function() {
  4212. this.$iban.val('MR1300012000010000002037372');
  4213. this.bv.validate();
  4214. expect(this.bv.isValidField('iban')).toBeTruthy();
  4215. });
  4216. it('Mauritius', function() {
  4217. this.$iban.val('MU17BOMM0101101030300200000MUR');
  4218. this.bv.validate();
  4219. expect(this.bv.isValidField('iban')).toBeTruthy();
  4220. });
  4221. it('Mali', function() {
  4222. this.$iban.val('ML03D00890170001002120000447');
  4223. this.bv.validate();
  4224. expect(this.bv.isValidField('iban')).toBeTruthy();
  4225. });
  4226. it('Moldova', function() {
  4227. this.$iban.val('MD24AG000225100013104168');
  4228. this.bv.validate();
  4229. expect(this.bv.isValidField('iban')).toBeTruthy();
  4230. });
  4231. it('Monaco', function() {
  4232. this.$iban.val('MC5813488000010051108001292');
  4233. this.bv.validate();
  4234. expect(this.bv.isValidField('iban')).toBeTruthy();
  4235. });
  4236. it('Montenegro', function() {
  4237. this.$iban.val('ME25505000012345678951');
  4238. this.bv.validate();
  4239. expect(this.bv.isValidField('iban')).toBeTruthy();
  4240. });
  4241. it('Mozambique', function() {
  4242. this.$iban.val('MZ59000100000011834194157');
  4243. this.bv.validate();
  4244. expect(this.bv.isValidField('iban')).toBeTruthy();
  4245. });
  4246. it('Netherlands', function() {
  4247. this.$iban.val('NL91ABNA0417164300');
  4248. this.bv.validate();
  4249. expect(this.bv.isValidField('iban')).toBeTruthy();
  4250. });
  4251. it('Norway', function() {
  4252. this.$iban.val('NO9386011117947');
  4253. this.bv.validate();
  4254. expect(this.bv.isValidField('iban')).toBeTruthy();
  4255. });
  4256. it('Pakistan', function() {
  4257. this.$iban.val('PK24SCBL0000001171495101');
  4258. this.bv.validate();
  4259. expect(this.bv.isValidField('iban')).toBeTruthy();
  4260. });
  4261. it('Palestine', function() {
  4262. this.$iban.val('PS92PALS000000000400123456702');
  4263. this.bv.validate();
  4264. expect(this.bv.isValidField('iban')).toBeTruthy();
  4265. });
  4266. it('Poland', function() {
  4267. this.$iban.val('PL27114020040000300201355387');
  4268. this.bv.validate();
  4269. expect(this.bv.isValidField('iban')).toBeTruthy();
  4270. });
  4271. it('Portugal', function() {
  4272. this.$iban.val('PT50000201231234567890154');
  4273. this.bv.validate();
  4274. expect(this.bv.isValidField('iban')).toBeTruthy();
  4275. });
  4276. it('Qatar', function() {
  4277. this.$iban.val('QA58DOHB00001234567890ABCDEFG');
  4278. this.bv.validate();
  4279. expect(this.bv.isValidField('iban')).toBeTruthy();
  4280. });
  4281. it('Romania', function() {
  4282. this.$iban.val('RO49AAAA1B31007593840000');
  4283. this.bv.validate();
  4284. expect(this.bv.isValidField('iban')).toBeTruthy();
  4285. });
  4286. it('San Marino', function() {
  4287. this.$iban.val('SM86U0322509800000000270100');
  4288. this.bv.validate();
  4289. expect(this.bv.isValidField('iban')).toBeTruthy();
  4290. });
  4291. it('Saudi Arabia', function() {
  4292. this.$iban.val('SA0380000000608010167519');
  4293. this.bv.validate();
  4294. expect(this.bv.isValidField('iban')).toBeTruthy();
  4295. });
  4296. it('Senegal', function() {
  4297. this.$iban.val('SN12K00100152000025690007542');
  4298. this.bv.validate();
  4299. expect(this.bv.isValidField('iban')).toBeTruthy();
  4300. });
  4301. it('Serbia', function() {
  4302. this.$iban.val('RS35260005601001611379');
  4303. this.bv.validate();
  4304. expect(this.bv.isValidField('iban')).toBeTruthy();
  4305. });
  4306. it('Slovakia', function() {
  4307. this.$iban.val('SK3112000000198742637541');
  4308. this.bv.validate();
  4309. expect(this.bv.isValidField('iban')).toBeTruthy();
  4310. });
  4311. it('Slovenia', function() {
  4312. this.$iban.val('SI56191000000123438');
  4313. this.bv.validate();
  4314. expect(this.bv.isValidField('iban')).toBeTruthy();
  4315. });
  4316. it('Spain', function() {
  4317. this.$iban.val('ES9121000418450200051332');
  4318. this.bv.validate();
  4319. expect(this.bv.isValidField('iban')).toBeTruthy();
  4320. });
  4321. it('Sweden', function() {
  4322. this.$iban.val('SE3550000000054910000003');
  4323. this.bv.validate();
  4324. expect(this.bv.isValidField('iban')).toBeTruthy();
  4325. });
  4326. it('Switzerland', function() {
  4327. this.$iban.val('CH9300762011623852957');
  4328. this.bv.validate();
  4329. expect(this.bv.isValidField('iban')).toBeTruthy();
  4330. });
  4331. it('Tunisia', function() {
  4332. this.$iban.val('TN5914207207100707129648');
  4333. this.bv.validate();
  4334. expect(this.bv.isValidField('iban')).toBeTruthy();
  4335. });
  4336. it('Turkey', function() {
  4337. this.$iban.val('TR330006100519786457841326');
  4338. this.bv.validate();
  4339. expect(this.bv.isValidField('iban')).toBeTruthy();
  4340. });
  4341. it('United Arab Emirates', function() {
  4342. this.$iban.val('AE260211000000230064016');
  4343. this.bv.validate();
  4344. expect(this.bv.isValidField('iban')).toBeTruthy();
  4345. });
  4346. it('United Kingdom', function() {
  4347. this.$iban.val('GB29NWBK60161331926819');
  4348. this.bv.validate();
  4349. expect(this.bv.isValidField('iban')).toBeTruthy();
  4350. });
  4351. it('Virgin Islands, British', function() {
  4352. this.$iban.val('VG96VPVG0000012345678901');
  4353. this.bv.validate();
  4354. expect(this.bv.isValidField('iban')).toBeTruthy();
  4355. });
  4356. it('invalid checksum', function() {
  4357. this.$iban.val('TR330006100519786457841325');
  4358. this.bv.validate();
  4359. expect(this.bv.isValidField('iban')).toEqual(false);
  4360. });
  4361. });
  4362. describe('id', function() {
  4363. beforeEach(function() {
  4364. $([
  4365. '<form class="form-horizontal" id="idForm">',
  4366. '<div class="form-group">',
  4367. '<select class="form-control" name="country">',
  4368. '<option value="BA">Bosnia and Herzegovina</option>',
  4369. '<option value="BG">Bulgaria</option>',
  4370. '<option value="BR">Brazil</option>',
  4371. '<option value="CH">Switzerland</option>',
  4372. '<option value="CL">Chile</option>',
  4373. '<option value="CN">China</option>',
  4374. '<option value="CZ">Czech</option>',
  4375. '<option value="DK">Denmark</option>',
  4376. '<option value="EE">Estonia</option>',
  4377. '<option value="ES">Spain</option>',
  4378. '<option value="FI">Finland</option>',
  4379. '<option value="HR">Croatia</option>',
  4380. '<option value="IE">Ireland</option>',
  4381. '<option value="IS">Iceland</option>',
  4382. '<option value="LT">Lithuania</option>',
  4383. '<option value="LV">Latvia</option>',
  4384. '<option value="ME">Montenegro</option>',
  4385. '<option value="MK">Macedonia</option>',
  4386. '<option value="NL">Netherlands</option>',
  4387. '<option value="RO">Romania</option>',
  4388. '<option value="RS">Serbia</option>',
  4389. '<option value="SE">Sweden</option>',
  4390. '<option value="SI">Slovenia</option>',
  4391. '<option value="SK">Slovakia</option>',
  4392. '<option value="SM">San Marino</option>',
  4393. '<option value="TH">Thailand</option>',
  4394. '<option value="ZA">South Africa</option>',
  4395. '</select>',
  4396. '</div>',
  4397. '<div class="form-group">',
  4398. '<input class="form-control" type="text" name="id" data-bv-id />',
  4399. '</div>',
  4400. '</form>'
  4401. ].join('\n')).appendTo('body');
  4402. $('#idForm').bootstrapValidator();
  4403. /**
  4404. * @type {BootstrapValidator}
  4405. */
  4406. this.bv = $('#idForm').data('bootstrapValidator');
  4407. this.$country = this.bv.getFieldElements('country');
  4408. this.$id = this.bv.getFieldElements('id');
  4409. });
  4410. afterEach(function() {
  4411. $('#idForm').bootstrapValidator('destroy').remove();
  4412. });
  4413. it('dynamic country', function() {
  4414. this.$id.attr('data-bv-id-country', 'country');
  4415. this.bv.destroy();
  4416. this.bv = $('#idForm').bootstrapValidator().data('bootstrapValidator');
  4417. this.$country.val('BG');
  4418. this.$id.val('7552010005');
  4419. this.bv.validate();
  4420. expect(this.bv.isValid()).toBeTruthy();
  4421. this.bv.resetForm();
  4422. this.$country.val('BR');
  4423. this.$id.val('231.002.999-00');
  4424. this.bv.validate();
  4425. expect(this.bv.isValid()).toEqual(false);
  4426. });
  4427. it('Bulgarian national identification number (EGN)', function() {
  4428. this.bv.updateOption('id', 'id', 'country', 'BG');
  4429. // Valid samples
  4430. var validSamples = ['7523169263', '8032056031', '803205 603 1', '8001010008', '7501020018', '7552010005', '7542011030'];
  4431. for (var i in validSamples) {
  4432. this.bv.resetForm();
  4433. this.$id.val(validSamples[i]);
  4434. this.bv.validate();
  4435. expect(this.bv.isValid()).toBeTruthy();
  4436. }
  4437. // Invalid samples
  4438. var invalidSamples = ['8019010008'];
  4439. for (i in invalidSamples) {
  4440. this.bv.resetForm();
  4441. this.$id.val(invalidSamples[i]);
  4442. this.bv.validate();
  4443. expect(this.bv.isValid()).toEqual(false);
  4444. }
  4445. });
  4446. it('Brazilian national identification number (CPF)', function() {
  4447. this.bv.updateOption('id', 'id', 'country', 'BR');
  4448. // Valid samples
  4449. var validSamples = ['39053344705', '390.533.447-05', '111.444.777-35'];
  4450. for (var i in validSamples) {
  4451. this.bv.resetForm();
  4452. this.$id.val(validSamples[i]);
  4453. this.bv.validate();
  4454. expect(this.bv.isValid()).toBeTruthy();
  4455. }
  4456. // Invalid samples
  4457. var invalidSamples = ['231.002.999-00'];
  4458. for (i in invalidSamples) {
  4459. this.bv.resetForm();
  4460. this.$id.val(invalidSamples[i]);
  4461. this.bv.validate();
  4462. expect(this.bv.isValid()).toEqual(false);
  4463. }
  4464. });
  4465. it('Swiss Social Security Number (AHV-Nr/No AVS)', function() {
  4466. this.bv.updateOption('id', 'id', 'country', 'CH');
  4467. // Valid samples
  4468. var validSamples = ['756.1234.5678.95', '7561234567895'];
  4469. for (var i in validSamples) {
  4470. this.bv.resetForm();
  4471. this.$id.val(validSamples[i]);
  4472. this.bv.validate();
  4473. expect(this.bv.isValid()).toBeTruthy();
  4474. }
  4475. });
  4476. it('Chilean national identification number (RUN/RUT)', function() {
  4477. this.bv.updateOption('id', 'id', 'country', 'CL');
  4478. // Valid samples
  4479. var validSamples = ['76086428-5', '22060449-7', '12531909-2','12937893-K','12937893-k'];
  4480. for (var i in validSamples) {
  4481. this.bv.resetForm();
  4482. this.$id.val(validSamples[i]);
  4483. this.bv.validate();
  4484. expect(this.bv.isValid()).toBeTruthy();
  4485. }
  4486. });
  4487. // #793
  4488. it('Chinese citizen identification number', function() {
  4489. this.bv.updateOption('id', 'id', 'country', 'CN');
  4490. // Valid samples
  4491. var validSamples = ['450202201409072332', '22011219930407001X', '110108601017023'];
  4492. for (var i in validSamples) {
  4493. this.bv.resetForm();
  4494. this.$id.val(validSamples[i]);
  4495. this.bv.validate();
  4496. expect(this.bv.isValid()).toBeTruthy();
  4497. }
  4498. // Invalid samples
  4499. var invalidSamples = ['999999199304070016', '220112190002290016', '220112199304070019', '999999601017023', '110108999999023'];
  4500. for (i in invalidSamples) {
  4501. this.bv.resetForm();
  4502. this.$id.val(invalidSamples[i]);
  4503. this.bv.validate();
  4504. expect(this.bv.isValid()).toEqual(false);
  4505. }
  4506. });
  4507. it('Czech national identification number (RC)', function() {
  4508. this.bv.updateOption('id', 'id', 'country', 'CZ');
  4509. // Valid samples
  4510. var validSamples = ['7103192745', '991231123'];
  4511. for (var i in validSamples) {
  4512. this.bv.resetForm();
  4513. this.$id.val(validSamples[i]);
  4514. this.bv.validate();
  4515. expect(this.bv.isValid()).toBeTruthy();
  4516. }
  4517. // Invalid samples
  4518. var invalidSamples = ['1103492745', '590312123'];
  4519. for (i in invalidSamples) {
  4520. this.bv.resetForm();
  4521. this.$id.val(invalidSamples[i]);
  4522. this.bv.validate();
  4523. expect(this.bv.isValid()).toEqual(false);
  4524. }
  4525. });
  4526. it('Danish Personal Identification number (CPR)', function() {
  4527. this.bv.updateOption('id', 'id', 'country', 'DK');
  4528. // Valid samples
  4529. var validSamples = ['2110625629', '211062-5629'];
  4530. for (var i in validSamples) {
  4531. this.bv.resetForm();
  4532. this.$id.val(validSamples[i]);
  4533. this.bv.validate();
  4534. expect(this.bv.isValid()).toBeTruthy();
  4535. }
  4536. // Invalid samples
  4537. var invalidSamples = ['511062-5629'];
  4538. for (i in invalidSamples) {
  4539. this.bv.resetForm();
  4540. this.$id.val(invalidSamples[i]);
  4541. this.bv.validate();
  4542. expect(this.bv.isValid()).toEqual(false);
  4543. }
  4544. });
  4545. it('Estonian Personal Identification Code (isikukood)', function() {
  4546. this.bv.updateOption('id', 'id', 'country', 'EE');
  4547. // Valid samples
  4548. var validSamples = ['37605030299'];
  4549. for (var i in validSamples) {
  4550. this.bv.resetForm();
  4551. this.$id.val(validSamples[i]);
  4552. this.bv.validate();
  4553. expect(this.bv.isValid()).toBeTruthy();
  4554. }
  4555. });
  4556. it('Spanish personal identity code (DNI/NIE)', function() {
  4557. this.bv.updateOption('id', 'id', 'country', 'ES');
  4558. // Valid samples
  4559. var validSamples = ['54362315K', '54362315-K', 'X2482300W', 'X-2482300W', 'X-2482300-W'];
  4560. for (var i in validSamples) {
  4561. this.bv.resetForm();
  4562. this.$id.val(validSamples[i]);
  4563. this.bv.validate();
  4564. expect(this.bv.isValid()).toBeTruthy();
  4565. }
  4566. // Invalid samples
  4567. var invalidSamples = ['54362315Z', 'X-2482300A'];
  4568. for (i in invalidSamples) {
  4569. this.bv.resetForm();
  4570. this.$id.val(invalidSamples[i]);
  4571. this.bv.validate();
  4572. expect(this.bv.isValid()).toEqual(false);
  4573. }
  4574. });
  4575. it('Finnish Personal Identity Code (HETU)', function() {
  4576. this.bv.updateOption('id', 'id', 'country', 'FI');
  4577. // Valid samples
  4578. var validSamples = ['311280-888Y', '131052-308T'];
  4579. for (var i in validSamples) {
  4580. this.bv.resetForm();
  4581. this.$id.val(validSamples[i]);
  4582. this.bv.validate();
  4583. expect(this.bv.isValid()).toBeTruthy();
  4584. }
  4585. // Invalid samples
  4586. var invalidSamples = ['131052-308U', '310252-308Y'];
  4587. for (i in invalidSamples) {
  4588. this.bv.resetForm();
  4589. this.$id.val(invalidSamples[i]);
  4590. this.bv.validate();
  4591. expect(this.bv.isValid()).toEqual(false);
  4592. }
  4593. });
  4594. it('Croatian personal identification number (OIB)', function() {
  4595. this.bv.updateOption('id', 'id', 'country', 'HR');
  4596. // Valid samples
  4597. var validSamples = ['33392005961'];
  4598. for (var i in validSamples) {
  4599. this.bv.resetForm();
  4600. this.$id.val(validSamples[i]);
  4601. this.bv.validate();
  4602. expect(this.bv.isValid()).toBeTruthy();
  4603. }
  4604. // Invalid samples
  4605. var invalidSamples = ['33392005962'];
  4606. for (i in invalidSamples) {
  4607. this.bv.resetForm();
  4608. this.$id.val(invalidSamples[i]);
  4609. this.bv.validate();
  4610. expect(this.bv.isValid()).toEqual(false);
  4611. }
  4612. });
  4613. it('Irish Personal Public Service Number (PPS)', function() {
  4614. this.bv.updateOption('id', 'id', 'country', 'IE');
  4615. // Valid samples
  4616. var validSamples = ['6433435F', '6433435FT', '6433435FW', '6433435OA', '6433435IH', '1234567TW', '1234567FA'];
  4617. for (var i in validSamples) {
  4618. this.bv.resetForm();
  4619. this.$id.val(validSamples[i]);
  4620. this.bv.validate();
  4621. expect(this.bv.isValid()).toBeTruthy();
  4622. }
  4623. // Invalid samples
  4624. var invalidSamples = ['6433435E', '6433435VH'];
  4625. for (i in invalidSamples) {
  4626. this.bv.resetForm();
  4627. this.$id.val(invalidSamples[i]);
  4628. this.bv.validate();
  4629. expect(this.bv.isValid()).toEqual(false);
  4630. }
  4631. });
  4632. it('Iceland national identification number (Kennitala)', function() {
  4633. this.bv.updateOption('id', 'id', 'country', 'IS');
  4634. // Valid samples
  4635. var validSamples = ['120174-3399', '1201743399', '0902862349'];
  4636. for (var i in validSamples) {
  4637. this.bv.resetForm();
  4638. this.$id.val(validSamples[i]);
  4639. this.bv.validate();
  4640. expect(this.bv.isValid()).toBeTruthy();
  4641. }
  4642. });
  4643. it('Lithuanian Personal Code (Asmens kodas)', function() {
  4644. this.bv.updateOption('id', 'id', 'country', 'LT');
  4645. // Valid samples
  4646. var validSamples = ['38703181745'];
  4647. for (var i in validSamples) {
  4648. this.bv.resetForm();
  4649. this.$id.val(validSamples[i]);
  4650. this.bv.validate();
  4651. expect(this.bv.isValid()).toBeTruthy();
  4652. }
  4653. // Invalid samples
  4654. var invalidSamples = ['38703181746', '78703181745', '38703421745'];
  4655. for (i in invalidSamples) {
  4656. this.bv.resetForm();
  4657. this.$id.val(invalidSamples[i]);
  4658. this.bv.validate();
  4659. expect(this.bv.isValid()).toEqual(false);
  4660. }
  4661. });
  4662. it('Latvian Personal Code (Personas kods)', function() {
  4663. this.bv.updateOption('id', 'id', 'country', 'LV');
  4664. // Valid samples
  4665. var validSamples = ['161175-19997', '16117519997'];
  4666. for (var i in validSamples) {
  4667. this.bv.resetForm();
  4668. this.$id.val(validSamples[i]);
  4669. this.bv.validate();
  4670. expect(this.bv.isValid()).toBeTruthy();
  4671. }
  4672. // Invalid samples
  4673. var invalidSamples = ['161375-19997'];
  4674. for (i in invalidSamples) {
  4675. this.bv.resetForm();
  4676. this.$id.val(invalidSamples[i]);
  4677. this.bv.validate();
  4678. expect(this.bv.isValid()).toEqual(false);
  4679. }
  4680. });
  4681. it('Dutch national identification number (BSN)', function() {
  4682. this.bv.updateOption('id', 'id', 'country', 'NL');
  4683. // Valid samples
  4684. var validSamples = ['111222333', '941331490', '9413.31.490'];
  4685. for (var i in validSamples) {
  4686. this.bv.resetForm();
  4687. this.$id.val(validSamples[i]);
  4688. this.bv.validate();
  4689. expect(this.bv.isValid()).toBeTruthy();
  4690. }
  4691. // Invalid samples
  4692. var invalidSamples = ['111252333'];
  4693. for (i in invalidSamples) {
  4694. this.bv.resetForm();
  4695. this.$id.val(invalidSamples[i]);
  4696. this.bv.validate();
  4697. expect(this.bv.isValid()).toEqual(false);
  4698. }
  4699. });
  4700. it('Romanian numerical personal code (CNP)', function() {
  4701. this.bv.updateOption('id', 'id', 'country', 'RO');
  4702. // Valid samples
  4703. var validSamples = ['1630615123457', '1800101221144'];
  4704. for (var i in validSamples) {
  4705. this.bv.resetForm();
  4706. this.$id.val(validSamples[i]);
  4707. this.bv.validate();
  4708. expect(this.bv.isValid()).toBeTruthy();
  4709. }
  4710. // Invalid samples
  4711. var invalidSamples = ['8800101221144', '1632215123457', '1630615123458'];
  4712. for (i in invalidSamples) {
  4713. this.bv.resetForm();
  4714. this.$id.val(invalidSamples[i]);
  4715. this.bv.validate();
  4716. expect(this.bv.isValid()).toEqual(false);
  4717. }
  4718. });
  4719. it('Swedish personal identity number (personnummer)', function() {
  4720. this.bv.updateOption('id', 'id', 'country', 'SE');
  4721. // Valid samples
  4722. var validSamples = ['8112289874', '811228-9874', '811228+9874'];
  4723. for (var i in validSamples) {
  4724. this.bv.resetForm();
  4725. this.$id.val(validSamples[i]);
  4726. this.bv.validate();
  4727. expect(this.bv.isValid()).toBeTruthy();
  4728. }
  4729. // Invalid samples
  4730. var invalidSamples = ['811228-9873'];
  4731. for (i in invalidSamples) {
  4732. this.bv.resetForm();
  4733. this.$id.val(invalidSamples[i]);
  4734. this.bv.validate();
  4735. expect(this.bv.isValid()).toEqual(false);
  4736. }
  4737. });
  4738. it('Slovak national identifier number (RC)', function() {
  4739. this.bv.updateOption('id', 'id', 'country', 'SK');
  4740. // Valid samples
  4741. var validSamples = ['7103192745', '991231123'];
  4742. for (var i in validSamples) {
  4743. this.bv.resetForm();
  4744. this.$id.val(validSamples[i]);
  4745. this.bv.validate();
  4746. expect(this.bv.isValid()).toBeTruthy();
  4747. }
  4748. // Invalid samples
  4749. var invalidSamples = ['7103192746', '1103492745'];
  4750. for (i in invalidSamples) {
  4751. this.bv.resetForm();
  4752. this.$id.val(invalidSamples[i]);
  4753. this.bv.validate();
  4754. expect(this.bv.isValid()).toEqual(false);
  4755. }
  4756. });
  4757. it('South African ID', function() {
  4758. this.bv.updateOption('id', 'id', 'country', 'ZA');
  4759. // Valid samples
  4760. var validSamples = ['8001015009087'];
  4761. for (var i in validSamples) {
  4762. this.bv.resetForm();
  4763. this.$id.val(validSamples[i]);
  4764. this.bv.validate();
  4765. expect(this.bv.isValid()).toBeTruthy();
  4766. }
  4767. // Invalid samples
  4768. var invalidSamples = ['8001015009287', '8001015009086'];
  4769. for (i in invalidSamples) {
  4770. this.bv.resetForm();
  4771. this.$id.val(invalidSamples[i]);
  4772. this.bv.validate();
  4773. expect(this.bv.isValid()).toEqual(false);
  4774. }
  4775. });
  4776. it('Thailand citizen number', function() {
  4777. this.bv.updateOption('id', 'id', 'country', 'TH');
  4778. // Valid samples
  4779. var validSamples = ['7145620509547', '3688699975685', '2368719339716'];
  4780. for (var i in validSamples) {
  4781. this.bv.resetForm();
  4782. this.$id.val(validSamples[i]);
  4783. this.bv.validate();
  4784. expect(this.bv.isValid()).toBeTruthy();
  4785. }
  4786. // Invalid samples
  4787. var invalidSamples = ['1100800092310'];
  4788. for (i in invalidSamples) {
  4789. this.bv.resetForm();
  4790. this.$id.val(invalidSamples[i]);
  4791. this.bv.validate();
  4792. expect(this.bv.isValid()).toEqual(false);
  4793. }
  4794. });
  4795. });
  4796. describe('imo', function() {
  4797. beforeEach(function() {
  4798. $([
  4799. '<form class="form-horizontal" id="imoForm">',
  4800. '<div class="form-group">',
  4801. '<input type="text" name="imo" data-bv-imo />',
  4802. '</div>',
  4803. '</form>'
  4804. ].join('\n')).appendTo('body');
  4805. $('#imoForm').bootstrapValidator();
  4806. this.bv = $('#imoForm').data('bootstrapValidator');
  4807. this.$imo = this.bv.getFieldElements('imo');
  4808. });
  4809. afterEach(function() {
  4810. $('#imoForm').bootstrapValidator('destroy').remove();
  4811. });
  4812. it('Valid IMO (upper)', function() {
  4813. this.bv.resetForm();
  4814. this.$imo.val('IMO 9074729');
  4815. this.bv.validate();
  4816. expect(this.bv.isValid()).toBeTruthy();
  4817. });
  4818. it('Valid IMO (lower)', function() {
  4819. this.bv.resetForm();
  4820. this.$imo.val('imo 9074729');
  4821. this.bv.validate();
  4822. expect(this.bv.isValid()).toBeTruthy();
  4823. });
  4824. it('Invalid IMO (bad format)', function() {
  4825. this.bv.resetForm();
  4826. this.$imo.val('9074729');
  4827. this.bv.validate();
  4828. expect(this.bv.isValid()).toBeFalsy();
  4829. });
  4830. it('Invalid IMO (bad check digit)', function() {
  4831. this.bv.resetForm();
  4832. this.$imo.val('IMO 9074728');
  4833. this.bv.validate();
  4834. expect(this.bv.isValid()).toBeFalsy();
  4835. });
  4836. });
  4837. describe('ip', function() {
  4838. beforeEach(function() {
  4839. $([
  4840. '<form class="form-horizontal" id="ipForm">',
  4841. '<div class="form-group">',
  4842. '<input type="text" name="ipv4" data-bv-ip data-bv-ip-ipv6="false" />',
  4843. '</div>',
  4844. '<div class="form-group">',
  4845. '<input type="text" name="ipv6" data-bv-ip data-bv-ip-ipv4="false" />',
  4846. '</div>',
  4847. '<div class="form-group">',
  4848. '<input type="text" name="both" data-bv-ip />',
  4849. '</div>',
  4850. '</form>'
  4851. ].join('\n')).appendTo('body');
  4852. $('#ipForm').bootstrapValidator();
  4853. this.bv = $('#ipForm').data('bootstrapValidator');
  4854. this.$ipv4 = this.bv.getFieldElements('ipv4');
  4855. this.$ipv6 = this.bv.getFieldElements('ipv6');
  4856. this.$both = this.bv.getFieldElements('both');
  4857. });
  4858. afterEach(function() {
  4859. $('#ipForm').bootstrapValidator('destroy').remove();
  4860. });
  4861. it('Valid ipv4', function() {
  4862. this.$ipv4.val('0.0.0.0');
  4863. this.bv.validate();
  4864. expect(this.bv.isValid()).toBeTruthy();
  4865. this.bv.resetForm();
  4866. this.$ipv4.val('192.168.1.1');
  4867. this.bv.validate();
  4868. expect(this.bv.isValid()).toBeTruthy();
  4869. this.bv.resetForm();
  4870. this.$ipv4.val('255.255.255.255');
  4871. this.bv.validate();
  4872. expect(this.bv.isValid()).toBeTruthy();
  4873. });
  4874. it('Invalid ipv4', function() {
  4875. this.$ipv4.val('10.168.0001.100'); // extra 0 not allowed
  4876. this.bv.validate();
  4877. expect(this.bv.isValid()).toEqual(false);
  4878. this.bv.resetForm();
  4879. this.$ipv4.val('0.0.0.256'); // 256 not allowed, max is 255
  4880. this.bv.validate();
  4881. expect(this.bv.isValid()).toEqual(false);
  4882. this.bv.resetForm();
  4883. this.$ipv4.val('256.255.255.255'); // max is 255.255.255.255
  4884. this.bv.validate();
  4885. expect(this.bv.isValid()).toEqual(false);
  4886. this.bv.resetForm();
  4887. this.$ipv4.val('192.168. 224.0'); // internal space
  4888. this.bv.validate();
  4889. expect(this.bv.isValid()).toEqual(false);
  4890. this.bv.resetForm();
  4891. this.$ipv4.val('192.168.224.0 1'); // junk after valid address
  4892. this.bv.validate();
  4893. expect(this.bv.isValid()).toEqual(false);
  4894. });
  4895. it('Valid ipv6', function() {
  4896. this.$ipv6.val('0000:0000:0000:0000:0000:0000:0000:0000');
  4897. this.bv.validate();
  4898. expect(this.bv.isValid()).toBeTruthy();
  4899. this.bv.resetForm();
  4900. this.$ipv6.val('fe00::1');
  4901. this.bv.validate();
  4902. expect(this.bv.isValid()).toBeTruthy();
  4903. this.bv.resetForm();
  4904. this.$ipv6.val('fe80::217:f2ff:fe07:ed62');
  4905. this.bv.validate();
  4906. expect(this.bv.isValid()).toBeTruthy();
  4907. this.bv.resetForm();
  4908. this.$ipv6.val('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff');
  4909. this.bv.validate();
  4910. expect(this.bv.isValid()).toBeTruthy();
  4911. });
  4912. it('Invalid ipv6', function() {
  4913. this.$ipv6.val('02001:0000:1234:0000:0000:C1C0:ABCD:0876'); // extra 0 not allowed
  4914. this.bv.validate();
  4915. expect(this.bv.isValid()).toEqual(false);
  4916. this.bv.resetForm();
  4917. this.$ipv6.val('2001:0000:1234:0000:00001:C1C0:ABCD:0876'); // extra 0 not allowed
  4918. this.bv.validate();
  4919. expect(this.bv.isValid()).toEqual(false);
  4920. this.bv.resetForm();
  4921. this.$ipv6.val('2001:0000:1234: 0000:0000:C1C0:ABCD:0876'); // internal space
  4922. this.bv.validate();
  4923. expect(this.bv.isValid()).toEqual(false);
  4924. this.bv.resetForm();
  4925. this.$ipv6.val('2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'); // junk after valid address
  4926. this.bv.validate();
  4927. expect(this.bv.isValid()).toEqual(false);
  4928. this.bv.resetForm();
  4929. this.$ipv6.val('3ffe:0b00:0000:0001:0000:0000:000a'); // seven segment
  4930. this.bv.validate();
  4931. expect(this.bv.isValid()).toEqual(false);
  4932. this.bv.resetForm();
  4933. this.$ipv6.val('FF02:0000:0000:0000:0000:0000:0000:0000:0001'); // nine segment
  4934. this.bv.validate();
  4935. expect(this.bv.isValid()).toEqual(false);
  4936. this.bv.resetForm();
  4937. this.$ipv6.val('::1111:2222:3333:4444:5555:6666::'); // double "::"
  4938. this.bv.validate();
  4939. expect(this.bv.isValid()).toEqual(false);
  4940. this.bv.resetForm();
  4941. this.$ipv6.val('3ffe:b00::1::a'); // double "::"
  4942. this.bv.validate();
  4943. expect(this.bv.isValid()).toEqual(false);
  4944. });
  4945. it('Both', function() {
  4946. this.$both.val('255.255.255.255'); // valid
  4947. this.bv.validate();
  4948. expect(this.bv.isValid()).toBeTruthy();
  4949. this.bv.resetForm();
  4950. this.$both.val('256.0.0.0'); // 256 not allowed, max is 255
  4951. this.bv.validate();
  4952. expect(this.bv.isValid()).toEqual(false);
  4953. this.bv.resetForm();
  4954. this.$both.val('2001:0db8:0000:85a3:0000:0000:ac1f:8001'); // valid
  4955. this.bv.validate();
  4956. expect(this.bv.isValid()).toBeTruthy();
  4957. this.bv.resetForm();
  4958. this.$both.val('2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'); // junk after valid address
  4959. this.bv.validate();
  4960. expect(this.bv.isValid()).toEqual(false);
  4961. });
  4962. });
  4963. describe('isbn', function() {
  4964. beforeEach(function() {
  4965. var html = [
  4966. '<div class="container">',
  4967. '<form class="form-horizontal" id="isbnForm">',
  4968. '<div class="form-group">',
  4969. '<input type="text" name="isbn" data-bv-isbn />',
  4970. '</div>',
  4971. '</form>',
  4972. '</div>'
  4973. ].join('\n');
  4974. $(html).appendTo('body');
  4975. $('#isbnForm').bootstrapValidator();
  4976. this.bv = $('#isbnForm').data('bootstrapValidator');
  4977. this.$isbn = this.bv.getFieldElements('isbn');
  4978. });
  4979. afterEach(function() {
  4980. $('#isbnForm').bootstrapValidator('destroy').parent().remove();
  4981. });
  4982. it('isbn10 hyphen', function() {
  4983. var samples = ['99921-58-10-7', '9971-5-0210-0', '960-425-059-0', '80-902734-1-6'];
  4984. for (var i in samples) {
  4985. this.$isbn.val(samples[i]);
  4986. this.bv.validate();
  4987. expect(this.bv.isValidField('isbn')).toBeTruthy();
  4988. }
  4989. });
  4990. it('isbn10 space', function() {
  4991. var samples = ['85 359 0277 5', '1 84356 028 3', '0 684 84328 5', '0 85131 041 9', '0 943396 04 2'];
  4992. for (var i in samples) {
  4993. this.$isbn.val(samples[i]);
  4994. this.bv.validate();
  4995. expect(this.bv.isValidField('isbn')).toBeTruthy();
  4996. }
  4997. });
  4998. it('isbn10 hyphen with X', function() {
  4999. var samples = ['0-8044-2957-X', '0-9752298-0-X'];
  5000. for (var i in samples) {
  5001. this.$isbn.val(samples[i]);
  5002. this.bv.validate();
  5003. expect(this.bv.isValidField('isbn')).toBeTruthy();
  5004. }
  5005. });
  5006. it('isbn10 invalid check digit', function() {
  5007. this.$isbn.val('99921-58-10-6');
  5008. this.bv.validate();
  5009. expect(this.bv.isValidField('isbn')).toEqual(false);
  5010. });
  5011. it('isbn13', function() {
  5012. this.$isbn.val('978-0-306-40615-7');
  5013. this.bv.validate();
  5014. expect(this.bv.isValidField('isbn')).toBeTruthy();
  5015. });
  5016. it('isbn13 invalid check digit', function() {
  5017. this.$isbn.val('978-0-306-40615-6');
  5018. this.bv.validate();
  5019. expect(this.bv.isValidField('isbn')).toEqual(false);
  5020. });
  5021. });
  5022. describe('isin', function() {
  5023. beforeEach(function() {
  5024. var html = [
  5025. '<div class="container">',
  5026. '<form class="form-horizontal" id="isinForm">',
  5027. '<div class="form-group">',
  5028. '<input type="text" name="isin" data-bv-isin />',
  5029. '</div>',
  5030. '</form>',
  5031. '</div>'
  5032. ].join('\n');
  5033. $(html).appendTo('body');
  5034. $('#isinForm').bootstrapValidator();
  5035. this.bv = $('#isinForm').data('bootstrapValidator');
  5036. this.$isin = this.bv.getFieldElements('isin');
  5037. });
  5038. afterEach(function() {
  5039. $('#isinForm').bootstrapValidator('destroy').parent().remove();
  5040. });
  5041. it('valid', function() {
  5042. var samples = ['US0378331005', 'AU0000XVGZA3', 'GB0002634946'];
  5043. for (var i in samples) {
  5044. this.$isin.val(samples[i]);
  5045. this.bv.validate();
  5046. expect(this.bv.isValidField('isin')).toBeTruthy();
  5047. }
  5048. });
  5049. it('invalid country code', function() {
  5050. this.$isin.val('AA0000XVGZA3');
  5051. this.bv.validate();
  5052. expect(this.bv.isValidField('isin')).toEqual(false);
  5053. });
  5054. it('contains only digits and alphabet', function() {
  5055. this.$isin.val('US12345ABC@#$');
  5056. this.bv.validate();
  5057. expect(this.bv.isValidField('isin')).toEqual(false);
  5058. });
  5059. it('invalid length', function() {
  5060. this.$isin.val('US1234567');
  5061. this.bv.validate();
  5062. expect(this.bv.isValidField('isin')).toEqual(false);
  5063. });
  5064. it('invalid check digit', function() {
  5065. this.$isin.val('US0378331004');
  5066. this.bv.validate();
  5067. expect(this.bv.isValidField('isin')).toEqual(false);
  5068. });
  5069. });
  5070. describe('ismn', function() {
  5071. beforeEach(function() {
  5072. var html = [
  5073. '<div class="container">',
  5074. '<form class="form-horizontal" id="ismnForm">',
  5075. '<div class="form-group">',
  5076. '<input type="text" name="ismn" data-bv-ismn />',
  5077. '</div>',
  5078. '</form>',
  5079. '</div>'
  5080. ].join('\n');
  5081. $(html).appendTo('body');
  5082. $('#ismnForm').bootstrapValidator();
  5083. this.bv = $('#ismnForm').data('bootstrapValidator');
  5084. this.$ismn = this.bv.getFieldElements('ismn');
  5085. });
  5086. afterEach(function() {
  5087. $('#ismnForm').bootstrapValidator('destroy').parent().remove();
  5088. });
  5089. it('valid start with M', function() {
  5090. this.$ismn.val('M230671187');
  5091. this.bv.validate();
  5092. expect(this.bv.isValidField('ismn')).toBeTruthy();
  5093. });
  5094. it('valid start with 979', function() {
  5095. this.$ismn.val('9790060115615');
  5096. this.bv.validate();
  5097. expect(this.bv.isValidField('ismn')).toBeTruthy();
  5098. });
  5099. it('valid contains spaces', function() {
  5100. this.$ismn.val('979 0 3452 4680 5');
  5101. this.bv.validate();
  5102. expect(this.bv.isValidField('ismn')).toBeTruthy();
  5103. });
  5104. it('valid contains dashes', function() {
  5105. this.$ismn.val('979-0-0601-1561-5');
  5106. this.bv.validate();
  5107. expect(this.bv.isValidField('ismn')).toBeTruthy();
  5108. });
  5109. it('invalid format', function() {
  5110. this.$ismn.val('N123456789');
  5111. this.bv.validate();
  5112. expect(this.bv.isValidField('ismn')).toEqual(false);
  5113. });
  5114. it('invalid check digit', function() {
  5115. this.$ismn.val('9790060115614');
  5116. this.bv.validate();
  5117. expect(this.bv.isValidField('ismn')).toEqual(false);
  5118. });
  5119. });
  5120. describe('issn', function() {
  5121. beforeEach(function() {
  5122. var html = [
  5123. '<div class="container">',
  5124. '<form class="form-horizontal" id="issnForm">',
  5125. '<div class="form-group">',
  5126. '<input type="text" name="issn" data-bv-issn />',
  5127. '</div>',
  5128. '</form>',
  5129. '</div>'
  5130. ].join('\n');
  5131. $(html).appendTo('body');
  5132. $('#issnForm').bootstrapValidator();
  5133. this.bv = $('#issnForm').data('bootstrapValidator');
  5134. this.$issn = this.bv.getFieldElements('issn');
  5135. });
  5136. afterEach(function() {
  5137. $('#issnForm').bootstrapValidator('destroy').parent().remove();
  5138. });
  5139. it('valid', function() {
  5140. var samples = ['0378-5955', '0024-9319', '0032-1478'];
  5141. for (var i in samples) {
  5142. this.$issn.val(samples[i]);
  5143. this.bv.validate();
  5144. expect(this.bv.isValidField('issn')).toBeTruthy();
  5145. }
  5146. });
  5147. it('not contains hyphen', function() {
  5148. this.$issn.val('03785955');
  5149. this.bv.validate();
  5150. expect(this.bv.isValidField('issn')).toEqual(false);
  5151. });
  5152. it('contains only digits, X', function() {
  5153. this.$issn.val('1234-566A');
  5154. this.bv.validate();
  5155. expect(this.bv.isValidField('issn')).toEqual(false);
  5156. });
  5157. it('invalid check sum', function() {
  5158. this.$issn.val('0032-147X');
  5159. this.bv.validate();
  5160. expect(this.bv.isValidField('issn')).toEqual(false);
  5161. });
  5162. });
  5163. describe('keywordColor', function() {
  5164. beforeEach(function() {
  5165. var html = [
  5166. '<div class="container">',
  5167. '<form class="form-horizontal" id="keywordColorForm">',
  5168. '<div class="form-group">',
  5169. '<input type="text" name="keyword" data-bv-keywordcolor />',
  5170. '</div>',
  5171. '</form>',
  5172. '</div>'
  5173. ].join('\n');
  5174. $(html).appendTo('body');
  5175. $('#keywordColorForm').bootstrapValidator();
  5176. this.bv = $('#keywordColorForm').data('bootstrapValidator');
  5177. this.$keywordColor = this.bv.getFieldElements('keyword');
  5178. });
  5179. afterEach(function() {
  5180. $('#keywordColorForm').bootstrapValidator('destroy').parent().remove();
  5181. });
  5182. it('accept transparent', function() {
  5183. this.$keywordColor.val('transparent');
  5184. this.bv.validate();
  5185. expect(this.bv.isValidField('keyword')).toBeTruthy();
  5186. });
  5187. it('accept blueviolet', function() {
  5188. this.$keywordColor.val('transparent');
  5189. this.bv.validate();
  5190. expect(this.bv.isValidField('keyword')).toBeTruthy();
  5191. });
  5192. it('reject combined keywords', function() {
  5193. this.$keywordColor.val('blueviolet red');
  5194. this.bv.validate();
  5195. expect(this.bv.isValidField('keyword')).toEqual(false);
  5196. });
  5197. it('reject shady', function() {
  5198. this.$keywordColor.val('shady');
  5199. this.bv.validate();
  5200. expect(this.bv.isValidField('keyword')).toEqual(false);
  5201. });
  5202. it('reject blueish', function() {
  5203. this.$keywordColor.val('blueish');
  5204. this.bv.validate();
  5205. expect(this.bv.isValidField('keyword')).toEqual(false);
  5206. });
  5207. });
  5208. function lessThanCompare() {
  5209. var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
  5210. $('#msg').html('lessThanCompare() called; compare to ' + compareTo);
  5211. return compareTo;
  5212. };
  5213. TestSuite = $.extend({}, TestSuite, {
  5214. lessThan: {
  5215. compareTo: function(value, validator, $field) {
  5216. var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
  5217. $('#msg').html('TestSuite.lessThan.compareTo() called; compare to ' + compareTo);
  5218. return compareTo;
  5219. }
  5220. }
  5221. });
  5222. describe('lessThan', function() {
  5223. beforeEach(function() {
  5224. $([
  5225. '<form class="form-horizontal" id="lessThanForm">',
  5226. '<div id="msg"></div>',
  5227. '<div class="form-group">',
  5228. '<input type="text" name="maxAge" />',
  5229. '</div>',
  5230. '<div class="form-group">',
  5231. '<input type="text" name="age" data-bv-lessthan data-bv-lessthan-value="100" />',
  5232. '</div>',
  5233. '</form>'
  5234. ].join('\n')).appendTo('body');
  5235. $('#lessThanForm').bootstrapValidator();
  5236. this.bv = $('#lessThanForm').data('bootstrapValidator');
  5237. this.$maxAge = this.bv.getFieldElements('maxAge');
  5238. this.$age = this.bv.getFieldElements('age');
  5239. });
  5240. afterEach(function() {
  5241. $('#lessThanForm').bootstrapValidator('destroy').remove();
  5242. });
  5243. it('not a number', function() {
  5244. this.$age.val('20abc');
  5245. this.bv.validate();
  5246. expect(this.bv.isValid()).toEqual(false);
  5247. });
  5248. it('compare to value', function() {
  5249. this.$age.val(120);
  5250. this.bv.validate();
  5251. expect(this.bv.isValid()).toEqual(false);
  5252. this.bv.resetForm();
  5253. this.$age.val(30);
  5254. this.bv.validate();
  5255. expect(this.bv.isValid()).toBeTruthy();
  5256. });
  5257. it('compare to other field', function() {
  5258. this.$age.attr('data-bv-lessthan-value', 'maxAge');
  5259. this.bv.destroy();
  5260. this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
  5261. this.$maxAge.val(40);
  5262. this.$age.val(20);
  5263. this.bv.validate();
  5264. expect(this.bv.isValid()).toBeTruthy();
  5265. this.bv.resetForm();
  5266. this.$maxAge.val(20);
  5267. this.$age.val(30);
  5268. this.bv.validate();
  5269. expect(this.bv.isValid()).toEqual(false);
  5270. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
  5271. });
  5272. it('compare to return value of a function', function() {
  5273. this.$age.attr('data-bv-lessthan-value', 'lessThanCompare');
  5274. this.bv.destroy();
  5275. this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
  5276. this.$maxAge.val(50);
  5277. this.$age.val(60);
  5278. this.bv.validate();
  5279. expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 50');
  5280. expect(this.bv.isValid()).toEqual(false);
  5281. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
  5282. this.bv.resetForm();
  5283. this.$maxAge.val(60);
  5284. this.$age.val(30);
  5285. this.bv.validate();
  5286. expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 60');
  5287. expect(this.bv.isValid()).toBeTruthy();
  5288. });
  5289. it('compare to return value of a namespace function', function() {
  5290. this.$age.attr('data-bv-lessthan-value', 'TestSuite.lessThan.compareTo');
  5291. this.bv.destroy();
  5292. this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
  5293. this.$maxAge.val(50);
  5294. this.$age.val(60);
  5295. this.bv.validate();
  5296. expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 50');
  5297. expect(this.bv.isValid()).toEqual(false);
  5298. expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
  5299. this.bv.resetForm();
  5300. this.$maxAge.val(60);
  5301. this.$age.val(30);
  5302. this.bv.validate();
  5303. expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 60');
  5304. expect(this.bv.isValid()).toBeTruthy();
  5305. });
  5306. });
  5307. describe('meid', function() {
  5308. beforeEach(function() {
  5309. $([
  5310. '<form class="form-horizontal" id="meidForm">',
  5311. '<div class="form-group">',
  5312. '<input type="text" name="meid" data-bv-meid />',
  5313. '</div>',
  5314. '</form>'
  5315. ].join('\n')).appendTo('body');
  5316. $('#meidForm').bootstrapValidator();
  5317. this.bv = $('#meidForm').data('bootstrapValidator');
  5318. this.$meid = this.bv.getFieldElements('meid');
  5319. });
  5320. afterEach(function() {
  5321. $('#meidForm').bootstrapValidator('destroy').remove();
  5322. });
  5323. it('Valid MEID (14 hex, check digit)', function() {
  5324. this.bv.resetForm();
  5325. this.$meid.val('A00000049259B16');
  5326. this.bv.validate();
  5327. expect(this.bv.isValid()).toBeTruthy();
  5328. });
  5329. it('Valid MEID (14 hex, dashes, check digit)', function() {
  5330. this.bv.resetForm();
  5331. this.$meid.val('A0-000004-9259B1-6');
  5332. this.bv.validate();
  5333. expect(this.bv.isValid()).toBeTruthy();
  5334. });
  5335. it('Valid MEID (14 hex, spaces, check digit)', function() {
  5336. this.bv.resetForm();
  5337. this.$meid.val('A0 000004 9259B1 6');
  5338. this.bv.validate();
  5339. expect(this.bv.isValid()).toBeTruthy();
  5340. });
  5341. it('Valid MEID (18 dec, check digit)', function() {
  5342. this.bv.resetForm();
  5343. this.$meid.val('2936087365007037100');
  5344. this.bv.validate();
  5345. expect(this.bv.isValid()).toBeTruthy();
  5346. });
  5347. it('Valid MEID (18 dec, dashes, check digit)', function() {
  5348. this.bv.resetForm();
  5349. this.$meid.val('29360-87365-0070-3710-0');
  5350. this.bv.validate();
  5351. expect(this.bv.isValid()).toBeTruthy();
  5352. });
  5353. it('Valid MEID (18 dec, spaces, check digit)', function() {
  5354. this.bv.resetForm();
  5355. this.$meid.val('29360 87365 0070 3710 0');
  5356. this.bv.validate();
  5357. expect(this.bv.isValid()).toBeTruthy();
  5358. });
  5359. it('Valid MEID (14 hex)', function() {
  5360. this.bv.resetForm();
  5361. this.$meid.val('AF0123450ABCDE');
  5362. this.bv.validate();
  5363. expect(this.bv.isValid()).toBeTruthy();
  5364. });
  5365. it('Valid MEID (14 hex, dashes)', function() {
  5366. this.bv.resetForm();
  5367. this.$meid.val('AF-012345-0ABCDE');
  5368. this.bv.validate();
  5369. expect(this.bv.isValid()).toBeTruthy();
  5370. });
  5371. it('Valid MEID (14 hex, spaces)', function() {
  5372. this.bv.resetForm();
  5373. this.$meid.val('AF 012345 0ABCDE');
  5374. this.bv.validate();
  5375. expect(this.bv.isValid()).toBeTruthy();
  5376. });
  5377. it('Valid MEID (18 dec)', function() {
  5378. this.bv.resetForm();
  5379. this.$meid.val('293608736500703710');
  5380. this.bv.validate();
  5381. expect(this.bv.isValid()).toBeTruthy();
  5382. });
  5383. it('Valid MEID (18 dec, dashes)', function() {
  5384. this.bv.resetForm();
  5385. this.$meid.val('29360-87365-0070-3710');
  5386. this.bv.validate();
  5387. expect(this.bv.isValid()).toBeTruthy();
  5388. });
  5389. it('Valid MEID (18 dec, spaces)', function() {
  5390. this.bv.resetForm();
  5391. this.$meid.val('29360 87365 0070 3710');
  5392. this.bv.validate();
  5393. expect(this.bv.isValid()).toBeTruthy();
  5394. });
  5395. it('Invalid MEID (14 hex, bad check digit)', function() {
  5396. this.bv.resetForm();
  5397. this.$meid.val('A00000049259B15');
  5398. this.bv.validate();
  5399. expect(this.bv.isValid()).toBeFalsy();
  5400. });
  5401. it('Invalid MEID (13 hex)', function() {
  5402. this.bv.resetForm();
  5403. this.$meid.val('A00000049259B');
  5404. this.bv.validate();
  5405. expect(this.bv.isValid()).toBeFalsy();
  5406. });
  5407. it('Invalid MEID (18 dec, bad check digit)', function() {
  5408. this.bv.resetForm();
  5409. this.$meid.val('2936087365007037101');
  5410. this.bv.validate();
  5411. expect(this.bv.isValid()).toBeFalsy();
  5412. });
  5413. it('Invalid MEID (17 dec)', function() {
  5414. this.bv.resetForm();
  5415. this.$meid.val('29360873650070371');
  5416. this.bv.validate();
  5417. expect(this.bv.isValid()).toBeFalsy();
  5418. });
  5419. });
  5420. describe('phone', function() {
  5421. beforeEach(function() {
  5422. $([
  5423. '<form class="form-horizontal" id="phoneForm">',
  5424. '<div class="form-group">',
  5425. '<select class="form-control" name="country">',
  5426. '<option value="BR">Brazil</option>',
  5427. '<option value="CN">China</option>',
  5428. '<option value="CZ">Czech Republic</option>',
  5429. '<option value="DK">Denmark</option>',
  5430. '<option value="ES">Spain</option>',
  5431. '<option value="FR">France</option>',
  5432. '<option value="GB">United Kingdom</option>',
  5433. '<option value="MA">Morocco</option>',
  5434. '<option value="PK">Pakistan</option>',
  5435. '<option value="RO">Romania</option>',
  5436. '<option value="RU">Russia</option>',
  5437. '<option value="SK">Slovakia</option>',
  5438. '<option value="TH">Thailand</option>',
  5439. '<option value="US">USA</option>',
  5440. '<option value="VE">Venezuela</option>',
  5441. '</select>',
  5442. '</div>',
  5443. '<div class="form-group">',
  5444. '<input type="text" name="phone" data-bv-phone />',
  5445. '</div>',
  5446. '</form>',
  5447. ].join('\n')).appendTo('body');
  5448. $('#phoneForm').bootstrapValidator();
  5449. /**
  5450. * @type {BootstrapValidator}
  5451. */
  5452. this.bv = $('#phoneForm').data('bootstrapValidator');
  5453. this.$country = this.bv.getFieldElements('country');
  5454. this.$phone = this.bv.getFieldElements('phone');
  5455. });
  5456. afterEach(function() {
  5457. $('#phoneForm').bootstrapValidator('destroy').remove();
  5458. });
  5459. it('dynamic country', function() {
  5460. this.$phone.attr('data-bv-phone-country', 'country');
  5461. this.bv.destroy();
  5462. this.bv = $('#phoneForm').bootstrapValidator().data('bootstrapValidator');
  5463. this.$country.val('BR');
  5464. this.$phone.val('16920894635');
  5465. this.bv.validate();
  5466. expect(this.bv.isValid()).toBeTruthy();
  5467. this.bv.resetForm();
  5468. this.$country.val('FR');
  5469. this.$phone.val('0644444444');
  5470. this.bv.validate();
  5471. expect(this.bv.isValid()).toBeTruthy();
  5472. this.bv.resetForm();
  5473. this.$country.val('GB');
  5474. this.$phone.val('012345678900');
  5475. this.bv.validate();
  5476. expect(this.bv.isValid()).toBeFalsy();
  5477. });
  5478. it('Brazil phone number', function() {
  5479. this.bv.updateOption('phone', 'phone', 'country', 'BR');
  5480. // Valid samples
  5481. var validSamples = [
  5482. '0800.000.00.00', '0800-000-00-00', '0800 000 00 00', '0800-00-00-00', '0800.00.00.00', '0800 00 00 00',
  5483. '0800-000-0000', '0800 000 0000', '0800.000.0000', '08000000000',
  5484. '1692089-4635', '16920894635', '16992089-4635', '16 99202-4635', '(16)99202-4635', '(16)92089-4635',
  5485. '(16) 92089-4635', '(15) 4343-4343', '+55 15 3702-7523', '(+55) 15 3702-7523', '(+55)1537027523',
  5486. '(+55)(15)3702-7523', '(+55) 15 3702-7523', '(+55) 15 99202-7523', '99202-4635', '(16) 9208-4635'
  5487. ];
  5488. for (var i in validSamples) {
  5489. this.bv.resetForm();
  5490. this.$phone.val(validSamples[i]);
  5491. this.bv.validate();
  5492. expect(this.bv.isValid()).toBeTruthy();
  5493. }
  5494. });
  5495. it('China phone number', function() {
  5496. this.bv.updateOption('phone', 'phone', 'country', 'CN');
  5497. // Valid samples
  5498. var validSamples = [
  5499. '18911111111', '189 1111 1111', '189-1111-1111', '0086-18911111111', '+86-18911111111',
  5500. '86-18911111111', '0086 18911111111', '+86 18911111111', '86 18911111111', '0086 189-1111-1111',
  5501. '+86 189-1111-1111', '86 189-1111-1111', '02011111111', '020-11111111', '020 11111111',
  5502. '020 1111 1111', '020-1111-1111', '0086 020 82803159', '0086-020-82803159', '0086-020-82803159',
  5503. '+86 20 61302222-8866', '+86 20 6130-2222-8866', '+86 10 59081185'
  5504. ];
  5505. for (var i in validSamples) {
  5506. this.bv.resetForm();
  5507. this.$phone.val(validSamples[i]);
  5508. this.bv.validate();
  5509. expect(this.bv.isValid()).toBeTruthy();
  5510. }
  5511. });
  5512. it('Czech Republic phone number', function() {
  5513. this.bv.updateOption('phone', 'phone', 'country', 'CZ');
  5514. // Valid samples
  5515. var validSamples = [
  5516. '00420123456789', '00420 123456789', '00420 123 456 789', '00 420 123 456 789',
  5517. '+420123456789', '+420 123456789', '+420 123 456 789', '123456789', '123 456 789'
  5518. ];
  5519. for (var i in validSamples) {
  5520. this.bv.resetForm();
  5521. this.$phone.val(validSamples[i]);
  5522. this.bv.validate();
  5523. expect(this.bv.isValid()).toBeTruthy();
  5524. }
  5525. // Invalid samples
  5526. var invalidSamples = [
  5527. '420123456789', '420 123456789', '420 123 456 789', '00421123456789', '00421 123456789',
  5528. '00421 123 456 789', '00 421 123 456 789', '+421123456789', '+421 123456789',
  5529. '+421 123 456 789'
  5530. ];
  5531. for (i in invalidSamples) {
  5532. this.bv.resetForm();
  5533. this.$phone.val(invalidSamples[i]);
  5534. this.bv.validate();
  5535. expect(this.bv.isValid()).toEqual(false);
  5536. }
  5537. });
  5538. it('France phone number', function() {
  5539. this.bv.updateOption('phone', 'phone', 'country', 'FR');
  5540. // Valid samples
  5541. var validSamples = [
  5542. // National formats
  5543. '0644444444', '06 44 44 44 44', '06-44-44-44-44', '06.44.44.44.44',
  5544. // International formats
  5545. '+33644444444', '+336.44.44.44.44', '+33 6.44.44.44.44', '0033644444444', '00336.44.44.44.44',
  5546. '0033 6.44.44.44.44',
  5547. // Some times
  5548. '+33(0)644444444', '+33 (0) 644444444'
  5549. ];
  5550. for (var i in validSamples) {
  5551. this.bv.resetForm();
  5552. this.$phone.val(validSamples[i]);
  5553. this.bv.validate();
  5554. expect(this.bv.isValid()).toBeTruthy();
  5555. }
  5556. // Invalid samples
  5557. var invalidSamples = [
  5558. // The separator between pairs of digits is not the same
  5559. '06 44.44-44.44', '06 44 44-44.44', '06 44 44-4444', '06 44 44-4444',
  5560. // Too many digits
  5561. '06444444444444',
  5562. // Missing leading 0
  5563. '6644444444',
  5564. // Too much non-numeric characters
  5565. '06 44.44-44.44', '+33 (0) 644444444',
  5566. // Bad parenthesis
  5567. '(0)644444444',
  5568. // Bad separator after the international prefix
  5569. '+33-(0)-644444444', '+33 (0)-644444444', '+33-(0) 644444444',
  5570. // Trailing separator
  5571. '06.44.44.44.44.'
  5572. ];
  5573. for (i in invalidSamples) {
  5574. this.bv.resetForm();
  5575. this.$phone.val(invalidSamples[i]);
  5576. this.bv.validate();
  5577. expect(this.bv.isValid()).toEqual(false);
  5578. }
  5579. });
  5580. it('United Kingdom phone number', function() {
  5581. this.bv.updateOption('phone', 'phone', 'country', 'GB');
  5582. // Valid samples
  5583. var validSamples = [
  5584. // National formats
  5585. '01611234567', '0161 123 4567', '(0161) 123 4567', '0161-123-4567',
  5586. // International formats
  5587. '+44 161 123 4567', '+441611234567', '+44(0)161234567', '00 44 161 1234567', '(011) 44 161 234567', '0161-158-5587',
  5588. // Extensions
  5589. '0161 123 4567 ext. 123', '01611234567x123', '+44161234567x123', '+44 (0) 161 1234567 ext 123'
  5590. ];
  5591. for (var i in validSamples) {
  5592. this.bv.resetForm();
  5593. this.$phone.val(validSamples[i]);
  5594. this.bv.validate();
  5595. expect(this.bv.isValid()).toBeTruthy();
  5596. }
  5597. // Invalid samples
  5598. var invalidSamples = [
  5599. '012345678900', // Too many digits
  5600. '1611234567', // Missing trunk
  5601. '012345678', // Not enough digits
  5602. '123 4567', // Missing area code
  5603. '061 123 4567' // Invalid area code
  5604. ];
  5605. for (i in invalidSamples) {
  5606. this.bv.resetForm();
  5607. this.$phone.val(invalidSamples[i]);
  5608. this.bv.validate();
  5609. expect(this.bv.isValid()).toEqual(false);
  5610. }
  5611. });
  5612. it('Morocco phone number', function() {
  5613. this.bv.updateOption('phone', 'phone', 'country', 'MA');
  5614. // Valid samples
  5615. var validSamples = [
  5616. // National formats
  5617. '0644444444', '0610245896', '0630548564', '06 44 44 44 44', '06-44-44-44-44', '06.44.44.44.44', '06 44.44-44.44',
  5618. '0528254856', '0535484541', '05 28 44 44 44', '05-28-44.44.44', '05.28.44.44.44', '05 28.44-44.44',
  5619. // International formats
  5620. '+212644444444', '+2126.44.44.44.44', '+212 6.44.44.44.44', '00212644444444', '002126.44.44.44.44', '00212 6.44.44.44.44',
  5621. // Some times
  5622. '+212(0)644444444', '+212 (0) 644444444'
  5623. ];
  5624. for (var i in validSamples) {
  5625. this.bv.resetForm();
  5626. this.$phone.val(validSamples[i]);
  5627. this.bv.validate();
  5628. expect(this.bv.isValid()).toBeTruthy();
  5629. }
  5630. // Invalid samples
  5631. var invalidSamples = [
  5632. '0625468961', '0512548632', '0542564896', // Not a valid phone numbers
  5633. '06444444444444', // Too many digits
  5634. '6644444444', // Missing leading 0
  5635. '06 44.44-44.44', '+212 (0) 644444444', // Too much non-numeric characters
  5636. '(0)644444444' // Bad parenthesis
  5637. ];
  5638. for (i in invalidSamples) {
  5639. this.bv.resetForm();
  5640. this.$phone.val(invalidSamples[i]);
  5641. this.bv.validate();
  5642. expect(this.bv.isValid()).toEqual(false);
  5643. }
  5644. });
  5645. it('Pakistan phone number', function() {
  5646. this.bv.updateOption('phone', 'phone', 'country', 'PK');
  5647. // Valid samples
  5648. var validSamples = ['03336527366'];
  5649. for (var i in validSamples) {
  5650. this.bv.resetForm();
  5651. this.$phone.val(validSamples[i]);
  5652. this.bv.validate();
  5653. expect(this.bv.isValid()).toBeTruthy();
  5654. }
  5655. });
  5656. it('Romania phone number', function() {
  5657. this.bv.updateOption('phone', 'phone', 'country', 'RO');
  5658. // Valid samples
  5659. var validSamples = [
  5660. '+40213-564-864', '+40213.564.864', '+40213 564 864', '0213-564-864',
  5661. '0213564864', '0313564864',
  5662. '0720512346', '0730512346', '0740512346', '0750512346', '+40750512346', '+40750.512.346',
  5663. '0760512346', '0770512346', '0780512346'
  5664. ];
  5665. for (var i in validSamples) {
  5666. this.bv.resetForm();
  5667. this.$phone.val(validSamples[i]);
  5668. this.bv.validate();
  5669. expect(this.bv.isValid()).toBeTruthy();
  5670. }
  5671. // Invalid samples
  5672. var invalidSamples = [
  5673. '0213/564/864', // Invalid separator
  5674. '0413564864', // Invalid land line number (The valid one should be +402, +403 or inside country 02 - 03)
  5675. '0790512346' // Invalid mobile phone number (The valid one is 072xxxxxxx - 078xxxxxxx)
  5676. ];
  5677. for (i in invalidSamples) {
  5678. this.bv.resetForm();
  5679. this.$phone.val(invalidSamples[i]);
  5680. this.bv.validate();
  5681. expect(this.bv.isValid()).toEqual(false);
  5682. }
  5683. });
  5684. it('Russia phone number', function() {
  5685. this.bv.updateOption('phone', 'phone', 'country', 'RU');
  5686. // Valid samples
  5687. var validSamples = ['+7(911)976-91-04'];
  5688. for (var i in validSamples) {
  5689. this.bv.resetForm();
  5690. this.$phone.val(validSamples[i]);
  5691. this.bv.validate();
  5692. expect(this.bv.isValid()).toBeTruthy();
  5693. }
  5694. });
  5695. it('Slovakia phone number', function() {
  5696. this.bv.updateOption('phone', 'phone', 'country', 'SK');
  5697. // Valid samples
  5698. var validSamples = [
  5699. '00420123456789', '00420 123456789', '00420 123 456 789', '00 420 123 456 789',
  5700. '+420123456789', '+420 123456789', '+420 123 456 789', '123456789', '123 456 789'
  5701. ];
  5702. for (var i in validSamples) {
  5703. this.bv.resetForm();
  5704. this.$phone.val(validSamples[i]);
  5705. this.bv.validate();
  5706. expect(this.bv.isValid()).toBeTruthy();
  5707. }
  5708. // Invalid samples
  5709. var invalidSamples = [
  5710. '420123456789', '420 123456789', '420 123 456 789', '00421123456789', '00421 123456789',
  5711. '00421 123 456 789', '00 421 123 456 789', '+421123456789', '+421 123456789',
  5712. '+421 123 456 789'
  5713. ];
  5714. for (i in invalidSamples) {
  5715. this.bv.resetForm();
  5716. this.$phone.val(invalidSamples[i]);
  5717. this.bv.validate();
  5718. expect(this.bv.isValid()).toEqual(false);
  5719. }
  5720. });
  5721. });
  5722. describe('stringLength', function() {
  5723. beforeEach(function() {
  5724. $([
  5725. '<form class="form-horizontal" id="stringLengthForm">',
  5726. '<div class="form-group">',
  5727. '<input type="text" name="textCharMaxLength" data-bv-stringlength data-bv-stringlength-max="10" />',
  5728. '</div>',
  5729. '<div class="form-group">',
  5730. '<textarea name="textareaCharMaxLength" data-bv-stringlength data-bv-stringlength-max="10"></textarea>',
  5731. '</div>',
  5732. '<div class="form-group">',
  5733. '<input type="text" name="textUTF8BytesMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-max="10" />',
  5734. '</div>',
  5735. '<div class="form-group">',
  5736. '<textarea name="textareaUTF8BytesMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-max="10"></textarea>',
  5737. '</div>',
  5738. '<div class="form-group">',
  5739. '<input type="text" name="textCharMinLength" data-bv-stringlength data-bv-stringlength-min="5" />',
  5740. '</div>',
  5741. '<div class="form-group">',
  5742. '<textarea name="textareaCharMinLength" data-bv-stringlength data-bv-stringlength-min="5"></textarea>',
  5743. '</div>',
  5744. '<div class="form-group">',
  5745. '<input type="text" name="textUTF8BytesMinLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" />',
  5746. '</div>',
  5747. '<div class="form-group">',
  5748. '<textarea name="textareaUTF8BytesMinLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5"></textarea>',
  5749. '</div>',
  5750. '<div class="form-group">',
  5751. '<input type="text" name="textCharMinMaxLength" data-bv-stringlength data-bv-stringlength-min="5" data-bv-stringlength-max="10" />',
  5752. '</div>',
  5753. '<div class="form-group">',
  5754. '<textarea name="textareaCharMinMaxLength" data-bv-stringlength data-bv-stringlength-min="5" data-bv-stringlength-max="10"></textarea>',
  5755. '</div>',
  5756. '<div class="form-group">',
  5757. '<input type="text" name="textUTF8BytesMinMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" data-bv-stringlength-max="10" />',
  5758. '</div>',
  5759. '<div class="form-group">',
  5760. '<textarea name="textareaUTF8BytesMinMaxLength" data-bv-stringlength data-bv-stringlength-utf8bytes="true" data-bv-stringlength-min="5" data-bv-stringlength-max="10"></textarea>',
  5761. '</div>',
  5762. '</form>'
  5763. ].join('\n')).appendTo('body');
  5764. $('#stringLengthForm').bootstrapValidator();
  5765. this.bv = $('#stringLengthForm').data('bootstrapValidator');
  5766. this.$textCharMaxLength = this.bv.getFieldElements('textCharMaxLength');
  5767. this.$textareaCharMaxLength = this.bv.getFieldElements('textareaCharMaxLength');
  5768. this.$textUTF8BytesMaxLength = this.bv.getFieldElements('textUTF8BytesMaxLength');
  5769. this.$textareaUTF8BytesMaxLength = this.bv.getFieldElements('textareaUTF8BytesMaxLength');
  5770. this.$textCharMinLength = this.bv.getFieldElements('textCharMinLength');
  5771. this.$textareaCharMinLength = this.bv.getFieldElements('textareaCharMinLength');
  5772. this.$textUTF8BytesMinLength = this.bv.getFieldElements('textUTF8BytesMinLength');
  5773. this.$textareaUTF8BytesMinLength = this.bv.getFieldElements('textareaUTF8BytesMinLength');
  5774. this.$textCharMinMaxLength = this.bv.getFieldElements('textCharMinMaxLength');
  5775. this.$textareaCharMinMaxLength = this.bv.getFieldElements('textareaCharMinMaxLength');
  5776. this.$textUTF8BytesMinMaxLength = this.bv.getFieldElements('textUTF8BytesMinMaxLength');
  5777. this.$textareaUTF8BytesMinMaxLength = this.bv.getFieldElements('textareaUTF8BytesMinMaxLength');
  5778. });
  5779. afterEach(function() {
  5780. $('#stringLengthForm').bootstrapValidator('destroy').remove();
  5781. });
  5782. it('Valid max lengths', function() {
  5783. this.$textCharMaxLength.val('123456789♥');
  5784. this.$textareaCharMaxLength.val('123456789♥');
  5785. this.$textUTF8BytesMaxLength.val('1234567♥');
  5786. this.$textareaUTF8BytesMaxLength.val('1234567♥');
  5787. this.bv.validate();
  5788. expect(this.bv.isValid()).toBeTruthy();
  5789. });
  5790. it('Valid min lengths', function() {
  5791. this.$textCharMinLength.val('1234♥');
  5792. this.$textareaCharMinLength.val('1234♥');
  5793. this.$textUTF8BytesMinLength.val('12♥');
  5794. this.$textareaUTF8BytesMinLength.val('12♥');
  5795. this.bv.validate();
  5796. expect(this.bv.isValid()).toBeTruthy();
  5797. });
  5798. it('Valid min and max lengths', function() {
  5799. this.$textCharMinMaxLength.val('1234♥');
  5800. this.$textareaCharMinMaxLength.val('1234♥');
  5801. this.$textUTF8BytesMinMaxLength.val('12♥');
  5802. this.$textareaUTF8BytesMinMaxLength.val('12♥');
  5803. this.bv.validate();
  5804. expect(this.bv.isValid()).toBeTruthy();
  5805. this.bv.resetForm();
  5806. this.$textCharMinMaxLength.val('123456789♥');
  5807. this.$textareaCharMinMaxLength.val('123456789♥');
  5808. this.$textUTF8BytesMinMaxLength.val('1234567♥');
  5809. this.$textareaUTF8BytesMinMaxLength.val('1234567♥');
  5810. this.bv.validate();
  5811. expect(this.bv.isValid()).toBeTruthy();
  5812. });
  5813. it('Invalid max lengths', function() {
  5814. this.$textCharMaxLength.val('1234567890♥'); // 11 chars when max is 10
  5815. this.bv.validate();
  5816. expect(this.bv.isValid()).toEqual(false);
  5817. this.bv.resetForm();
  5818. this.$textareaCharMaxLength.val('1234567890♥'); // 11 chars when max is 10
  5819. this.bv.validate();
  5820. expect(this.bv.isValid()).toEqual(false);
  5821. this.bv.resetForm();
  5822. this.$textUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10
  5823. this.bv.validate();
  5824. expect(this.bv.isValid()).toEqual(false);
  5825. this.bv.resetForm();
  5826. this.$textareaUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10
  5827. this.bv.validate();
  5828. expect(this.bv.isValid()).toEqual(false);
  5829. });
  5830. it('Invalid min lengths', function() {
  5831. this.$textCharMinLength.val('123♥'); // 4 chars when min is 5
  5832. this.bv.validate();
  5833. expect(this.bv.isValid()).toEqual(false);
  5834. this.bv.resetForm();
  5835. this.$textareaCharMinLength.val('123♥'); // 4 chars when min is 5
  5836. this.bv.validate();
  5837. expect(this.bv.isValid()).toEqual(false);
  5838. this.bv.resetForm();
  5839. this.$textUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5
  5840. this.bv.validate();
  5841. expect(this.bv.isValid()).toEqual(false);
  5842. this.bv.resetForm();
  5843. this.$textareaUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5
  5844. this.bv.validate();
  5845. expect(this.bv.isValid()).toEqual(false);
  5846. });
  5847. it('Invalid min and max lengths', function() {
  5848. this.$textCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10
  5849. this.bv.validate();
  5850. expect(this.bv.isValid()).toEqual(false);
  5851. this.bv.resetForm();
  5852. this.$textareaCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10
  5853. this.bv.validate();
  5854. expect(this.bv.isValid()).toEqual(false);
  5855. this.bv.resetForm();
  5856. this.$textUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10
  5857. this.bv.validate();
  5858. expect(this.bv.isValid()).toEqual(false);
  5859. this.bv.resetForm();
  5860. this.$textareaUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10
  5861. this.bv.validate();
  5862. expect(this.bv.isValid()).toEqual(false);
  5863. this.bv.resetForm();
  5864. this.$textCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10
  5865. this.bv.validate();
  5866. expect(this.bv.isValid()).toEqual(false);
  5867. this.bv.resetForm();
  5868. this.$textareaCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10
  5869. this.bv.validate();
  5870. expect(this.bv.isValid()).toEqual(false);
  5871. this.bv.resetForm();
  5872. this.$textUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10
  5873. this.bv.validate();
  5874. expect(this.bv.isValid()).toEqual(false);
  5875. this.bv.resetForm();
  5876. this.$textareaUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10
  5877. this.bv.validate();
  5878. expect(this.bv.isValid()).toEqual(false);
  5879. });
  5880. });
  5881. describe('rgbColor', function() {
  5882. beforeEach(function() {
  5883. var html = [
  5884. '<div class="container">',
  5885. '<form class="form-horizontal" id="rgbColorForm">',
  5886. '<div class="form-group">',
  5887. '<input type="text" name="rgb" data-bv-rgbcolor />',
  5888. '</div>',
  5889. '</form>',
  5890. '</div>'
  5891. ].join('\n');
  5892. $(html).appendTo('body');
  5893. $('#rgbColorForm').bootstrapValidator();
  5894. this.bv = $('#rgbColorForm').data('bootstrapValidator');
  5895. this.$rgbColor = this.bv.getFieldElements('rgb');
  5896. });
  5897. afterEach(function() {
  5898. $('#rgbColorForm').bootstrapValidator('destroy').parent().remove();
  5899. });
  5900. it('accept rgb()', function() {
  5901. this.$rgbColor.val('rgb(255,255,255)');
  5902. this.bv.validate();
  5903. expect(this.bv.isValidField('rgb')).toBeTruthy();
  5904. });
  5905. it('accept spaces around numeric values', function() {
  5906. this.$rgbColor.val('rgb( 255 , 255 , 255 )');
  5907. this.bv.validate();
  5908. expect(this.bv.isValidField('rgb')).toBeTruthy();
  5909. });
  5910. it('accept multiple spaces around numeric values', function() {
  5911. this.$rgbColor.val('rgb( 255, 255, 255 )');
  5912. this.bv.validate();
  5913. expect(this.bv.isValidField('rgb')).toBeTruthy();
  5914. });
  5915. it('accept interger values', function() {
  5916. this.$rgbColor.val('rgb(255,255,255)');
  5917. this.bv.validate();
  5918. expect(this.bv.isValidField('rgb')).toBeTruthy();
  5919. });
  5920. it('accept percent values', function() {
  5921. this.$rgbColor.val('rgb(100%,100%,100%)');
  5922. this.bv.validate();
  5923. expect(this.bv.isValidField('rgb')).toBeTruthy();
  5924. });
  5925. it('reject mixed intergers and percentile input', function() {
  5926. this.$rgbColor.val('rgb(255,255,100%)');
  5927. this.bv.validate();
  5928. expect(this.bv.isValidField('rgb')).toEqual(false);
  5929. });
  5930. it('reject negative integers', function() {
  5931. this.$rgbColor.val('rgb(-10,255,255)');
  5932. this.bv.validate();
  5933. expect(this.bv.isValidField('rgb')).toEqual(false);
  5934. });
  5935. it('reject negative percentages', function() {
  5936. this.$rgbColor.val('rgb(-10%,100%,100%)');
  5937. this.bv.validate();
  5938. expect(this.bv.isValidField('rgb')).toEqual(false);
  5939. });
  5940. it('require rgb()', function() {
  5941. this.$rgbColor.val('255,255,255');
  5942. this.bv.validate();
  5943. expect(this.bv.isValidField('rgb')).toEqual(false);
  5944. });
  5945. it('reject intergers above 255', function() {
  5946. this.$rgbColor.val('rgb(255,255,256)');
  5947. this.bv.validate();
  5948. expect(this.bv.isValidField('rgb')).toEqual(false);
  5949. });
  5950. it('reject percentages above 100%', function() {
  5951. this.$rgbColor.val('rgb(100%,100%,101%)');
  5952. this.bv.validate();
  5953. expect(this.bv.isValidField('rgb')).toEqual(false);
  5954. });
  5955. it('reject space between rgb and (', function() {
  5956. this.$rgbColor.val('rgb (255,255,255)');
  5957. this.bv.validate();
  5958. expect(this.bv.isValidField('rgb')).toEqual(false);
  5959. });
  5960. it('reject leading space', function() {
  5961. this.$rgbColor.val(' rgb(255,255,255)');
  5962. this.bv.validate();
  5963. expect(this.bv.isValidField('rgb')).toEqual(false);
  5964. });
  5965. it('reject trailing space', function() {
  5966. this.$rgbColor.val('rgb(255,255,255) ');
  5967. this.bv.validate();
  5968. expect(this.bv.isValidField('rgb')).toEqual(false);
  5969. });
  5970. });
  5971. describe('rgbaColor', function() {
  5972. beforeEach(function() {
  5973. var html = [
  5974. '<div class="container">',
  5975. <<<<<<< HEAD
  5976. '<form class="form-horizontal" id="rgbaColorForm">',
  5977. =======
  5978. '<form class="form-horizontal" id="rbgColorForm">',
  5979. >>>>>>> Add validator and test suite for rgba() color validation
  5980. '<div class="form-group">',
  5981. '<input type="text" name="rgba" data-bv-rgbacolor />',
  5982. '</div>',
  5983. '</form>',
  5984. '</div>'
  5985. ].join('\n');
  5986. $(html).appendTo('body');
  5987. <<<<<<< HEAD
  5988. $('#rgbaColorForm').bootstrapValidator();
  5989. this.bv = $('#rgbaColorForm').data('bootstrapValidator');
  5990. =======
  5991. $('#rbgColorForm').bootstrapValidator();
  5992. this.bv = $('#rbgColorForm').data('bootstrapValidator');
  5993. >>>>>>> Add validator and test suite for rgba() color validation
  5994. this.$rgbaColor = this.bv.getFieldElements('rgba');
  5995. });
  5996. afterEach(function() {
  5997. <<<<<<< HEAD
  5998. $('#rgbaColorForm').bootstrapValidator('destroy').parent().remove();
  5999. =======
  6000. $('#rbgColorForm').bootstrapValidator('destroy').parent().remove();
  6001. >>>>>>> Add validator and test suite for rgba() color validation
  6002. });
  6003. it('accept rgba()', function() {
  6004. this.$rgbaColor.val('rgba(255,255,255,1)');
  6005. this.bv.validate();
  6006. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6007. });
  6008. it('accept spaces around numeric values', function() {
  6009. this.$rgbaColor.val('rgba( 255 , 255 , 255 , 1 )');
  6010. this.bv.validate();
  6011. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6012. });
  6013. it('accept multiple spaces around numeric values', function() {
  6014. this.$rgbaColor.val('rgba( 255 , 255 , 255 , 1 )');
  6015. this.bv.validate();
  6016. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6017. });
  6018. it('accept interger values', function() {
  6019. this.$rgbaColor.val('rgba(255,255,255,1)');
  6020. this.bv.validate();
  6021. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6022. });
  6023. it('accept percent values', function() {
  6024. this.$rgbaColor.val('rgba(100%,100%,100%,1)');
  6025. this.bv.validate();
  6026. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6027. });
  6028. it('accept integer alpha channel value of 0', function() {
  6029. this.$rgbaColor.val('rgba(255,255,255,0)');
  6030. this.bv.validate();
  6031. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6032. });
  6033. it('accept integer alpha channel value of 1', function() {
  6034. this.$rgbaColor.val('rgba(255,255,255,1)');
  6035. this.bv.validate();
  6036. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6037. });
  6038. it('accept floating alpha channel with leading 0', function() {
  6039. this.$rgbaColor.val('rgba(255,255,255,0.5)');
  6040. this.bv.validate();
  6041. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6042. });
  6043. it('accept floating alpha channel without leading 0', function() {
  6044. this.$rgbaColor.val('rgba(255,255,255,.5)');
  6045. this.bv.validate();
  6046. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6047. });
  6048. it('accept floating alpha channel with more than 1 decimal place', function() {
  6049. this.$rgbaColor.val('rgba(255,255,255,.524141)');
  6050. this.bv.validate();
  6051. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6052. });
  6053. it('accept integer alpha channel value of 0 with percentage rgb values', function() {
  6054. this.$rgbaColor.val('rgba(100%,100%,100%,0)');
  6055. this.bv.validate();
  6056. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6057. });
  6058. it('accept integer alpha channel value of 1 with percentage rgb values', function() {
  6059. this.$rgbaColor.val('rgba(100%,100%,100%,1)');
  6060. this.bv.validate();
  6061. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6062. });
  6063. it('accept floating alpha channel with leading 0 with percentage rgb values', function() {
  6064. this.$rgbaColor.val('rgba(100%,100%,100%,0.5)');
  6065. this.bv.validate();
  6066. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6067. });
  6068. it('accept floating alpha channel without leading 0 with percentage rgb values', function() {
  6069. this.$rgbaColor.val('rgba(100%,100%,100%,.5)');
  6070. this.bv.validate();
  6071. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6072. });
  6073. it('accept floating alpha channel with more than 1 decimal place with percentage rgb values', function() {
  6074. this.$rgbaColor.val('rgba(100%,100%,100%,.524141)');
  6075. this.bv.validate();
  6076. expect(this.bv.isValidField('rgba')).toBeTruthy();
  6077. });
  6078. it('reject percentage value for alpha channel', function() {
  6079. this.$rgbaColor.val('rgba(100%,100%,100%,50%)');
  6080. this.bv.validate();
  6081. expect(this.bv.isValidField('rgba')).toEqual(false);
  6082. });
  6083. it('reject integers larger than 1 for alpha channel', function() {
  6084. this.$rgbaColor.val('rgba(255,255,255,2)');
  6085. this.bv.validate();
  6086. expect(this.bv.isValidField('rgba')).toEqual(false);
  6087. });
  6088. it('reject negative integers for alpha channel', function() {
  6089. this.$rgbaColor.val('rgba(255,255,255,-1)');
  6090. this.bv.validate();
  6091. expect(this.bv.isValidField('rgba')).toEqual(false);
  6092. });
  6093. it('reject floats larger than 1 for alpha channel', function() {
  6094. this.$rgbaColor.val('rgba(255,255,255,1.000000000001)');
  6095. this.bv.validate();
  6096. expect(this.bv.isValidField('rgba')).toEqual(false);
  6097. });
  6098. it('reject negative floats for alpha channel', function() {
  6099. this.$rgbaColor.val('rgba(255,255,255,-0.5)');
  6100. this.bv.validate();
  6101. expect(this.bv.isValidField('rgba')).toEqual(false);
  6102. });
  6103. it('reject more floats larger than 1 for alpha channel', function() {
  6104. this.$rgbaColor.val('rgba(255,255,255,2.3)');
  6105. this.bv.validate();
  6106. expect(this.bv.isValidField('rgba')).toEqual(false);
  6107. });
  6108. it('reject mixed intergers and percentile input', function() {
  6109. this.$rgbaColor.val('rgba(255,255,100%,1)');
  6110. this.bv.validate();
  6111. expect(this.bv.isValidField('rgba')).toEqual(false);
  6112. });
  6113. it('reject negative integers', function() {
  6114. this.$rgbaColor.val('rgba(-10,255,255,1)');
  6115. this.bv.validate();
  6116. expect(this.bv.isValidField('rgba')).toEqual(false);
  6117. });
  6118. it('reject negative percentages', function() {
  6119. this.$rgbaColor.val('rgba(-10%,100%,100%,1)');
  6120. this.bv.validate();
  6121. expect(this.bv.isValidField('rgba')).toEqual(false);
  6122. });
  6123. it('require rgba()', function() {
  6124. this.$rgbaColor.val('255,255,255,1');
  6125. this.bv.validate();
  6126. expect(this.bv.isValidField('rgba')).toEqual(false);
  6127. });
  6128. it('reject intergers above 255', function() {
  6129. this.$rgbaColor.val('rgba(255,255,256),1');
  6130. this.bv.validate();
  6131. expect(this.bv.isValidField('rgba')).toEqual(false);
  6132. });
  6133. it('reject percentages above 100%', function() {
  6134. this.$rgbaColor.val('rgba(100%,100%,101%,1)');
  6135. this.bv.validate();
  6136. expect(this.bv.isValidField('rgba')).toEqual(false);
  6137. });
  6138. it('reject space between rgba and (', function() {
  6139. this.$rgbaColor.val('rgba (255,255,255,1)');
  6140. this.bv.validate();
  6141. expect(this.bv.isValidField('rgba')).toEqual(false);
  6142. });
  6143. it('reject leading space', function() {
  6144. this.$rgbaColor.val(' rgba(255,255,255,1)');
  6145. this.bv.validate();
  6146. expect(this.bv.isValidField('rgba')).toEqual(false);
  6147. });
  6148. it('reject trailing space', function() {
  6149. this.$rgbaColor.val('rgba(255,255,255,1) ');
  6150. this.bv.validate();
  6151. expect(this.bv.isValidField('rgba')).toEqual(false);
  6152. });
  6153. });
  6154. describe('uri', function() {
  6155. beforeEach(function() {
  6156. $([
  6157. '<form class="form-horizontal" id="uriForm">',
  6158. '<div id="msg"></div>',
  6159. '<div class="form-group">',
  6160. '<input type="text" name="uri" data-bv-uri />',
  6161. '</div>',
  6162. '</form>'
  6163. ].join('\n')).appendTo('body');
  6164. $('#uriForm').bootstrapValidator();
  6165. this.bv = $('#uriForm').data('bootstrapValidator');
  6166. this.$uri = this.bv.getFieldElements('uri');
  6167. });
  6168. afterEach(function() {
  6169. $('#uriForm').bootstrapValidator('destroy').remove();
  6170. });
  6171. var validGlobalURIs = [
  6172. 'http://foo.com/blah_blah',
  6173. 'http://foo.com/blah_blah',
  6174. 'http://foo.com/blah_blah/',
  6175. 'http://foo.com/blah_blah_(wikipedia)',
  6176. 'http://foo.com/blah_blah_(wikipedia)_(again)',
  6177. 'http://www.example.com/wpstyle/?p=364',
  6178. 'https://www.example.com/foo/?bar=baz&inga=42&quux',
  6179. 'http://✪df.ws/123',
  6180. 'http://userid:password@example.com:8080',
  6181. 'http://userid:password@example.com:8080/',
  6182. 'http://userid@example.com',
  6183. 'http://userid@example.com/',
  6184. 'http://userid@example.com:8080',
  6185. 'http://userid@example.com:8080/',
  6186. 'http://userid:password@example.com',
  6187. 'http://userid:password@example.com/',
  6188. 'http://142.42.1.1/',
  6189. 'http://142.42.1.1:8080/',
  6190. 'http://➡.ws/䨹',
  6191. 'http://⌘.ws',
  6192. 'http://⌘.ws/',
  6193. 'http://foo.com/blah_(wikipedia)#cite-1',
  6194. 'http://foo.com/blah_(wikipedia)_blah#cite-1',
  6195. 'http://foo.com/unicode_(✪)_in_parens',
  6196. 'http://foo.com/(something)?after=parens',
  6197. 'http://☺.damowmow.com/',
  6198. 'http://code.google.com/events/#&product=browser',
  6199. 'http://j.mp',
  6200. 'ftp://foo.bar/baz',
  6201. 'http://foo.bar/?q=Test%20URL-encoded%20stuff',
  6202. 'http://مثال.إختبار',
  6203. 'http://例子.测试',
  6204. 'http://उदाहरण.परीक्षा',
  6205. "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
  6206. 'http://1337.net',
  6207. 'http://a.b-c.de',
  6208. 'http://223.255.255.254'
  6209. ];
  6210. var invalidGlobalURIs = [
  6211. 'http://',
  6212. 'http://.',
  6213. 'http://..',
  6214. 'http://../',
  6215. 'http://?',
  6216. 'http://??',
  6217. 'http://??/',
  6218. 'http://#',
  6219. 'http://##',
  6220. 'http://##/',
  6221. 'http://foo.bar?q=Spaces should be encoded',
  6222. '//',
  6223. '//a',
  6224. '///a',
  6225. '///',
  6226. 'http:///a',
  6227. 'foo.com',
  6228. 'rdar://1234',
  6229. 'h://test',
  6230. 'http:// shouldfail.com',
  6231. ':// should fail',
  6232. 'http://foo.bar/foo(bar)baz quux',
  6233. 'ftps://foo.bar/',
  6234. 'http://-error-.invalid/',
  6235. 'http://a.b--c.de/',
  6236. 'http://-a.b.co',
  6237. 'http://a.b-.co',
  6238. 'http://.www.foo.bar/',
  6239. 'http://www.foo.bar./',
  6240. 'http://.www.foo.bar./'
  6241. ];
  6242. var localURIs = [
  6243. 'http://intranetsite',
  6244. 'http://intranetsite/test',
  6245. 'http://intranetsite:80',
  6246. 'http://intranetsite:80/test',
  6247. 'http://user:pass@intranetsite',
  6248. 'http://user:pass@intranetsite/test',
  6249. 'http://user:pass@intranetsite:80',
  6250. 'http://user:pass@intranetsite:80/test',
  6251. 'http://10.1.1.0',
  6252. 'http://10.1.1.255',
  6253. 'http://10.1.1.1',
  6254. 'http://10.1.1.254',
  6255. 'http://127.0.0.1',
  6256. 'http://192.168.0.1',
  6257. 'http://0.0.0.0',
  6258. 'http://224.1.1.1',
  6259. 'http://1.1.1.1.1',
  6260. 'http://123.123.123',
  6261. 'http://3628126748'
  6262. ];
  6263. it('Valid URIs (allowLocal=false)', function() {
  6264. var me = this;
  6265. $.each(validGlobalURIs, function(index, uri) {
  6266. me.bv.resetForm();
  6267. me.$uri.val(uri);
  6268. me.bv.validate();
  6269. expect(me.bv.isValid()).toBeTruthy();
  6270. });
  6271. });
  6272. it('Invalid URIs (allowLocal=false)', function() {
  6273. var me = this;
  6274. $.each(invalidGlobalURIs.concat(localURIs), function(index, uri) {
  6275. me.bv.resetForm();
  6276. me.$uri.val(uri);
  6277. me.bv.validate();
  6278. expect(me.bv.isValid()).toEqual(false);
  6279. });
  6280. });
  6281. it('Valid URIs (allowLocal=true)', function() {
  6282. var me = this;
  6283. me.bv.updateOption('uri', 'uri', 'allowLocal', true);
  6284. $.each(validGlobalURIs.concat(localURIs), function(index, uri) {
  6285. me.bv.resetForm();
  6286. me.$uri.val(uri);
  6287. me.bv.validate();
  6288. expect(me.bv.isValid()).toBeTruthy();
  6289. });
  6290. });
  6291. it('Invalid URIs (allowLocal=true)', function() {
  6292. var me = this;
  6293. me.bv.updateOption('uri', 'uri', 'allowLocal', true);
  6294. $.each(invalidGlobalURIs, function(index, uri) {
  6295. me.bv.resetForm();
  6296. me.$uri.val(uri);
  6297. me.bv.validate();
  6298. expect(me.bv.isValid()).toEqual(false);
  6299. });
  6300. });
  6301. });
  6302. describe('vat', function() {
  6303. beforeEach(function() {
  6304. $([
  6305. '<form class="form-horizontal" id="vatForm">',
  6306. '<div class="form-group">',
  6307. '<select class="form-control" name="country">',
  6308. '<option value="AT">Austria</option>',
  6309. '<option value="BE">Belgium</option>',
  6310. '<option value="BG">Bulgaria</option>',
  6311. '<option value="HR">Croatia</option>',
  6312. '<option value="CY">Cyprus</option>',
  6313. '<option value="CZ">Czech Republic</option>',
  6314. '<option value="DK">Denmark</option>',
  6315. '<option value="EE">Estonia</option>',
  6316. '<option value="FI">Finland</option>',
  6317. '<option value="FR">France</option>',
  6318. '<option value="DE">Germany</option>',
  6319. '<option value="GR">Greece</option>',
  6320. '<option value="HU">Hungary</option>',
  6321. '<option value="IE">Ireland</option>',
  6322. '<option value="IS">Iceland</option>',
  6323. '<option value="IT">Italy</option>',
  6324. '<option value="LV">Latvia</option>',
  6325. '<option value="LT">Lithuania</option>',
  6326. '<option value="LU">Luxembourg</option>',
  6327. '<option value="MT">Malta</option>',
  6328. '<option value="NL">Netherlands</option>',
  6329. '<option value="NO">Norway</option>',
  6330. '<option value="PL">Poland</option>',
  6331. '<option value="PT">Portugal</option>',
  6332. '<option value="RO">Romania</option>',
  6333. '<option value="RU">Russia</option>',
  6334. '<option value="RS">Serbia</option>',
  6335. '<option value="SK">Slovakia</option>',
  6336. '<option value="SI">Slovenia</option>',
  6337. '<option value="ES">Spain</option>',
  6338. '<option value="SE">Sweden</option>',
  6339. '<option value="CH">Switzerland</option>',
  6340. '<option value="GB">United Kingdom</option>',
  6341. '<option value="VE">Venezuela</option>',
  6342. '<option value="ZA">South Africa</option>',
  6343. '</select>',
  6344. '</div>',
  6345. '<div class="form-group">',
  6346. '<input type="text" name="vat" data-bv-vat />',
  6347. '</div>',
  6348. '</form>',
  6349. ].join('\n')).appendTo('body');
  6350. $('#vatForm').bootstrapValidator();
  6351. /**
  6352. * @type {BootstrapValidator}
  6353. */
  6354. this.bv = $('#vatForm').data('bootstrapValidator');
  6355. this.$country = this.bv.getFieldElements('country');
  6356. this.$vat = this.bv.getFieldElements('vat');
  6357. });
  6358. afterEach(function() {
  6359. $('#vatForm').bootstrapValidator('destroy').remove();
  6360. });
  6361. it('dynamic country', function() {
  6362. this.$vat.attr('data-bv-vat-country', 'country');
  6363. this.bv.destroy();
  6364. this.bv = $('#vatForm').bootstrapValidator().data('bootstrapValidator');
  6365. this.$country.val('AT');
  6366. this.$vat.val('ATU13585627');
  6367. this.bv.validate();
  6368. expect(this.bv.isValid()).toBeTruthy();
  6369. this.bv.resetForm();
  6370. this.$country.val('BG');
  6371. this.$vat.val('BE0428759497');
  6372. this.bv.validate();
  6373. expect(this.bv.isValid()).toEqual(false);
  6374. this.bv.resetForm();
  6375. this.$country.val('BE');
  6376. this.$vat.val('BE431150351');
  6377. this.bv.validate();
  6378. expect(this.bv.isValid()).toEqual(false);
  6379. });
  6380. it('Austrian VAT number', function() {
  6381. this.bv.updateOption('vat', 'vat', 'country', 'AT');
  6382. // Valid samples
  6383. var validSamples = ['ATU13585627', 'U13585627'];
  6384. for (var i in validSamples) {
  6385. this.bv.resetForm();
  6386. this.$vat.val(validSamples[i]);
  6387. this.bv.validate();
  6388. expect(this.bv.isValid()).toBeTruthy();
  6389. }
  6390. // Invalid samples
  6391. var invalidSamples = ['ATU13585626', 'U13585626'];
  6392. for (i in invalidSamples) {
  6393. this.bv.resetForm();
  6394. this.$vat.val(invalidSamples[i]);
  6395. this.bv.validate();
  6396. expect(this.bv.isValid()).toEqual(false);
  6397. }
  6398. });
  6399. it('Belgian VAT number', function() {
  6400. this.bv.updateOption('vat', 'vat', 'country', 'BE');
  6401. // Valid samples
  6402. var validSamples = ['BE0428759497', '0428759497'];
  6403. for (var i in validSamples) {
  6404. this.bv.resetForm();
  6405. this.$vat.val(validSamples[i]);
  6406. this.bv.validate();
  6407. expect(this.bv.isValid()).toBeTruthy();
  6408. }
  6409. // Invalid samples
  6410. var invalidSamples = ['BE431150351', '431150351'];
  6411. for (i in invalidSamples) {
  6412. this.bv.resetForm();
  6413. this.$vat.val(invalidSamples[i]);
  6414. this.bv.validate();
  6415. expect(this.bv.isValid()).toEqual(false);
  6416. }
  6417. });
  6418. it('Bulgarian VAT number', function() {
  6419. this.bv.updateOption('vat', 'vat', 'country', 'BG');
  6420. // Valid samples
  6421. var validSamples = ['BG175074752', 'BG7523169263', 'BG8032056031', 'BG7542011030', 'BG7111042925', '175074752', '7523169263', '8032056031'];
  6422. for (var i in validSamples) {
  6423. this.bv.resetForm();
  6424. this.$vat.val(validSamples[i]);
  6425. this.bv.validate();
  6426. expect(this.bv.isValid()).toBeTruthy();
  6427. }
  6428. // Invalid samples
  6429. var invalidSamples = ['BG175074753', 'BG7552A10004', 'BG7111042922', '175074753', '7552A10004'];
  6430. for (i in invalidSamples) {
  6431. this.bv.resetForm();
  6432. this.$vat.val(invalidSamples[i]);
  6433. this.bv.validate();
  6434. expect(this.bv.isValid()).toEqual(false);
  6435. }
  6436. });
  6437. it('Cypriot VAT number', function() {
  6438. this.bv.updateOption('vat', 'vat', 'country', 'CY');
  6439. // Valid samples
  6440. var validSamples = ['CY10259033P', '10259033P'];
  6441. for (var i in validSamples) {
  6442. this.bv.resetForm();
  6443. this.$vat.val(validSamples[i]);
  6444. this.bv.validate();
  6445. expect(this.bv.isValid()).toBeTruthy();
  6446. }
  6447. // Invalid samples
  6448. var invalidSamples = ['CY10259033Z', '10259033Z'];
  6449. for (i in invalidSamples) {
  6450. this.bv.resetForm();
  6451. this.$vat.val(invalidSamples[i]);
  6452. this.bv.validate();
  6453. expect(this.bv.isValid()).toEqual(false);
  6454. }
  6455. });
  6456. it('Czech Republic VAT number', function() {
  6457. this.bv.updateOption('vat', 'vat', 'country', 'CZ');
  6458. // Valid samples
  6459. var validSamples = ['CZ25123891', 'CZ7103192745', 'CZ991231123', 'CZ640903926', '25123891', '7103192745'];
  6460. for (var i in validSamples) {
  6461. this.bv.resetForm();
  6462. this.$vat.val(validSamples[i]);
  6463. this.bv.validate();
  6464. expect(this.bv.isValid()).toBeTruthy();
  6465. }
  6466. // Invalid samples
  6467. var invalidSamples = ['CZ25123890', 'CZ1103492745', 'CZ590312123', '25123890', '1103492745'];
  6468. for (i in invalidSamples) {
  6469. this.bv.resetForm();
  6470. this.$vat.val(invalidSamples[i]);
  6471. this.bv.validate();
  6472. expect(this.bv.isValid()).toEqual(false);
  6473. }
  6474. });
  6475. it('German VAT number', function() {
  6476. this.bv.updateOption('vat', 'vat', 'country', 'DE');
  6477. // Valid samples
  6478. var validSamples = ['DE136695976', '136695976'];
  6479. for (var i in validSamples) {
  6480. this.bv.resetForm();
  6481. this.$vat.val(validSamples[i]);
  6482. this.bv.validate();
  6483. expect(this.bv.isValid()).toBeTruthy();
  6484. }
  6485. // Invalid samples
  6486. var invalidSamples = ['DE136695978', '136695978'];
  6487. for (i in invalidSamples) {
  6488. this.bv.resetForm();
  6489. this.$vat.val(invalidSamples[i]);
  6490. this.bv.validate();
  6491. expect(this.bv.isValid()).toEqual(false);
  6492. }
  6493. });
  6494. it('Danish VAT number', function() {
  6495. this.bv.updateOption('vat', 'vat', 'country', 'DK');
  6496. // Valid samples
  6497. var validSamples = ['DK13585628', '13585628'];
  6498. for (var i in validSamples) {
  6499. this.bv.resetForm();
  6500. this.$vat.val(validSamples[i]);
  6501. this.bv.validate();
  6502. expect(this.bv.isValid()).toBeTruthy();
  6503. }
  6504. // Invalid samples
  6505. var invalidSamples = ['DK13585627', '13585627'];
  6506. for (i in invalidSamples) {
  6507. this.bv.resetForm();
  6508. this.$vat.val(invalidSamples[i]);
  6509. this.bv.validate();
  6510. expect(this.bv.isValid()).toEqual(false);
  6511. }
  6512. });
  6513. it('Estonian VAT number', function() {
  6514. this.bv.updateOption('vat', 'vat', 'country', 'EE');
  6515. // Valid samples
  6516. var validSamples = ['EE100931558', 'EE100594102', '100931558', '100594102'];
  6517. for (var i in validSamples) {
  6518. this.bv.resetForm();
  6519. this.$vat.val(validSamples[i]);
  6520. this.bv.validate();
  6521. expect(this.bv.isValid()).toBeTruthy();
  6522. }
  6523. // Invalid samples
  6524. var invalidSamples = ['EE100594103', '100594103'];
  6525. for (i in invalidSamples) {
  6526. this.bv.resetForm();
  6527. this.$vat.val(invalidSamples[i]);
  6528. this.bv.validate();
  6529. expect(this.bv.isValid()).toEqual(false);
  6530. }
  6531. });
  6532. it('Spanish VAT number (NIF)', function() {
  6533. this.bv.updateOption('vat', 'vat', 'country', 'ES');
  6534. // Valid samples
  6535. var validSamples = ['ES54362315K', 'ESX2482300W', 'ESX5253868R', 'ESM1234567L', 'ESJ99216582', 'ESB58378431', 'ESB64717838', '54362315K', 'X2482300W', 'X5253868R', 'M1234567L', 'J99216582'];
  6536. for (var i in validSamples) {
  6537. this.bv.resetForm();
  6538. this.$vat.val(validSamples[i]);
  6539. this.bv.validate();
  6540. expect(this.bv.isValid()).toBeTruthy();
  6541. }
  6542. // Invalid samples
  6543. var invalidSamples = ['ES54362315Z', 'ESX2482300A', 'ESJ99216583', '54362315Z', 'X2482300A'];
  6544. for (i in invalidSamples) {
  6545. this.bv.resetForm();
  6546. this.$vat.val(invalidSamples[i]);
  6547. this.bv.validate();
  6548. expect(this.bv.isValid()).toEqual(false);
  6549. }
  6550. });
  6551. it('Finnish VAT number', function() {
  6552. this.bv.updateOption('vat', 'vat', 'country', 'FI');
  6553. // Valid samples
  6554. var validSamples = ['FI20774740', '20774740'];
  6555. for (var i in validSamples) {
  6556. this.bv.resetForm();
  6557. this.$vat.val(validSamples[i]);
  6558. this.bv.validate();
  6559. expect(this.bv.isValid()).toBeTruthy();
  6560. }
  6561. // Invalid samples
  6562. var invalidSamples = ['FI20774741', '20774741'];
  6563. for (i in invalidSamples) {
  6564. this.bv.resetForm();
  6565. this.$vat.val(invalidSamples[i]);
  6566. this.bv.validate();
  6567. expect(this.bv.isValid()).toEqual(false);
  6568. }
  6569. });
  6570. it('French VAT number (TVA)', function() {
  6571. this.bv.updateOption('vat', 'vat', 'country', 'FR');
  6572. // Valid samples
  6573. var validSamples = ['FR40303265045', 'FR23334175221', 'FRK7399859412', 'FR4Z123456782', '40303265045', '23334175221', 'K7399859412'];
  6574. for (var i in validSamples) {
  6575. this.bv.resetForm();
  6576. this.$vat.val(validSamples[i]);
  6577. this.bv.validate();
  6578. expect(this.bv.isValid()).toBeTruthy();
  6579. }
  6580. // Invalid samples
  6581. var invalidSamples = ['FR84323140391', '84323140391'];
  6582. for (i in invalidSamples) {
  6583. this.bv.resetForm();
  6584. this.$vat.val(invalidSamples[i]);
  6585. this.bv.validate();
  6586. expect(this.bv.isValid()).toEqual(false);
  6587. }
  6588. });
  6589. it('United Kingdom VAT number', function() {
  6590. this.bv.updateOption('vat', 'vat', 'country', 'GB');
  6591. // Valid samples
  6592. var validSamples = ['GB980780684', '980780684'];
  6593. for (var i in validSamples) {
  6594. this.bv.resetForm();
  6595. this.$vat.val(validSamples[i]);
  6596. this.bv.validate();
  6597. expect(this.bv.isValid()).toBeTruthy();
  6598. }
  6599. // Invalid samples
  6600. var invalidSamples = ['GB802311781', '802311781'];
  6601. for (i in invalidSamples) {
  6602. this.bv.resetForm();
  6603. this.$vat.val(invalidSamples[i]);
  6604. this.bv.validate();
  6605. expect(this.bv.isValid()).toEqual(false);
  6606. }
  6607. });
  6608. it('Greek VAT number', function() {
  6609. this.bv.updateOption('vat', 'vat', 'country', 'GR');
  6610. // Valid samples
  6611. var validSamples = ['GR023456780', 'EL094259216', '023456780', '094259216'];
  6612. for (var i in validSamples) {
  6613. this.bv.resetForm();
  6614. this.$vat.val(validSamples[i]);
  6615. this.bv.validate();
  6616. expect(this.bv.isValid()).toBeTruthy();
  6617. }
  6618. // Invalid samples
  6619. var invalidSamples = ['GR123456781', '123456781'];
  6620. for (i in invalidSamples) {
  6621. this.bv.resetForm();
  6622. this.$vat.val(invalidSamples[i]);
  6623. this.bv.validate();
  6624. expect(this.bv.isValid()).toEqual(false);
  6625. }
  6626. });
  6627. it('Hungarian VAT number', function() {
  6628. this.bv.updateOption('vat', 'vat', 'country', 'HU');
  6629. // Valid samples
  6630. var validSamples = ['HU12892312', '12892312'];
  6631. for (var i in validSamples) {
  6632. this.bv.resetForm();
  6633. this.$vat.val(validSamples[i]);
  6634. this.bv.validate();
  6635. expect(this.bv.isValid()).toBeTruthy();
  6636. }
  6637. // Invalid samples
  6638. var invalidSamples = ['HU12892313', '12892313'];
  6639. for (i in invalidSamples) {
  6640. this.bv.resetForm();
  6641. this.$vat.val(invalidSamples[i]);
  6642. this.bv.validate();
  6643. expect(this.bv.isValid()).toEqual(false);
  6644. }
  6645. });
  6646. it('Croatian VAT number', function() {
  6647. this.bv.updateOption('vat', 'vat', 'country', 'HR');
  6648. // Valid samples
  6649. var validSamples = ['HR33392005961', '33392005961'];
  6650. for (var i in validSamples) {
  6651. this.bv.resetForm();
  6652. this.$vat.val(validSamples[i]);
  6653. this.bv.validate();
  6654. expect(this.bv.isValid()).toBeTruthy();
  6655. }
  6656. // Invalid samples
  6657. var invalidSamples = ['HR33392005962', '33392005962'];
  6658. for (i in invalidSamples) {
  6659. this.bv.resetForm();
  6660. this.$vat.val(invalidSamples[i]);
  6661. this.bv.validate();
  6662. expect(this.bv.isValid()).toEqual(false);
  6663. }
  6664. });
  6665. it('Irish VAT number', function() {
  6666. this.bv.updateOption('vat', 'vat', 'country', 'IE');
  6667. // Valid samples
  6668. var validSamples = ['IE6433435F', 'IE6433435OA', 'IE8D79739I', '6433435F', '6433435OA', '8D79739I'];
  6669. for (var i in validSamples) {
  6670. this.bv.resetForm();
  6671. this.$vat.val(validSamples[i]);
  6672. this.bv.validate();
  6673. expect(this.bv.isValid()).toBeTruthy();
  6674. }
  6675. // Invalid samples
  6676. var invalidSamples = ['IE8D79738J', '8D79738J'];
  6677. for (i in invalidSamples) {
  6678. this.bv.resetForm();
  6679. this.$vat.val(invalidSamples[i]);
  6680. this.bv.validate();
  6681. expect(this.bv.isValid()).toEqual(false);
  6682. }
  6683. });
  6684. it('Iceland VAT (VSK) number', function() {
  6685. this.bv.updateOption('vat', 'vat', 'country', 'IS');
  6686. // Valid samples
  6687. var validSamples = ['IS11111', 'IS111111', '11111', '111111'];
  6688. for (var i in validSamples) {
  6689. this.bv.resetForm();
  6690. this.$vat.val(validSamples[i]);
  6691. this.bv.validate();
  6692. expect(this.bv.isValid()).toBeTruthy();
  6693. }
  6694. // Invalid samples
  6695. var invalidSamples = ['IS1234567', 'IS123456ABC', '1234567', '123456ABC'];
  6696. for (i in invalidSamples) {
  6697. this.bv.resetForm();
  6698. this.$vat.val(invalidSamples[i]);
  6699. this.bv.validate();
  6700. expect(this.bv.isValid()).toEqual(false);
  6701. }
  6702. });
  6703. it('Italian VAT number', function() {
  6704. this.bv.updateOption('vat', 'vat', 'country', 'IT');
  6705. // Valid samples
  6706. var validSamples = ['IT00743110157', '00743110157'];
  6707. for (var i in validSamples) {
  6708. this.bv.resetForm();
  6709. this.$vat.val(validSamples[i]);
  6710. this.bv.validate();
  6711. expect(this.bv.isValid()).toBeTruthy();
  6712. }
  6713. // Invalid samples
  6714. var invalidSamples = ['IT00743110158', '00743110158'];
  6715. for (i in invalidSamples) {
  6716. this.bv.resetForm();
  6717. this.$vat.val(invalidSamples[i]);
  6718. this.bv.validate();
  6719. expect(this.bv.isValid()).toEqual(false);
  6720. }
  6721. });
  6722. it('Lithuanian VAT number', function() {
  6723. this.bv.updateOption('vat', 'vat', 'country', 'LT');
  6724. // Valid samples
  6725. var validSamples = ['LT119511515', 'LT100001919017', 'LT100004801610', '119511515', '100001919017', '100004801610'];
  6726. for (var i in validSamples) {
  6727. this.bv.resetForm();
  6728. this.$vat.val(validSamples[i]);
  6729. this.bv.validate();
  6730. expect(this.bv.isValid()).toBeTruthy();
  6731. }
  6732. // Invalid samples
  6733. var invalidSamples = ['LT100001919018', '100001919018'];
  6734. for (i in invalidSamples) {
  6735. this.bv.resetForm();
  6736. this.$vat.val(invalidSamples[i]);
  6737. this.bv.validate();
  6738. expect(this.bv.isValid()).toEqual(false);
  6739. }
  6740. });
  6741. it('Luxembourg VAT number', function() {
  6742. this.bv.updateOption('vat', 'vat', 'country', 'LU');
  6743. // Valid samples
  6744. var validSamples = ['LU15027442', '15027442'];
  6745. for (var i in validSamples) {
  6746. this.bv.resetForm();
  6747. this.$vat.val(validSamples[i]);
  6748. this.bv.validate();
  6749. expect(this.bv.isValid()).toBeTruthy();
  6750. }
  6751. // Invalid samples
  6752. var invalidSamples = ['LU15027443', '15027443'];
  6753. for (i in invalidSamples) {
  6754. this.bv.resetForm();
  6755. this.$vat.val(invalidSamples[i]);
  6756. this.bv.validate();
  6757. expect(this.bv.isValid()).toEqual(false);
  6758. }
  6759. });
  6760. it('Latvian VAT number', function() {
  6761. this.bv.updateOption('vat', 'vat', 'country', 'LV');
  6762. // Valid samples
  6763. var validSamples = ['LV40003521600', 'LV16117519997', '40003521600', '16117519997'];
  6764. for (var i in validSamples) {
  6765. this.bv.resetForm();
  6766. this.$vat.val(validSamples[i]);
  6767. this.bv.validate();
  6768. expect(this.bv.isValid()).toBeTruthy();
  6769. }
  6770. // Invalid samples
  6771. var invalidSamples = ['LV40003521601', 'LV16137519997', '40003521601', '16137519997'];
  6772. for (i in invalidSamples) {
  6773. this.bv.resetForm();
  6774. this.$vat.val(invalidSamples[i]);
  6775. this.bv.validate();
  6776. expect(this.bv.isValid()).toEqual(false);
  6777. }
  6778. });
  6779. it('Maltese VAT number', function() {
  6780. this.bv.updateOption('vat', 'vat', 'country', 'MT');
  6781. // Valid samples
  6782. var validSamples = ['MT11679112', '11679112'];
  6783. for (var i in validSamples) {
  6784. this.bv.resetForm();
  6785. this.$vat.val(validSamples[i]);
  6786. this.bv.validate();
  6787. expect(this.bv.isValid()).toBeTruthy();
  6788. }
  6789. // Invalid samples
  6790. var invalidSamples = ['MT11679113', '11679113'];
  6791. for (i in invalidSamples) {
  6792. this.bv.resetForm();
  6793. this.$vat.val(invalidSamples[i]);
  6794. this.bv.validate();
  6795. expect(this.bv.isValid()).toEqual(false);
  6796. }
  6797. });
  6798. it('Dutch VAT number', function() {
  6799. this.bv.updateOption('vat', 'vat', 'country', 'NL');
  6800. // Valid samples
  6801. var validSamples = ['NL004495445B01', '004495445B01'];
  6802. for (var i in validSamples) {
  6803. this.bv.resetForm();
  6804. this.$vat.val(validSamples[i]);
  6805. this.bv.validate();
  6806. expect(this.bv.isValid()).toBeTruthy();
  6807. }
  6808. // Invalid samples
  6809. var invalidSamples = ['NL123456789B90', '123456789B90'];
  6810. for (i in invalidSamples) {
  6811. this.bv.resetForm();
  6812. this.$vat.val(invalidSamples[i]);
  6813. this.bv.validate();
  6814. expect(this.bv.isValid()).toEqual(false);
  6815. }
  6816. });
  6817. it('Polish VAT number', function() {
  6818. this.bv.updateOption('vat', 'vat', 'country', 'PL');
  6819. // Valid samples
  6820. var validSamples = ['PL8567346215', '8567346215'];
  6821. for (var i in validSamples) {
  6822. this.bv.resetForm();
  6823. this.$vat.val(validSamples[i]);
  6824. this.bv.validate();
  6825. expect(this.bv.isValid()).toBeTruthy();
  6826. }
  6827. // Invalid samples
  6828. var invalidSamples = ['PL8567346216', '8567346216'];
  6829. for (i in invalidSamples) {
  6830. this.bv.resetForm();
  6831. this.$vat.val(invalidSamples[i]);
  6832. this.bv.validate();
  6833. expect(this.bv.isValid()).toEqual(false);
  6834. }
  6835. });
  6836. it('Portuguese VAT number', function() {
  6837. this.bv.updateOption('vat', 'vat', 'country', 'PT');
  6838. // Valid samples
  6839. var validSamples = ['PT501964843', '501964843'];
  6840. for (var i in validSamples) {
  6841. this.bv.resetForm();
  6842. this.$vat.val(validSamples[i]);
  6843. this.bv.validate();
  6844. expect(this.bv.isValid()).toBeTruthy();
  6845. }
  6846. // Invalid samples
  6847. var invalidSamples = ['PT501964842', '501964842'];
  6848. for (i in invalidSamples) {
  6849. this.bv.resetForm();
  6850. this.$vat.val(invalidSamples[i]);
  6851. this.bv.validate();
  6852. expect(this.bv.isValid()).toEqual(false);
  6853. }
  6854. });
  6855. it('Romanian VAT number', function() {
  6856. this.bv.updateOption('vat', 'vat', 'country', 'RO');
  6857. // Valid samples
  6858. var validSamples = ['RO18547290', '18547290'];
  6859. for (var i in validSamples) {
  6860. this.bv.resetForm();
  6861. this.$vat.val(validSamples[i]);
  6862. this.bv.validate();
  6863. expect(this.bv.isValid()).toBeTruthy();
  6864. }
  6865. // Invalid samples
  6866. var invalidSamples = ['RO18547291', '18547291'];
  6867. for (i in invalidSamples) {
  6868. this.bv.resetForm();
  6869. this.$vat.val(invalidSamples[i]);
  6870. this.bv.validate();
  6871. expect(this.bv.isValid()).toEqual(false);
  6872. }
  6873. });
  6874. it('Russian VAT number', function() {
  6875. this.bv.updateOption('vat', 'vat', 'country', 'RU');
  6876. // Valid samples
  6877. var validSamples = ['RU7805145876', 'RU781300557475', '7805145876', '781300557475'];
  6878. for (var i in validSamples) {
  6879. this.bv.resetForm();
  6880. this.$vat.val(validSamples[i]);
  6881. this.bv.validate();
  6882. expect(this.bv.isValid()).toBeTruthy();
  6883. }
  6884. // Invalid samples
  6885. var invalidSamples = ['RU7805145877', 'RU781300557474', '7805145877', '781300557474'];
  6886. for (i in invalidSamples) {
  6887. this.bv.resetForm();
  6888. this.$vat.val(invalidSamples[i]);
  6889. this.bv.validate();
  6890. expect(this.bv.isValid()).toEqual(false);
  6891. }
  6892. });
  6893. it('Swedish VAT number', function() {
  6894. this.bv.updateOption('vat', 'vat', 'country', 'SE');
  6895. // Valid samples
  6896. var validSamples = ['SE123456789701', '123456789701'];
  6897. for (var i in validSamples) {
  6898. this.bv.resetForm();
  6899. this.$vat.val(validSamples[i]);
  6900. this.bv.validate();
  6901. expect(this.bv.isValid()).toBeTruthy();
  6902. }
  6903. // Invalid samples
  6904. var invalidSamples = ['SE123456789101', '123456789101'];
  6905. for (i in invalidSamples) {
  6906. this.bv.resetForm();
  6907. this.$vat.val(invalidSamples[i]);
  6908. this.bv.validate();
  6909. expect(this.bv.isValid()).toEqual(false);
  6910. }
  6911. });
  6912. it('Slovenian VAT number', function() {
  6913. this.bv.updateOption('vat', 'vat', 'country', 'SI');
  6914. // Valid samples
  6915. var validSamples = ['SI50223054', '50223054'];
  6916. for (var i in validSamples) {
  6917. this.bv.resetForm();
  6918. this.$vat.val(validSamples[i]);
  6919. this.bv.validate();
  6920. expect(this.bv.isValid()).toBeTruthy();
  6921. }
  6922. // Invalid samples
  6923. var invalidSamples = ['SI50223055', '50223055'];
  6924. for (i in invalidSamples) {
  6925. this.bv.resetForm();
  6926. this.$vat.val(invalidSamples[i]);
  6927. this.bv.validate();
  6928. expect(this.bv.isValid()).toEqual(false);
  6929. }
  6930. });
  6931. it('Slovak VAT number', function() {
  6932. this.bv.updateOption('vat', 'vat', 'country', 'SK');
  6933. // Valid samples
  6934. var validSamples = ['SK2022749619', '2022749619'];
  6935. for (var i in validSamples) {
  6936. this.bv.resetForm();
  6937. this.$vat.val(validSamples[i]);
  6938. this.bv.validate();
  6939. expect(this.bv.isValid()).toBeTruthy();
  6940. }
  6941. // Invalid samples
  6942. var invalidSamples = ['SK2022749618', '2022749618'];
  6943. for (i in invalidSamples) {
  6944. this.bv.resetForm();
  6945. this.$vat.val(invalidSamples[i]);
  6946. this.bv.validate();
  6947. expect(this.bv.isValid()).toEqual(false);
  6948. }
  6949. });
  6950. it('South African VAT number', function() {
  6951. this.bv.updateOption('vat', 'vat', 'country', 'ZA');
  6952. // Valid samples
  6953. var validSamples = ['ZA4012345678', '4012345678'];
  6954. for (var i in validSamples) {
  6955. this.bv.resetForm();
  6956. this.$vat.val(validSamples[i]);
  6957. this.bv.validate();
  6958. expect(this.bv.isValid()).toBeTruthy();
  6959. }
  6960. // Invalid samples
  6961. var invalidSamples = ['ZA40123456789', 'ZA0123456789', '40123456789', '0123456789'];
  6962. for (i in invalidSamples) {
  6963. this.bv.resetForm();
  6964. this.$vat.val(invalidSamples[i]);
  6965. this.bv.validate();
  6966. expect(this.bv.isValid()).toEqual(false);
  6967. }
  6968. });
  6969. it('Venezuelan VAT number (RIF)', function() {
  6970. this.bv.updateOption('vat', 'vat', 'country', 'VE');
  6971. // Valid samples
  6972. var validSamples = ['VEJ309272292', 'VEV242818101', 'VEJ000126518', 'VEJ000458324', 'J309272292', 'V242818101', 'J000126518', 'J000458324'];
  6973. for (var i in validSamples) {
  6974. this.bv.resetForm();
  6975. this.$vat.val(validSamples[i]);
  6976. this.bv.validate();
  6977. expect(this.bv.isValid()).toBeTruthy();
  6978. }
  6979. // Invalid samples
  6980. var invalidSamples = ['VEJ309272293', 'VEV242818100', 'J000126519', 'J000458323'];
  6981. for (i in invalidSamples) {
  6982. this.bv.resetForm();
  6983. this.$vat.val(invalidSamples[i]);
  6984. this.bv.validate();
  6985. expect(this.bv.isValid()).toEqual(false);
  6986. }
  6987. });
  6988. });
  6989. function getCountryCode(value, validator, $field) {
  6990. $('#msg').html('getCountryCode() called');
  6991. return validator.getFieldElements('country').val();
  6992. };
  6993. TestSuite = $.extend({}, TestSuite, {
  6994. ZipCode: {
  6995. getCountryCode: function(value, validator, $field) {
  6996. $('#msg').html('TestSuite.ZipCode.getCountryCode() called');
  6997. return validator.getFieldElements('country').val();
  6998. }
  6999. }
  7000. });
  7001. describe('zipCode', function() {
  7002. beforeEach(function() {
  7003. $([
  7004. '<form class="form-horizontal" id="zipCodeForm">',
  7005. '<div id="msg"></div>',
  7006. '<div class="form-group">',
  7007. '<label class="col-md-3 control-label">Country:</label>',
  7008. '<div class="col-md-2">',
  7009. '<select class="form-control" name="country">',
  7010. '<option value="">Select a country</option>',
  7011. '<option value="US">United States</option>',
  7012. '<option value="CA">Canada</option>',
  7013. '<option value="CZ">Czech Republic</option>',
  7014. '<option value="DK">Denmark</option>',
  7015. '<option value="IT">Italy</option>',
  7016. '<option value="NL">Netherlands</option>',
  7017. '<option value="SE">Sweden</option>',
  7018. '<option value="SK">Slovakia</option>',
  7019. '<option value="GB">United Kingdom</option>',
  7020. '</select>',
  7021. '</div>',
  7022. '</div>',
  7023. '<div class="form-group">',
  7024. '<label class="col-md-3 control-label">Zipcode</label>',
  7025. '<div class="col-md-2">',
  7026. '<input type="text" class="form-control" name="zc" data-bv-zipcode data-bv-zipcode-country="US" />',
  7027. '</div>',
  7028. '</div>',
  7029. '</form>'
  7030. ].join('\n')).appendTo('body');
  7031. $('#zipCodeForm').bootstrapValidator();
  7032. /**
  7033. * @type {BootstrapValidator}
  7034. */
  7035. this.bv = $('#zipCodeForm').data('bootstrapValidator');
  7036. this.$country = this.bv.getFieldElements('country');
  7037. this.$zipCode = this.bv.getFieldElements('zc');
  7038. });
  7039. afterEach(function() {
  7040. $('#zipCodeForm').bootstrapValidator('destroy').remove();
  7041. });
  7042. it('country code updateOption()', function() {
  7043. // Check IT postal code
  7044. this.bv.updateOption('zc', 'zipCode', 'country', 'IT');
  7045. this.$zipCode.val('1234');
  7046. this.bv.validate();
  7047. expect(this.bv.isValid()).toEqual(false);
  7048. this.bv.resetForm();
  7049. this.$zipCode.val('IT-12345');
  7050. this.bv.validate();
  7051. expect(this.bv.isValid()).toBeTruthy();
  7052. // Check United Kingdom postal code
  7053. this.bv.updateOption('zc', 'zipCode', 'country', 'GB');
  7054. var validUkSamples = ['EC1A 1BB', 'W1A 1HQ', 'M1 1AA', 'B33 8TH', 'CR2 6XH', 'DN55 1PT', 'AI-2640', 'ASCN 1ZZ', 'GIR 0AA'];
  7055. for (var i in validUkSamples) {
  7056. this.bv.resetForm();
  7057. this.$zipCode.val(validUkSamples[i]);
  7058. this.bv.validate();
  7059. expect(this.bv.isValid()).toBeTruthy();
  7060. }
  7061. });
  7062. it('country code other field declarative', function() {
  7063. this.$zipCode.attr('data-bv-zipcode-country', 'country');
  7064. // Need to destroy the plugin instance ...
  7065. $('#zipCodeForm').bootstrapValidator('destroy');
  7066. // ... and re-create it
  7067. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  7068. this.$country.val('IT');
  7069. this.bv.resetForm();
  7070. this.$zipCode.val('1234');
  7071. this.bv.validate();
  7072. expect(this.bv.isValid()).toEqual(false);
  7073. this.bv.resetForm();
  7074. this.$zipCode.val('I-12345');
  7075. this.bv.validate();
  7076. expect(this.bv.isValid()).toBeTruthy();
  7077. });
  7078. it('country code callback declarative function', function() {
  7079. this.$zipCode.attr('data-bv-zipcode-country', 'getCountryCode');
  7080. $('#zipCodeForm').bootstrapValidator('destroy');
  7081. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  7082. this.$country.val('NL');
  7083. this.$zipCode.val('0123');
  7084. this.bv.validate();
  7085. expect($('#msg').html()).toEqual('getCountryCode() called');
  7086. expect(this.bv.isValid()).toEqual(false);
  7087. });
  7088. it('country code callback declarative function()', function() {
  7089. this.$zipCode.attr('data-bv-zipcode-country', 'getCountryCode()');
  7090. $('#zipCodeForm').bootstrapValidator('destroy');
  7091. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  7092. this.$country.val('NL');
  7093. this.$zipCode.val('1234 ab');
  7094. this.bv.validate();
  7095. expect($('#msg').html()).toEqual('getCountryCode() called');
  7096. expect(this.bv.isValid()).toBeTruthy();
  7097. });
  7098. it('country code callback declarative A.B.C', function() {
  7099. this.$zipCode.attr('data-bv-zipcode-country', 'TestSuite.ZipCode.getCountryCode');
  7100. $('#zipCodeForm').bootstrapValidator('destroy');
  7101. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  7102. this.$country.val('DK');
  7103. this.$zipCode.val('DK 123');
  7104. this.bv.validate();
  7105. expect($('#msg').html()).toEqual('TestSuite.ZipCode.getCountryCode() called');
  7106. expect(this.bv.isValid()).toEqual(false);
  7107. });
  7108. it('country code callback declarative A.B.C()', function() {
  7109. this.$zipCode.attr('data-bv-zipcode-country', 'TestSuite.ZipCode.getCountryCode()');
  7110. $('#zipCodeForm').bootstrapValidator('destroy');
  7111. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  7112. this.$country.val('DK');
  7113. this.$zipCode.val('DK-1234');
  7114. this.bv.validate();
  7115. expect($('#msg').html()).toEqual('TestSuite.ZipCode.getCountryCode() called');
  7116. expect(this.bv.isValid()).toBeTruthy();
  7117. });
  7118. it('country code callback programmatically', function() {
  7119. this.$zipCode.removeAttr('data-bv-zipcode-country');
  7120. $('#zipCodeForm').bootstrapValidator('destroy');
  7121. this.bv = $('#zipCodeForm')
  7122. .bootstrapValidator({
  7123. fields: {
  7124. zc: {
  7125. validators: {
  7126. zipCode: {
  7127. country: function(value, validator, $field) {
  7128. return getCountryCode(value, validator, $field);
  7129. }
  7130. }
  7131. }
  7132. }
  7133. }
  7134. })
  7135. .data('bootstrapValidator');
  7136. this.$country.val('SE');
  7137. this.bv.resetForm();
  7138. this.$zipCode.val('S-567 8');
  7139. this.bv.validate();
  7140. expect($('#msg').html()).toEqual('getCountryCode() called');
  7141. expect(this.bv.isValid()).toEqual(false);
  7142. this.bv.resetForm();
  7143. this.$zipCode.val('S-12345');
  7144. this.bv.validate();
  7145. expect($('#msg').html()).toEqual('getCountryCode() called');
  7146. expect(this.bv.isValid()).toBeTruthy();
  7147. });
  7148. it('not supported country code', function() {
  7149. this.$zipCode.attr('data-bv-zipcode-country', 'NOT_SUPPORTED');
  7150. $('#zipCodeForm').bootstrapValidator('destroy');
  7151. this.bv = $('#zipCodeForm').bootstrapValidator().data('bootstrapValidator');
  7152. this.bv.resetForm();
  7153. this.$zipCode.val('1234');
  7154. this.bv.validate();
  7155. expect(this.bv.isValid()).toEqual(false);
  7156. expect(this.bv.getMessages(this.$zipCode, 'zipCode')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, 'NOT_SUPPORTED'));
  7157. });
  7158. it('US zipcode', function() {
  7159. this.$zipCode.val('12345');
  7160. this.bv.validate();
  7161. expect(this.bv.isValid()).toBeTruthy();
  7162. this.bv.resetForm();
  7163. this.$zipCode.val('123');
  7164. this.bv.validate();
  7165. expect(this.bv.isValid()).toEqual(false);
  7166. });
  7167. it('Czech Republic postal code', function() {
  7168. this.bv.updateOption('zc', 'zipCode', 'country', 'CZ');
  7169. // Valid samples
  7170. var validSamples = ['12345', '123 45'];
  7171. for (var i in validSamples) {
  7172. this.bv.resetForm();
  7173. this.$zipCode.val(validSamples[i]);
  7174. this.bv.validate();
  7175. expect(this.bv.isValid()).toBeTruthy();
  7176. }
  7177. // Invalid samples
  7178. var invalidSamples = ['12 345', '123456', '1 2345', '1234 5', '12 3 45'];
  7179. for (i in invalidSamples) {
  7180. this.bv.resetForm();
  7181. this.$zipCode.val(invalidSamples[i]);
  7182. this.bv.validate();
  7183. expect(this.bv.isValid()).toEqual(false);
  7184. }
  7185. });
  7186. it('Slovakia postal code', function() {
  7187. this.bv.updateOption('zc', 'zipCode', 'country', 'SK');
  7188. // Valid samples
  7189. var validSamples = ['12345', '123 45'];
  7190. for (var i in validSamples) {
  7191. this.bv.resetForm();
  7192. this.$zipCode.val(validSamples[i]);
  7193. this.bv.validate();
  7194. expect(this.bv.isValid()).toBeTruthy();
  7195. }
  7196. // Invalid samples
  7197. var invalidSamples = ['12 345', '123456', '1 2345', '1234 5', '12 3 45'];
  7198. for (i in invalidSamples) {
  7199. this.bv.resetForm();
  7200. this.$zipCode.val(invalidSamples[i]);
  7201. this.bv.validate();
  7202. expect(this.bv.isValid()).toEqual(false);
  7203. }
  7204. });
  7205. });