0d21e146be5eec0de23b5474de8b61f3d586c130dba7d7b8759a2fec381384d6fee31867b411a45a1822054ad58e16c8eb4dc552b49cefcca034d341558491 169 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // identity function for calling harmony imports with the correct context
  37. /******/ __webpack_require__.i = function(value) { return value; };
  38. /******/
  39. /******/ // define getter function for harmony exports
  40. /******/ __webpack_require__.d = function(exports, name, getter) {
  41. /******/ if(!__webpack_require__.o(exports, name)) {
  42. /******/ Object.defineProperty(exports, name, {
  43. /******/ configurable: false,
  44. /******/ enumerable: true,
  45. /******/ get: getter
  46. /******/ });
  47. /******/ }
  48. /******/ };
  49. /******/
  50. /******/ // getDefaultExport function for compatibility with non-harmony modules
  51. /******/ __webpack_require__.n = function(module) {
  52. /******/ var getter = module && module.__esModule ?
  53. /******/ function getDefault() { return module['default']; } :
  54. /******/ function getModuleExports() { return module; };
  55. /******/ __webpack_require__.d(getter, 'a', getter);
  56. /******/ return getter;
  57. /******/ };
  58. /******/
  59. /******/ // Object.prototype.hasOwnProperty.call
  60. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  61. /******/
  62. /******/ // __webpack_public_path__
  63. /******/ __webpack_require__.p = "";
  64. /******/
  65. /******/ // Load entry module and return exports
  66. /******/ return __webpack_require__(__webpack_require__.s = 13);
  67. /******/ })
  68. /************************************************************************/
  69. /******/ ([
  70. /* 0 */,
  71. /* 1 */
  72. /***/ (function(module, exports, __webpack_require__) {
  73. var map = {
  74. "./border.spec.js": 4,
  75. "./calculator/viewportColumns.spec.js": 5,
  76. "./calculator/viewportRows.spec.js": 6,
  77. "./cell/coords.spec.js": 7,
  78. "./cell/range.spec.js": 8,
  79. "./core.spec.js": 9,
  80. "./event.spec.js": 10,
  81. "./filter/column.spec.js": 11,
  82. "./filter/row.spec.js": 12,
  83. "./scroll.spec.js": 14,
  84. "./scrollbar.spec.js": 15,
  85. "./scrollbarNative.spec.js": 16,
  86. "./selection.spec.js": 17,
  87. "./settings/columnHeaders.spec.js": 18,
  88. "./settings/preventOverflow.spec.js": 19,
  89. "./settings/rowHeaders.spec.js": 20,
  90. "./settings/stretchH.spec.js": 21,
  91. "./table.spec.js": 22
  92. };
  93. function webpackContext(req) {
  94. return __webpack_require__(webpackContextResolve(req));
  95. };
  96. function webpackContextResolve(req) {
  97. var id = map[req];
  98. if(!(id + 1)) // check for number or string
  99. throw new Error("Cannot find module '" + req + "'.");
  100. return id;
  101. };
  102. webpackContext.keys = function webpackContextKeys() {
  103. return Object.keys(map);
  104. };
  105. webpackContext.resolve = webpackContextResolve;
  106. module.exports = webpackContext;
  107. webpackContext.id = 1;
  108. /***/ }),
  109. /* 2 */,
  110. /* 3 */,
  111. /* 4 */
  112. /***/ (function(module, exports, __webpack_require__) {
  113. "use strict";
  114. describe('WalkontableBorder', function () {
  115. var $table,
  116. $container,
  117. $wrapper,
  118. debug = false;
  119. beforeEach(function () {
  120. $container = $('<div></div>');
  121. $wrapper = $('<div></div>');
  122. $container.width(100).height(200);
  123. $table = $('<table></table>');
  124. $container.append($wrapper);
  125. $wrapper.append($table);
  126. $container.appendTo('body');
  127. createDataArray();
  128. });
  129. afterEach(function () {
  130. if (!debug) {
  131. $('.wtHolder').remove();
  132. }
  133. $container.remove();
  134. });
  135. it('should add/remove border to selection when cell is clicked', function () {
  136. var wt = new Walkontable.Core({
  137. table: $table[0],
  138. data: getData,
  139. totalRows: 5,
  140. totalColumns: 5,
  141. selections: [new Walkontable.Selection({
  142. border: {
  143. width: 1,
  144. color: 'red'
  145. }
  146. })],
  147. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  148. wt.selections.current.clear();
  149. wt.selections.current.add(coords);
  150. wt.draw();
  151. }
  152. });
  153. shimSelectionProperties(wt);
  154. wt.draw();
  155. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  156. var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
  157. var $top = $(wt.selections.current.getBorder(wt).top);
  158. var $right = $(wt.selections.current.getBorder(wt).right);
  159. var $bottom = $(wt.selections.current.getBorder(wt).bottom);
  160. var $left = $(wt.selections.current.getBorder(wt).left);
  161. $td1.simulate('mousedown');
  162. expect($top.css('height')).toBe('1px');
  163. expect($top.position().top).toBe(23);
  164. expect($top.position().left).toBe(0);
  165. expect($right.css('width')).toBe('1px');
  166. expect($right.position().top).toBe(23);
  167. expect($right.position().left).toBe(49);
  168. expect($bottom.css('height')).toBe('1px');
  169. expect($bottom.position().top).toBe(46);
  170. expect($bottom.position().left).toBe(0);
  171. expect($left.css('width')).toBe('1px');
  172. expect($left.position().top).toBe(23);
  173. expect($left.position().left).toBe(0);
  174. $td2.simulate('mousedown');
  175. expect($top.css('height')).toBe('1px');
  176. expect($top.position().top).toBe(46);
  177. expect($top.position().left).toBe(49);
  178. expect($right.css('width')).toBe('1px');
  179. expect($right.position().top).toBe(46);
  180. expect($right.position().left).toBe(99);
  181. expect($bottom.css('height')).toBe('1px');
  182. expect($bottom.position().top).toBe(69);
  183. expect($bottom.position().left).toBe(49);
  184. expect($left.css('width')).toBe('1px');
  185. expect($left.position().top).toBe(46);
  186. expect($left.position().left).toBe(49);
  187. });
  188. it('should add/remove corner to selection when cell is clicked', function () {
  189. var wt = new Walkontable.Core({
  190. table: $table[0],
  191. data: getData,
  192. totalRows: 5,
  193. totalColumns: 5,
  194. selections: [new Walkontable.Selection({
  195. border: {
  196. width: 2,
  197. color: 'green',
  198. cornerVisible: function cornerVisible() {
  199. return true;
  200. }
  201. }
  202. }), new Walkontable.Selection({})],
  203. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  204. wt.selections.current.clear();
  205. wt.selections.current.add(coords);
  206. wt.draw();
  207. }
  208. });
  209. shimSelectionProperties(wt);
  210. wt.draw();
  211. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  212. var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
  213. var $corner = $(wt.selections.current.getBorder(wt).corner);
  214. $td1.simulate('mousedown');
  215. expect($corner.css('width')).toBe('5px');
  216. expect($corner.css('height')).toBe('5px');
  217. expect($corner.position().top).toBe(42);
  218. expect($corner.position().left).toBe(45);
  219. $td2.simulate('mousedown');
  220. expect($corner.css('width')).toBe('5px');
  221. expect($corner.css('height')).toBe('5px');
  222. expect($corner.position().top).toBe(65);
  223. expect($corner.position().left).toBe(95);
  224. });
  225. it('should move the fill handle / corner border to the left, if in the position it would overlap the container (e.g.: far-right)', function () {
  226. $container.css({
  227. overflow: 'hidden',
  228. width: '200px'
  229. });
  230. var wt = new Walkontable.Core({
  231. table: $table[0],
  232. data: getData,
  233. totalRows: 5,
  234. totalColumns: 4,
  235. selections: [new Walkontable.Selection({
  236. border: {
  237. width: 2,
  238. color: 'green',
  239. cornerVisible: function cornerVisible() {
  240. return true;
  241. }
  242. }
  243. }), new Walkontable.Selection({})],
  244. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  245. wt.selections.current.clear();
  246. wt.selections.current.add(coords);
  247. wt.draw();
  248. }
  249. });
  250. shimSelectionProperties(wt);
  251. wt.draw();
  252. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  253. var $td2 = $table.find('tbody tr:eq(3) td:eq(3)');
  254. var $td3 = $table.find('tbody tr:eq(2) td:eq(1)');
  255. var $corner = $(wt.selections.current.getBorder(wt).corner);
  256. $td1.simulate('mousedown');
  257. expect($corner.css('width')).toBe('5px');
  258. expect($corner.css('height')).toBe('5px');
  259. expect($corner.position().top).toBe(42);
  260. expect($corner.position().left).toBe(45);
  261. expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
  262. $td2.simulate('mousedown');
  263. expect($corner.css('width')).toBe('5px');
  264. expect($corner.css('height')).toBe('5px');
  265. expect($corner.position().top).toBe(88);
  266. expect($corner.position().left).toBe(193);
  267. expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
  268. $td3.simulate('mousedown');
  269. expect($corner.css('width')).toBe('5px');
  270. expect($corner.css('height')).toBe('5px');
  271. expect($corner.position().top).toBe(65);
  272. expect($corner.position().left).toBe(95);
  273. expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
  274. });
  275. });
  276. /***/ }),
  277. /* 5 */
  278. /***/ (function(module, exports, __webpack_require__) {
  279. "use strict";
  280. describe('Walkontable.ViewportColumnsCalculator', function () {
  281. function allColumns20() {
  282. return 20;
  283. }
  284. it('should render first 5 columns in unscrolled container', function () {
  285. var calc = new Walkontable.ViewportColumnsCalculator(100, 0, 1000, allColumns20);
  286. expect(calc.startColumn).toBe(0);
  287. expect(calc.startPosition).toBe(0);
  288. expect(calc.endColumn).toBe(4);
  289. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 0, 1000, allColumns20, null, true);
  290. expect(visibleCalc.startColumn).toBe(0);
  291. expect(visibleCalc.endColumn).toBe(4);
  292. });
  293. it('should render 6 columns, starting from 3 in container scrolled to half of fourth column', function () {
  294. var calc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20);
  295. expect(calc.startColumn).toBe(3);
  296. expect(calc.startPosition).toBe(60);
  297. expect(calc.endColumn).toBe(8);
  298. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20, null, true);
  299. expect(visibleCalc.startColumn).toBe(4);
  300. expect(visibleCalc.endColumn).toBe(7);
  301. });
  302. it('should render 10 columns, starting from 1 in container scrolled to half of fourth column (with render overrides)', function () {
  303. var overrideFn = function overrideFn(calc) {
  304. calc.startColumn -= 2;
  305. calc.endColumn += 2;
  306. };
  307. var calc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20, overrideFn);
  308. expect(calc.startColumn).toBe(1);
  309. expect(calc.startPosition).toBe(20);
  310. expect(calc.endColumn).toBe(10);
  311. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20, null, true);
  312. expect(visibleCalc.startColumn).toBe(4);
  313. expect(visibleCalc.endColumn).toBe(7);
  314. });
  315. it('should return number of rendered columns', function () {
  316. var calc = new Walkontable.ViewportColumnsCalculator(100, 50, 1000, allColumns20);
  317. expect(calc.count).toBe(6);
  318. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 50, 1000, allColumns20, null, true);
  319. expect(visibleCalc.count).toBe(4);
  320. });
  321. it('should render all columns if their size is smaller than viewport', function () {
  322. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 8, allColumns20);
  323. expect(calc.startColumn).toBe(0);
  324. expect(calc.endColumn).toBe(7);
  325. expect(calc.count).toBe(8);
  326. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 8, allColumns20, null, true);
  327. expect(visibleCalc.startColumn).toBe(0);
  328. expect(visibleCalc.endColumn).toBe(7);
  329. expect(visibleCalc.count).toBe(8);
  330. });
  331. it('should render all columns if their size is exactly the viewport', function () {
  332. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 10, allColumns20);
  333. expect(calc.startColumn).toBe(0);
  334. expect(calc.endColumn).toBe(9);
  335. expect(calc.count).toBe(10);
  336. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 10, allColumns20, null, true);
  337. expect(visibleCalc.startColumn).toBe(0);
  338. expect(visibleCalc.endColumn).toBe(9);
  339. expect(visibleCalc.count).toBe(10);
  340. });
  341. it('should render all columns if their size is slightly larger than viewport', function () {
  342. var calc = new Walkontable.ViewportColumnsCalculator(199, 0, 10, allColumns20);
  343. expect(calc.startColumn).toBe(0);
  344. expect(calc.endColumn).toBe(9);
  345. expect(calc.count).toBe(10);
  346. var visibleCalc = new Walkontable.ViewportColumnsCalculator(199, 0, 10, allColumns20, null, true);
  347. expect(visibleCalc.startColumn).toBe(0);
  348. expect(visibleCalc.endColumn).toBe(8);
  349. expect(visibleCalc.count).toBe(9);
  350. });
  351. it('should set null values if total columns is 0', function () {
  352. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20);
  353. expect(calc.startColumn).toBe(null);
  354. expect(calc.startPosition).toBe(null);
  355. expect(calc.endColumn).toBe(null);
  356. expect(calc.count).toBe(0);
  357. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20, null, true);
  358. expect(visibleCalc.startColumn).toBe(null);
  359. expect(visibleCalc.endColumn).toBe(null);
  360. });
  361. it('should set null values if total columns is 0 (with overrideFn provided)', function () {
  362. var overrideFn = function overrideFn(myCalc) {
  363. myCalc.startColumn = 0;
  364. myCalc.endColumn = 0;
  365. };
  366. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20, overrideFn);
  367. expect(calc.startColumn).toBe(null);
  368. expect(calc.startPosition).toBe(null);
  369. expect(calc.endColumn).toBe(null);
  370. expect(calc.count).toBe(0);
  371. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20, null, true);
  372. expect(visibleCalc.startColumn).toBe(null);
  373. expect(visibleCalc.endColumn).toBe(null);
  374. });
  375. it('should scroll backwards if total columns is reached', function () {
  376. var calc = new Walkontable.ViewportColumnsCalculator(190, 350, 20, allColumns20);
  377. expect(calc.startColumn).toBe(10);
  378. expect(calc.startPosition).toBe(200);
  379. expect(calc.endColumn).toBe(19);
  380. expect(calc.count).toBe(10);
  381. var visibleCalc = new Walkontable.ViewportColumnsCalculator(190, 350, 20, allColumns20, null, true);
  382. expect(visibleCalc.startColumn).toBe(11);
  383. expect(visibleCalc.endColumn).toBe(19);
  384. });
  385. it('should update stretchAllRatio after refreshStretching call (stretch: all)', function () {
  386. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 20, allColumns20, null, true, 'all');
  387. expect(calc.stretchAllRatio).toBe(0);
  388. expect(calc.stretchLastWidth).toBe(0);
  389. calc.refreshStretching(414);
  390. expect(calc.stretchAllRatio).toBe(1.035);
  391. expect(calc.stretchLastWidth).toBe(0);
  392. });
  393. it('should update stretchAllRatio after refreshStretching call (stretch: last)', function () {
  394. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'last');
  395. expect(calc.stretchAllRatio).toBe(0);
  396. expect(calc.stretchLastWidth).toBe(0);
  397. calc.refreshStretching(414);
  398. expect(calc.stretchAllRatio).toBe(0);
  399. expect(calc.stretchLastWidth).toBe(334);
  400. });
  401. it('should return valid stretched column width (stretch: all)', function () {
  402. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'all');
  403. expect(calc.getStretchedColumnWidth(0, 50)).toBe(null);
  404. expect(calc.needVerifyLastColumnWidth).toBe(true);
  405. calc.refreshStretching(417);
  406. expect(calc.getStretchedColumnWidth(0, allColumns20())).toBe(83);
  407. expect(calc.getStretchedColumnWidth(1, allColumns20())).toBe(83);
  408. expect(calc.getStretchedColumnWidth(2, allColumns20())).toBe(83);
  409. expect(calc.getStretchedColumnWidth(3, allColumns20())).toBe(83);
  410. expect(calc.needVerifyLastColumnWidth).toBe(true);
  411. expect(calc.getStretchedColumnWidth(4, allColumns20())).toBe(85);
  412. expect(calc.needVerifyLastColumnWidth).toBe(false);
  413. });
  414. it('should return valid stretched column width (stretch: last)', function () {
  415. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'last');
  416. expect(calc.getStretchedColumnWidth(0, 50)).toBe(null);
  417. calc.refreshStretching(417);
  418. expect(calc.getStretchedColumnWidth(0, allColumns20())).toBe(null);
  419. expect(calc.getStretchedColumnWidth(1, allColumns20())).toBe(null);
  420. expect(calc.getStretchedColumnWidth(2, allColumns20())).toBe(null);
  421. expect(calc.getStretchedColumnWidth(3, allColumns20())).toBe(null);
  422. expect(calc.getStretchedColumnWidth(4, allColumns20())).toBe(337);
  423. });
  424. it('call refreshStretching should clear stretchAllColumnsWidth and needVerifyLastColumnWidth property', function () {
  425. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'all');
  426. expect(calc.stretchAllColumnsWidth.length).toBe(0);
  427. expect(calc.needVerifyLastColumnWidth).toBe(true);
  428. calc.refreshStretching(417);
  429. calc.getStretchedColumnWidth(0, allColumns20());
  430. calc.getStretchedColumnWidth(1, allColumns20());
  431. calc.getStretchedColumnWidth(2, allColumns20());
  432. calc.getStretchedColumnWidth(3, allColumns20());
  433. calc.getStretchedColumnWidth(4, allColumns20());
  434. expect(calc.stretchAllColumnsWidth.length).toBe(5);
  435. expect(calc.needVerifyLastColumnWidth).toBe(false);
  436. calc.refreshStretching(201);
  437. expect(calc.stretchAllColumnsWidth.length).toBe(0);
  438. expect(calc.needVerifyLastColumnWidth).toBe(true);
  439. });
  440. });
  441. /***/ }),
  442. /* 6 */
  443. /***/ (function(module, exports, __webpack_require__) {
  444. "use strict";
  445. describe('Walkontable.ViewportRowsCalculator', function () {
  446. function allRows20() {
  447. return 20;
  448. }
  449. it('should render first 5 rows in unscrolled container', function () {
  450. var calc = new Walkontable.ViewportRowsCalculator(100, 0, 1000, allRows20);
  451. expect(calc.startRow).toBe(0);
  452. expect(calc.startPosition).toBe(0);
  453. expect(calc.endRow).toBe(4);
  454. var visibleCalc = new Walkontable.ViewportRowsCalculator(100, 0, 1000, allRows20, null, true);
  455. expect(visibleCalc.startRow).toBe(0);
  456. expect(visibleCalc.endRow).toBe(4);
  457. });
  458. it('should render 6 rows, starting from 3 in container scrolled to half of fourth row', function () {
  459. var calc = new Walkontable.ViewportRowsCalculator(100, 70, 1000, allRows20);
  460. expect(calc.startRow).toBe(3);
  461. expect(calc.startPosition).toBe(60);
  462. expect(calc.endRow).toBe(8);
  463. var visibleCalc = new Walkontable.ViewportRowsCalculator(100, 70, 1000, allRows20, null, true);
  464. expect(visibleCalc.startRow).toBe(4);
  465. expect(visibleCalc.endRow).toBe(7);
  466. });
  467. it('should render 10 rows, starting from 1 in container scrolled to half of fourth row (with render overrides)', function () {
  468. var overrideFn = function overrideFn(calc) {
  469. calc.startRow -= 2;
  470. calc.endRow += 2;
  471. };
  472. var calc = new Walkontable.ViewportRowsCalculator(100, 70, 1000, allRows20, overrideFn);
  473. expect(calc.startRow).toBe(1);
  474. expect(calc.startPosition).toBe(20);
  475. expect(calc.endRow).toBe(10);
  476. var visibleCalc = new Walkontable.ViewportRowsCalculator(100, 70, 1000, allRows20, null, true);
  477. expect(visibleCalc.startRow).toBe(4);
  478. expect(visibleCalc.endRow).toBe(7);
  479. });
  480. it('should return number of rendered rows', function () {
  481. var calc = new Walkontable.ViewportRowsCalculator(100, 50, 1000, allRows20);
  482. expect(calc.count).toBe(6);
  483. var visibleCalc = new Walkontable.ViewportRowsCalculator(100, 50, 1000, allRows20, null, true);
  484. expect(visibleCalc.count).toBe(4);
  485. });
  486. it('should render all rows if their size is smaller than viewport', function () {
  487. var calc = new Walkontable.ViewportRowsCalculator(200, 0, 8, allRows20);
  488. expect(calc.startRow).toBe(0);
  489. expect(calc.endRow).toBe(7);
  490. expect(calc.count).toBe(8);
  491. var visibleCalc = new Walkontable.ViewportRowsCalculator(200, 0, 8, allRows20, null, true);
  492. expect(visibleCalc.startRow).toBe(0);
  493. expect(visibleCalc.endRow).toBe(7);
  494. expect(visibleCalc.count).toBe(8);
  495. });
  496. it('should render all rows if their size is exactly the viewport', function () {
  497. var calc = new Walkontable.ViewportRowsCalculator(200, 0, 10, allRows20);
  498. expect(calc.startRow).toBe(0);
  499. expect(calc.endRow).toBe(9);
  500. expect(calc.count).toBe(10);
  501. var visibleCalc = new Walkontable.ViewportRowsCalculator(200, 0, 10, allRows20, null, true);
  502. expect(visibleCalc.startRow).toBe(0);
  503. expect(visibleCalc.endRow).toBe(9);
  504. expect(visibleCalc.count).toBe(10);
  505. });
  506. it('should render all rows if their size is slightly larger than viewport', function () {
  507. var calc = new Walkontable.ViewportRowsCalculator(199, 0, 10, allRows20);
  508. expect(calc.startRow).toBe(0);
  509. expect(calc.endRow).toBe(9);
  510. expect(calc.count).toBe(10);
  511. var visibleCalc = new Walkontable.ViewportRowsCalculator(199, 0, 10, allRows20, null, true);
  512. expect(visibleCalc.startRow).toBe(0);
  513. expect(visibleCalc.endRow).toBe(8);
  514. expect(visibleCalc.count).toBe(9);
  515. });
  516. it('should set null values if total rows is 0', function () {
  517. var calc = new Walkontable.ViewportRowsCalculator(200, 0, 0, allRows20);
  518. expect(calc.startRow).toBe(null);
  519. expect(calc.startPosition).toBe(null);
  520. expect(calc.endRow).toBe(null);
  521. expect(calc.count).toBe(0);
  522. var visibleCalc = new Walkontable.ViewportRowsCalculator(200, 0, 0, allRows20, null, true);
  523. expect(visibleCalc.startRow).toBe(null);
  524. expect(visibleCalc.endRow).toBe(null);
  525. });
  526. it('should set null values if total rows is 0 (with overrideFn provided)', function () {
  527. var overrideFn = function overrideFn(myCalc) {
  528. myCalc.startRow = 0;
  529. myCalc.endRow = 0;
  530. };
  531. var calc = new Walkontable.ViewportRowsCalculator(200, 0, 0, allRows20, overrideFn);
  532. expect(calc.startRow).toBe(null);
  533. expect(calc.startPosition).toBe(null);
  534. expect(calc.endRow).toBe(null);
  535. expect(calc.count).toBe(0);
  536. var visibleCalc = new Walkontable.ViewportRowsCalculator(200, 0, 0, allRows20, null, true);
  537. expect(visibleCalc.startRow).toBe(null);
  538. expect(visibleCalc.endRow).toBe(null);
  539. });
  540. it('should scroll backwards if total rows is reached', function () {
  541. var calc = new Walkontable.ViewportRowsCalculator(190, 350, 20, allRows20);
  542. expect(calc.startRow).toBe(10);
  543. expect(calc.startPosition).toBe(200);
  544. expect(calc.endRow).toBe(19);
  545. expect(calc.count).toBe(10);
  546. var visibleCalc = new Walkontable.ViewportRowsCalculator(190, 350, 20, allRows20, null, true);
  547. expect(visibleCalc.startRow).toBe(11);
  548. expect(visibleCalc.endRow).toBe(19);
  549. });
  550. });
  551. /***/ }),
  552. /* 7 */
  553. /***/ (function(module, exports, __webpack_require__) {
  554. "use strict";
  555. describe('Walkontable.CellCoords', function () {
  556. describe('isValid', function () {
  557. var table = document.createElement('table');
  558. var wrapper = document.createElement('div');
  559. var container = document.createElement('div');
  560. wrapper.appendChild(container);
  561. container.appendChild(table);
  562. var wot = new Walkontable.Core({
  563. table: table,
  564. data: [],
  565. totalRows: 10,
  566. totalColumns: 5
  567. });
  568. it('should be false if one of the arguments is smaller than 0', function () {
  569. var cellCoords = new Walkontable.CellCoords(-1, 0);
  570. var result = cellCoords.isValid(wot);
  571. expect(result).toBe(false);
  572. cellCoords = new Walkontable.CellCoords(0, -1);
  573. result = cellCoords.isValid(wot);
  574. expect(result).toBe(false);
  575. });
  576. it('should be true if row is within the total number of rows', function () {
  577. var cellCoords = new Walkontable.CellCoords(9, 1);
  578. var result = cellCoords.isValid(wot);
  579. expect(result).toBe(true);
  580. });
  581. it('should be false if row is greater than total number of rows', function () {
  582. var cellCoords = new Walkontable.CellCoords(10, 1);
  583. var result = cellCoords.isValid(wot);
  584. expect(result).toBe(false);
  585. });
  586. it('should be true if column is within the total number of columns', function () {
  587. var cellCoords = new Walkontable.CellCoords(1, 4);
  588. var result = cellCoords.isValid(wot);
  589. expect(result).toBe(true);
  590. });
  591. it('should be false if column is greater than total number of columns', function () {
  592. var cellCoords = new Walkontable.CellCoords(1, 5);
  593. var result = cellCoords.isValid(wot);
  594. expect(result).toBe(false);
  595. });
  596. });
  597. describe('isEqual', function () {
  598. it('should be equal to itself', function () {
  599. var cellCoords = new Walkontable.CellCoords(1, 1);
  600. var result = cellCoords.isEqual(cellCoords);
  601. expect(result).toBe(true);
  602. });
  603. it('should be equal to another instance with the same row and column', function () {
  604. var cellCoords = new Walkontable.CellCoords(1, 1);
  605. var cellCoords2 = new Walkontable.CellCoords(1, 1);
  606. var result = cellCoords.isEqual(cellCoords2);
  607. expect(result).toBe(true);
  608. });
  609. it('should not be equal to an instance with different row or column', function () {
  610. var cellCoords = new Walkontable.CellCoords(1, 1);
  611. var cellCoords2 = new Walkontable.CellCoords(2, 1);
  612. var result = cellCoords.isEqual(cellCoords2);
  613. expect(result).toBe(false);
  614. });
  615. });
  616. });
  617. /***/ }),
  618. /* 8 */
  619. /***/ (function(module, exports, __webpack_require__) {
  620. "use strict";
  621. describe('Walkontable.CellRange', function () {
  622. describe('getAll', function () {
  623. it('should get all cells in range', function () {
  624. var from = new Walkontable.CellCoords(1, 1);
  625. var to = new Walkontable.CellCoords(3, 3);
  626. var range = new Walkontable.CellRange(from, from, to);
  627. var all = range.getAll();
  628. expect(all.length).toBe(9);
  629. expect(all[0].row).toBe(from.row);
  630. expect(all[0].col).toBe(from.col);
  631. expect(all[1].row).toBe(1);
  632. expect(all[1].col).toBe(2);
  633. expect(all[8].row).toBe(to.row);
  634. expect(all[8].col).toBe(to.col);
  635. });
  636. it('should get all cells in range (reverse order)', function () {
  637. var from = new Walkontable.CellCoords(3, 3);
  638. var to = new Walkontable.CellCoords(1, 1);
  639. var range = new Walkontable.CellRange(from, from, to);
  640. var all = range.getAll();
  641. expect(all.length).toBe(9);
  642. expect(all[0].row).toBe(to.row);
  643. expect(all[0].col).toBe(to.col);
  644. expect(all[1].row).toBe(1);
  645. expect(all[1].col).toBe(2);
  646. expect(all[8].row).toBe(from.row);
  647. expect(all[8].col).toBe(from.col);
  648. });
  649. });
  650. describe('getInner', function () {
  651. it('should get cells in range excluding from and to', function () {
  652. var from = new Walkontable.CellCoords(1, 1);
  653. var to = new Walkontable.CellCoords(3, 3);
  654. var range = new Walkontable.CellRange(from, from, to);
  655. var inner = range.getInner();
  656. expect(inner.length).toBe(7);
  657. expect(inner[1].row).toBe(1);
  658. expect(inner[1].col).toBe(3);
  659. });
  660. it('should get cells in range excluding from and to (reverse order)', function () {
  661. var from = new Walkontable.CellCoords(3, 3);
  662. var to = new Walkontable.CellCoords(1, 1);
  663. var range = new Walkontable.CellRange(from, from, to);
  664. var inner = range.getInner();
  665. expect(inner.length).toBe(7);
  666. expect(inner[1].row).toBe(1);
  667. expect(inner[1].col).toBe(3);
  668. });
  669. });
  670. describe('includes', function () {
  671. it('should return true if range is a single cell and the same cell is given', function () {
  672. var from = new Walkontable.CellCoords(0, 0);
  673. var to = new Walkontable.CellCoords(0, 0);
  674. var range = new Walkontable.CellRange(from, from, to);
  675. expect(range.includes(new Walkontable.CellCoords(0, 0))).toBe(true);
  676. });
  677. it('should return true if given cell is within the range', function () {
  678. var from = new Walkontable.CellCoords(1, 1);
  679. var to = new Walkontable.CellCoords(3, 3);
  680. var range = new Walkontable.CellRange(from, from, to);
  681. expect(range.includes(new Walkontable.CellCoords(1, 1))).toBe(true);
  682. expect(range.includes(new Walkontable.CellCoords(3, 1))).toBe(true);
  683. expect(range.includes(new Walkontable.CellCoords(3, 3))).toBe(true);
  684. expect(range.includes(new Walkontable.CellCoords(1, 3))).toBe(true);
  685. expect(range.includes(new Walkontable.CellCoords(2, 2))).toBe(true);
  686. expect(range.includes(new Walkontable.CellCoords(1, 2))).toBe(true);
  687. expect(range.includes(new Walkontable.CellCoords(2, 1))).toBe(true);
  688. });
  689. it('should return false if given cell outside the range', function () {
  690. var from = new Walkontable.CellCoords(1, 1);
  691. var to = new Walkontable.CellCoords(3, 3);
  692. var range = new Walkontable.CellRange(from, from, to);
  693. expect(range.includes(new Walkontable.CellCoords(0, 0))).toBe(false);
  694. expect(range.includes(new Walkontable.CellCoords(4, 4))).toBe(false);
  695. expect(range.includes(new Walkontable.CellCoords(1, 4))).toBe(false);
  696. expect(range.includes(new Walkontable.CellCoords(4, 1))).toBe(false);
  697. expect(range.includes(new Walkontable.CellCoords(-1, -1))).toBe(false);
  698. });
  699. });
  700. describe('includesRange', function () {
  701. describe('B has more than one cell', function () {
  702. /*
  703. +----------+
  704. | a |
  705. | +------+ |
  706. | | b | |
  707. | | | |
  708. | +------+ |
  709. +----------+
  710. */
  711. it('B is included in A, none of borders touch each other', function () {
  712. var aTopLeft = new Walkontable.CellCoords(0, 0);
  713. var aBottomRight = new Walkontable.CellCoords(5, 5);
  714. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  715. var bTopLeft = new Walkontable.CellCoords(1, 1);
  716. var bBottomRight = new Walkontable.CellCoords(4, 4);
  717. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  718. expect(a.includesRange(b)).toBe(true);
  719. });
  720. /*
  721. +----------+
  722. | b |
  723. | +------+ |
  724. | | a | |
  725. | | | |
  726. | +------+ |
  727. +----------+
  728. */
  729. it('A is included in B, none of borders touch each other', function () {
  730. var aTopLeft = new Walkontable.CellCoords(1, 1);
  731. var aBottomRight = new Walkontable.CellCoords(4, 4);
  732. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  733. var bTopLeft = new Walkontable.CellCoords(0, 0);
  734. var bBottomRight = new Walkontable.CellCoords(5, 4);
  735. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  736. expect(a.includesRange(b)).toBe(false);
  737. });
  738. /*
  739. +-----------+
  740. | a | b | |
  741. | | | |
  742. | +-----+ |
  743. +-----------+
  744. */
  745. it('B is included in A, top borders touch', function () {
  746. var aTopLeft = new Walkontable.CellCoords(0, 0);
  747. var aBottomRight = new Walkontable.CellCoords(5, 5);
  748. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  749. var bTopLeft = new Walkontable.CellCoords(0, 1);
  750. var bBottomRight = new Walkontable.CellCoords(4, 4);
  751. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  752. expect(a.includesRange(b)).toBe(true);
  753. });
  754. /*
  755. +---------+
  756. | a | b |
  757. | | |
  758. | +-----|
  759. | |
  760. +---------+
  761. */
  762. it('B is included in A, top and right borders touch', function () {
  763. var aTopLeft = new Walkontable.CellCoords(0, 0);
  764. var aBottomRight = new Walkontable.CellCoords(5, 5);
  765. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  766. var bTopLeft = new Walkontable.CellCoords(0, 1);
  767. var bBottomRight = new Walkontable.CellCoords(4, 5);
  768. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  769. expect(a.includesRange(b)).toBe(true);
  770. });
  771. /*
  772. +---------+
  773. | +-----|
  774. | a | b |
  775. | | |
  776. | +-----|
  777. +---------+
  778. */
  779. it('B is included in A, right borders touch', function () {
  780. var aTopLeft = new Walkontable.CellCoords(0, 0);
  781. var aBottomRight = new Walkontable.CellCoords(5, 5);
  782. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  783. var bTopLeft = new Walkontable.CellCoords(1, 1);
  784. var bBottomRight = new Walkontable.CellCoords(4, 5);
  785. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  786. expect(a.includesRange(b)).toBe(true);
  787. });
  788. /*
  789. +---------+
  790. | +-----|
  791. | a | b |
  792. | | |
  793. +---------+
  794. */
  795. it('B is included in A, bottom and right borders touch', function () {
  796. var aTopLeft = new Walkontable.CellCoords(0, 0);
  797. var aBottomRight = new Walkontable.CellCoords(5, 5);
  798. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  799. var bTopLeft = new Walkontable.CellCoords(1, 1);
  800. var bBottomRight = new Walkontable.CellCoords(5, 5);
  801. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  802. expect(a.includesRange(b)).toBe(true);
  803. });
  804. /*
  805. +-----------+
  806. | +-----+ |
  807. | a | b | |
  808. | | | |
  809. +-----------+
  810. */
  811. it('B is included in A, bottom borders touch', function () {
  812. var aTopLeft = new Walkontable.CellCoords(0, 0);
  813. var aBottomRight = new Walkontable.CellCoords(5, 5);
  814. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  815. var bTopLeft = new Walkontable.CellCoords(1, 1);
  816. var bBottomRight = new Walkontable.CellCoords(5, 4);
  817. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  818. expect(a.includesRange(b)).toBe(true);
  819. });
  820. /*
  821. +-----------+
  822. |-----+ a |
  823. | b | |
  824. | | |
  825. +-----------+
  826. */
  827. it('B is included in A, bottom and left borders touch', function () {
  828. var aTopLeft = new Walkontable.CellCoords(0, 0);
  829. var aBottomRight = new Walkontable.CellCoords(5, 5);
  830. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  831. var bTopLeft = new Walkontable.CellCoords(1, 0);
  832. var bBottomRight = new Walkontable.CellCoords(5, 4);
  833. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  834. expect(a.includesRange(b)).toBe(true);
  835. });
  836. /*
  837. +-----------+
  838. |-----+ a |
  839. | b | |
  840. | | |
  841. |-----+ |
  842. +-----------+
  843. */
  844. it('B is included in A, left borders touch', function () {
  845. var aTopLeft = new Walkontable.CellCoords(0, 0);
  846. var aBottomRight = new Walkontable.CellCoords(5, 5);
  847. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  848. var bTopLeft = new Walkontable.CellCoords(1, 0);
  849. var bBottomRight = new Walkontable.CellCoords(4, 4);
  850. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  851. expect(a.includesRange(b)).toBe(true);
  852. });
  853. /*
  854. +-----------+
  855. | b | a |
  856. | | |
  857. |-----+ |
  858. +-----------+
  859. */
  860. it('B is included in A, top and left borders touch', function () {
  861. var aTopLeft = new Walkontable.CellCoords(0, 0);
  862. var aBottomRight = new Walkontable.CellCoords(5, 5);
  863. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  864. var bTopLeft = new Walkontable.CellCoords(0, 0);
  865. var bBottomRight = new Walkontable.CellCoords(4, 4);
  866. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  867. expect(a.includesRange(b)).toBe(true);
  868. });
  869. /*
  870. +------------+
  871. | a | b | |
  872. | | | |
  873. +------------+
  874. */
  875. it('B is included in A, top and bottom borders touch', function () {
  876. var aTopLeft = new Walkontable.CellCoords(0, 0);
  877. var aBottomRight = new Walkontable.CellCoords(5, 5);
  878. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  879. var bTopLeft = new Walkontable.CellCoords(0, 1);
  880. var bBottomRight = new Walkontable.CellCoords(5, 4);
  881. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  882. expect(a.includesRange(b)).toBe(true);
  883. });
  884. /*
  885. +----------+
  886. | a | b |
  887. | | |
  888. +----------+
  889. */
  890. it('B is included in A, top, right and bottom borders touch', function () {
  891. var aTopLeft = new Walkontable.CellCoords(0, 0);
  892. var aBottomRight = new Walkontable.CellCoords(5, 5);
  893. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  894. var bTopLeft = new Walkontable.CellCoords(0, 1);
  895. var bBottomRight = new Walkontable.CellCoords(5, 5);
  896. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  897. expect(a.includesRange(b)).toBe(true);
  898. });
  899. /*
  900. +----------+
  901. | b | a |
  902. | | |
  903. +----------+
  904. */
  905. it('B is included in A, top, left and bottom borders touch', function () {
  906. var aTopLeft = new Walkontable.CellCoords(0, 0);
  907. var aBottomRight = new Walkontable.CellCoords(5, 5);
  908. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  909. var bTopLeft = new Walkontable.CellCoords(0, 0);
  910. var bBottomRight = new Walkontable.CellCoords(5, 4);
  911. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  912. expect(a.includesRange(b)).toBe(true);
  913. });
  914. /*
  915. +----------+
  916. | a |
  917. |----------|
  918. | b |
  919. |----------|
  920. +----------+
  921. */
  922. it('B is included in A, left and right borders touch', function () {
  923. var aTopLeft = new Walkontable.CellCoords(0, 0);
  924. var aBottomRight = new Walkontable.CellCoords(5, 5);
  925. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  926. var bTopLeft = new Walkontable.CellCoords(1, 0);
  927. var bBottomRight = new Walkontable.CellCoords(4, 5);
  928. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  929. expect(a.includesRange(b)).toBe(true);
  930. });
  931. /*
  932. +----------+
  933. | a |
  934. |----------|
  935. | b |
  936. +----------+
  937. */
  938. it('B is included in A, left, bottom and right borders touch', function () {
  939. var aTopLeft = new Walkontable.CellCoords(0, 0);
  940. var aBottomRight = new Walkontable.CellCoords(5, 5);
  941. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  942. var bTopLeft = new Walkontable.CellCoords(1, 0);
  943. var bBottomRight = new Walkontable.CellCoords(5, 5);
  944. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  945. expect(a.includesRange(b)).toBe(true);
  946. });
  947. /*
  948. +----------+
  949. | b |
  950. |----------|
  951. | a |
  952. +----------+
  953. */
  954. it('B is included in A, left, top and right borders touch', function () {
  955. var aTopLeft = new Walkontable.CellCoords(0, 0);
  956. var aBottomRight = new Walkontable.CellCoords(5, 5);
  957. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  958. var bTopLeft = new Walkontable.CellCoords(0, 0);
  959. var bBottomRight = new Walkontable.CellCoords(4, 5);
  960. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  961. expect(a.includesRange(b)).toBe(true);
  962. });
  963. });
  964. describe('B has exactly one cell', function () {
  965. /*
  966. +----------+
  967. | a |
  968. | +------+ |
  969. | | b | |
  970. | | | |
  971. | +------+ |
  972. +----------+
  973. */
  974. it('B is included in A, none of borders touch each other', function () {
  975. var aTopLeft = new Walkontable.CellCoords(0, 0);
  976. var aBottomRight = new Walkontable.CellCoords(5, 5);
  977. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  978. var bTopLeft = new Walkontable.CellCoords(1, 1);
  979. var bBottomRight = new Walkontable.CellCoords(1, 1);
  980. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  981. expect(a.includesRange(b)).toBe(true);
  982. });
  983. });
  984. });
  985. describe('expand', function () {
  986. it('should not change range if expander to a cell that fits within the range', function () {
  987. var from = new Walkontable.CellCoords(1, 1);
  988. var to = new Walkontable.CellCoords(3, 3);
  989. var range = new Walkontable.CellRange(from, from, to);
  990. var topLeft = range.getTopLeftCorner();
  991. var bottomRight = range.getBottomRightCorner();
  992. var expander = new Walkontable.CellCoords(3, 1);
  993. var res = range.expand(expander);
  994. expect(res).toBe(false);
  995. var topLeft2 = range.getTopLeftCorner();
  996. var bottomRight2 = range.getBottomRightCorner();
  997. expect(topLeft2).toEqual(topLeft);
  998. expect(bottomRight2).toEqual(bottomRight);
  999. });
  1000. it('should change range if expander to a cell outside of the cell range', function () {
  1001. var from = new Walkontable.CellCoords(1, 1);
  1002. var to = new Walkontable.CellCoords(3, 3);
  1003. var range = new Walkontable.CellRange(from, from, to);
  1004. var topLeft = range.getTopLeftCorner();
  1005. var expander = new Walkontable.CellCoords(4, 4);
  1006. var res = range.expand(expander);
  1007. expect(res).toBe(true);
  1008. var topLeft2 = range.getTopLeftCorner();
  1009. var bottomRight2 = range.getBottomRightCorner();
  1010. expect(topLeft2).toEqual(topLeft);
  1011. expect(bottomRight2).toEqual(expander);
  1012. });
  1013. it('should change range if expander to a cell outside of the cell range (inverted)', function () {
  1014. var from = new Walkontable.CellCoords(1, 1);
  1015. var to = new Walkontable.CellCoords(3, 3);
  1016. var range = new Walkontable.CellRange(from, from, to);
  1017. var topLeft = range.getTopLeftCorner();
  1018. var expander = new Walkontable.CellCoords(4, 4);
  1019. var res = range.expand(expander);
  1020. expect(res).toBe(true);
  1021. var topLeft2 = range.getTopLeftCorner();
  1022. var bottomRight2 = range.getBottomRightCorner();
  1023. expect(topLeft2).toEqual(topLeft);
  1024. expect(bottomRight2).toEqual(expander);
  1025. });
  1026. it('should change range if expander to a cell outside of the cell range (bottom left)', function () {
  1027. var from = new Walkontable.CellCoords(1, 1);
  1028. var to = new Walkontable.CellCoords(3, 3);
  1029. var range = new Walkontable.CellRange(from, from, to);
  1030. var expander = new Walkontable.CellCoords(3, 0);
  1031. var res = range.expand(expander);
  1032. expect(res).toBe(true);
  1033. var topLeft2 = range.getTopLeftCorner();
  1034. var bottomRight2 = range.getBottomRightCorner();
  1035. expect(topLeft2).toEqual(new Walkontable.CellCoords(1, 0));
  1036. expect(bottomRight2).toEqual(new Walkontable.CellCoords(3, 3));
  1037. });
  1038. it('should change range if expander to a cell outside of the cell range (inverted top right)', function () {
  1039. var from = new Walkontable.CellCoords(2, 0);
  1040. var to = new Walkontable.CellCoords(1, 0);
  1041. var range = new Walkontable.CellRange(from, from, to);
  1042. var expander = new Walkontable.CellCoords(1, 1);
  1043. var res = range.expand(expander);
  1044. expect(res).toBe(true);
  1045. var topLeft2 = range.getTopLeftCorner();
  1046. var bottomRight2 = range.getBottomRightCorner();
  1047. expect(topLeft2).toEqual(new Walkontable.CellCoords(1, 0));
  1048. expect(bottomRight2).toEqual(new Walkontable.CellCoords(2, 1));
  1049. });
  1050. it('should change range if expander to a cell outside of the cell range (inverted bottom left)', function () {
  1051. var from = new Walkontable.CellCoords(2, 1);
  1052. var to = new Walkontable.CellCoords(1, 1);
  1053. var range = new Walkontable.CellRange(from, from, to);
  1054. var expander = new Walkontable.CellCoords(3, 0);
  1055. var res = range.expand(expander);
  1056. expect(res).toBe(true);
  1057. var topLeft2 = range.getTopLeftCorner();
  1058. var bottomRight2 = range.getBottomRightCorner();
  1059. expect(topLeft2).toEqual(new Walkontable.CellCoords(1, 0));
  1060. expect(bottomRight2).toEqual(new Walkontable.CellCoords(3, 1));
  1061. });
  1062. });
  1063. describe('overlaps', function () {
  1064. describe('positive', function () {
  1065. /*
  1066. +-------+
  1067. | |
  1068. | b |
  1069. +-------+ |
  1070. | +-|-----+
  1071. | a |
  1072. | |
  1073. +-------+
  1074. */
  1075. it('overlapping from NE', function () {
  1076. var aTopLeft = new Walkontable.CellCoords(3, 0);
  1077. var aBottomRight = new Walkontable.CellCoords(8, 5);
  1078. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1079. var bTopLeft = new Walkontable.CellCoords(0, 3);
  1080. var bBottomRight = new Walkontable.CellCoords(5, 8);
  1081. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1082. expect(a.overlaps(b)).toBe(true);
  1083. });
  1084. /*
  1085. +---------+
  1086. | +-------+
  1087. | | | |
  1088. | a | | b |
  1089. | | | |
  1090. | +-------+
  1091. +---------+
  1092. */
  1093. it('overlapping from E', function () {
  1094. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1095. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1096. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1097. var bTopLeft = new Walkontable.CellCoords(1, 3);
  1098. var bBottomRight = new Walkontable.CellCoords(4, 6);
  1099. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1100. expect(a.overlaps(b)).toBe(true);
  1101. });
  1102. /*
  1103. +--------+
  1104. | |
  1105. | a |
  1106. | +---------+
  1107. | | | |
  1108. +----|---+ |
  1109. | b |
  1110. | |
  1111. +---------+
  1112. */
  1113. it('overlapping from SE', function () {
  1114. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1115. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1116. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1117. var bTopLeft = new Walkontable.CellCoords(3, 3);
  1118. var bBottomRight = new Walkontable.CellCoords(8, 8);
  1119. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1120. expect(a.overlaps(b)).toBe(true);
  1121. });
  1122. /*
  1123. +---------+
  1124. | a |
  1125. | +-----+ |
  1126. +-|-----|-+
  1127. | b |
  1128. +-----+
  1129. */
  1130. it('overlapping from S', function () {
  1131. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1132. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1133. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1134. var bTopLeft = new Walkontable.CellCoords(3, 1);
  1135. var bBottomRight = new Walkontable.CellCoords(6, 4);
  1136. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1137. expect(a.overlaps(b)).toBe(true);
  1138. });
  1139. /*
  1140. +--------+
  1141. | a |
  1142. +--------+ |
  1143. | | | |
  1144. | +----|---+
  1145. | b |
  1146. +--------+
  1147. */
  1148. it('overlapping from SW', function () {
  1149. var aTopLeft = new Walkontable.CellCoords(0, 3);
  1150. var aBottomRight = new Walkontable.CellCoords(5, 8);
  1151. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1152. var bTopLeft = new Walkontable.CellCoords(3, 0);
  1153. var bBottomRight = new Walkontable.CellCoords(8, 5);
  1154. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1155. expect(a.overlaps(b)).toBe(true);
  1156. });
  1157. /*
  1158. +-------+
  1159. +---|--+ |
  1160. | | | |
  1161. | b | | a |
  1162. | | | |
  1163. +---|--+ |
  1164. +-------+
  1165. */
  1166. it('overlapping from S', function () {
  1167. var aTopLeft = new Walkontable.CellCoords(0, 3);
  1168. var aBottomRight = new Walkontable.CellCoords(5, 8);
  1169. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1170. var bTopLeft = new Walkontable.CellCoords(1, 1);
  1171. var bBottomRight = new Walkontable.CellCoords(4, 4);
  1172. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1173. expect(a.overlaps(b)).toBe(true);
  1174. });
  1175. /*
  1176. +------+
  1177. | b |
  1178. | +-------+
  1179. | | | |
  1180. +---|--+ a |
  1181. | |
  1182. +-------+
  1183. */
  1184. it('overlapping from NW', function () {
  1185. var aTopLeft = new Walkontable.CellCoords(3, 3);
  1186. var aBottomRight = new Walkontable.CellCoords(8, 8);
  1187. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1188. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1189. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1190. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1191. expect(a.overlaps(b)).toBe(true);
  1192. });
  1193. /*
  1194. +---------+
  1195. | b |
  1196. | +-----+ |
  1197. +-|-----|-+
  1198. | a |
  1199. +-----+
  1200. */
  1201. it('overlapping from N', function () {
  1202. var aTopLeft = new Walkontable.CellCoords(3, 1);
  1203. var aBottomRight = new Walkontable.CellCoords(6, 4);
  1204. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1205. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1206. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1207. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1208. expect(a.overlaps(b)).toBe(true);
  1209. });
  1210. /*
  1211. +----------+
  1212. | a |
  1213. | +------+ |
  1214. | | b | |
  1215. | | | |
  1216. | +------+ |
  1217. +----------+
  1218. */
  1219. it('overlapping when includes', function () {
  1220. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1221. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1222. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1223. var bTopLeft = new Walkontable.CellCoords(1, 1);
  1224. var bBottomRight = new Walkontable.CellCoords(4, 4);
  1225. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1226. expect(a.overlaps(b)).toBe(true);
  1227. });
  1228. /*
  1229. +----------+
  1230. | b |
  1231. | +------+ |
  1232. | | a | |
  1233. | | | |
  1234. | +------+ |
  1235. +----------+
  1236. */
  1237. it('overlapping when included', function () {
  1238. var aTopLeft = new Walkontable.CellCoords(1, 1);
  1239. var aBottomRight = new Walkontable.CellCoords(4, 4);
  1240. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1241. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1242. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1243. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1244. expect(a.overlaps(b)).toBe(true);
  1245. });
  1246. /*
  1247. b-> +----------+
  1248. | a |
  1249. | |
  1250. | |
  1251. +----------+
  1252. */
  1253. it('overlapping when A includes B and B has only one cell, and this cell is A\'s top left corner', function () {
  1254. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1255. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1256. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1257. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1258. var bBottomRight = new Walkontable.CellCoords(0, 0);
  1259. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1260. expect(a.overlaps(b)).toBe(true);
  1261. });
  1262. /*
  1263. +----------+ <- b
  1264. | a |
  1265. | |
  1266. | |
  1267. +----------+
  1268. */
  1269. it('overlapping when A includes B and B has only one cell, and this cell is A\'s top right corner', function () {
  1270. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1271. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1272. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1273. var bTopLeft = new Walkontable.CellCoords(0, 5);
  1274. var bBottomRight = new Walkontable.CellCoords(0, 5);
  1275. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1276. expect(a.overlaps(b)).toBe(true);
  1277. });
  1278. /*
  1279. +----------+
  1280. | a |
  1281. | |
  1282. | |
  1283. b -> +----------+
  1284. */
  1285. it('overlapping when A includes B and B has only one cell, and this cell is A\'s bottom left corner', function () {
  1286. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1287. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1288. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1289. var bTopLeft = new Walkontable.CellCoords(5, 0);
  1290. var bBottomRight = new Walkontable.CellCoords(5, 0);
  1291. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1292. expect(a.overlaps(b)).toBe(true);
  1293. });
  1294. /*
  1295. +----------+
  1296. | a |
  1297. | |
  1298. | |
  1299. +----------+ <- b
  1300. */
  1301. it('overlapping when A includes B and B has only one cell, and this cell is A\'s bottom right corner', function () {
  1302. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1303. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1304. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1305. var bTopLeft = new Walkontable.CellCoords(5, 5);
  1306. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1307. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1308. expect(a.overlaps(b)).toBe(true);
  1309. });
  1310. /*
  1311. +----+
  1312. |b |
  1313. +----+----+
  1314. | a|
  1315. +----+
  1316. */
  1317. it('overlapping by touching from NE', function () {
  1318. var aTopLeft = new Walkontable.CellCoords(5, 0);
  1319. var aBottomRight = new Walkontable.CellCoords(10, 5);
  1320. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1321. var bTopLeft = new Walkontable.CellCoords(0, 5);
  1322. var bBottomRight = new Walkontable.CellCoords(5, 10);
  1323. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1324. expect(a.overlaps(b)).toBe(true);
  1325. });
  1326. /*
  1327. +----+----+
  1328. | a| b|
  1329. +----+----+
  1330. */
  1331. it('overlapping by touching from E', function () {
  1332. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1333. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1334. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1335. var bTopLeft = new Walkontable.CellCoords(0, 5);
  1336. var bBottomRight = new Walkontable.CellCoords(5, 10);
  1337. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1338. expect(a.overlaps(b)).toBe(true);
  1339. });
  1340. /*
  1341. +----+
  1342. | a|
  1343. +----+----+
  1344. | b|
  1345. +----+
  1346. */
  1347. it('overlapping by touching from SE', function () {
  1348. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1349. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1350. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1351. var bTopLeft = new Walkontable.CellCoords(5, 5);
  1352. var bBottomRight = new Walkontable.CellCoords(10, 10);
  1353. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1354. expect(a.overlaps(b)).toBe(true);
  1355. });
  1356. /*
  1357. +----+
  1358. | a|
  1359. +----+
  1360. | b|
  1361. +----+
  1362. */
  1363. it('overlapping by touching from S', function () {
  1364. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1365. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1366. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1367. var bTopLeft = new Walkontable.CellCoords(5, 5);
  1368. var bBottomRight = new Walkontable.CellCoords(10, 5);
  1369. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1370. expect(a.overlaps(b)).toBe(true);
  1371. });
  1372. /*
  1373. +----+
  1374. | a|
  1375. +----+----+
  1376. | b|
  1377. +----+
  1378. */
  1379. it('overlapping by touching from SW', function () {
  1380. var aTopLeft = new Walkontable.CellCoords(0, 5);
  1381. var aBottomRight = new Walkontable.CellCoords(5, 10);
  1382. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1383. var bTopLeft = new Walkontable.CellCoords(5, 0);
  1384. var bBottomRight = new Walkontable.CellCoords(10, 5);
  1385. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1386. expect(a.overlaps(b)).toBe(true);
  1387. });
  1388. /*
  1389. +----+----+
  1390. | b| a|
  1391. +----+----+
  1392. */
  1393. it('overlapping by touching from W', function () {
  1394. var aTopLeft = new Walkontable.CellCoords(0, 5);
  1395. var aBottomRight = new Walkontable.CellCoords(5, 10);
  1396. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1397. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1398. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1399. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1400. expect(a.overlaps(b)).toBe(true);
  1401. });
  1402. /*
  1403. +----+
  1404. | b|
  1405. +----+----+
  1406. | a|
  1407. +----+
  1408. */
  1409. it('overlapping by touching from NW', function () {
  1410. var aTopLeft = new Walkontable.CellCoords(5, 5);
  1411. var aBottomRight = new Walkontable.CellCoords(10, 10);
  1412. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1413. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1414. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1415. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1416. expect(a.overlaps(b)).toBe(true);
  1417. });
  1418. /*
  1419. +----+
  1420. | b|
  1421. +----+
  1422. | a|
  1423. +----+
  1424. */
  1425. it('overlapping by touching from E', function () {
  1426. var aTopLeft = new Walkontable.CellCoords(5, 0);
  1427. var aBottomRight = new Walkontable.CellCoords(10, 5);
  1428. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1429. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1430. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1431. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1432. expect(a.overlaps(b)).toBe(true);
  1433. });
  1434. });
  1435. describe('negative', function () {
  1436. /*
  1437. +---+
  1438. | b|
  1439. +---+
  1440. +------+
  1441. | |
  1442. | a |
  1443. | |
  1444. +------+
  1445. */
  1446. it('not overlapping from NE', function () {
  1447. var aTopLeft = new Walkontable.CellCoords(6, 0);
  1448. var aBottomRight = new Walkontable.CellCoords(11, 5);
  1449. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1450. var bTopLeft = new Walkontable.CellCoords(0, 3);
  1451. var bBottomRight = new Walkontable.CellCoords(5, 8);
  1452. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1453. expect(a.overlaps(b)).toBe(false);
  1454. });
  1455. /*
  1456. +------+
  1457. | | +--+
  1458. | a | | b|
  1459. | | +--+
  1460. +------+
  1461. */
  1462. it('not overlapping from E', function () {
  1463. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1464. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1465. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1466. var bTopLeft = new Walkontable.CellCoords(1, 6);
  1467. var bBottomRight = new Walkontable.CellCoords(4, 9);
  1468. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1469. expect(a.overlaps(b)).toBe(false);
  1470. });
  1471. /*
  1472. +----+
  1473. |a |
  1474. | | +----+
  1475. +----+ |b |
  1476. | |
  1477. +----+
  1478. */
  1479. it('not overlapping from SE', function () {
  1480. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1481. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1482. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1483. var bTopLeft = new Walkontable.CellCoords(1, 6);
  1484. var bBottomRight = new Walkontable.CellCoords(4, 9);
  1485. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1486. expect(a.overlaps(b)).toBe(false);
  1487. });
  1488. /*
  1489. +----+
  1490. |a |
  1491. | |
  1492. +----+
  1493. +----+
  1494. |b |
  1495. | |
  1496. +----+
  1497. */
  1498. it('not overlapping from S', function () {
  1499. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1500. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1501. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1502. var bTopLeft = new Walkontable.CellCoords(6, 0);
  1503. var bBottomRight = new Walkontable.CellCoords(11, 5);
  1504. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1505. expect(a.overlaps(b)).toBe(false);
  1506. });
  1507. /*
  1508. +----+
  1509. |a |
  1510. | |
  1511. +----+
  1512. +----+
  1513. |b |
  1514. | |
  1515. +----+
  1516. */
  1517. it('not overlapping from SW', function () {
  1518. var aTopLeft = new Walkontable.CellCoords(0, 3);
  1519. var aBottomRight = new Walkontable.CellCoords(5, 8);
  1520. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1521. var bTopLeft = new Walkontable.CellCoords(6, 0);
  1522. var bBottomRight = new Walkontable.CellCoords(11, 5);
  1523. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1524. expect(a.overlaps(b)).toBe(false);
  1525. });
  1526. /*
  1527. +------+
  1528. +--+ | |
  1529. | b| | a |
  1530. +--+ | |
  1531. +------+
  1532. */
  1533. it('not overlapping from W', function () {
  1534. var aTopLeft = new Walkontable.CellCoords(0, 6);
  1535. var aBottomRight = new Walkontable.CellCoords(5, 11);
  1536. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1537. var bTopLeft = new Walkontable.CellCoords(3, 0);
  1538. var bBottomRight = new Walkontable.CellCoords(6, 3);
  1539. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1540. expect(a.overlaps(b)).toBe(false);
  1541. });
  1542. /*
  1543. +----+
  1544. |b |
  1545. | | +----+
  1546. +----+ | a |
  1547. | |
  1548. +----+
  1549. */
  1550. it('not overlapping from NW', function () {
  1551. var aTopLeft = new Walkontable.CellCoords(0, 6);
  1552. var aBottomRight = new Walkontable.CellCoords(3, 11);
  1553. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1554. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1555. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1556. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1557. expect(a.overlaps(b)).toBe(false);
  1558. });
  1559. /*
  1560. +----+
  1561. |b |
  1562. +----+
  1563. +----+
  1564. | a|
  1565. +----+
  1566. */
  1567. it('not overlapping from N', function () {
  1568. var aTopLeft = new Walkontable.CellCoords(6, 0);
  1569. var aBottomRight = new Walkontable.CellCoords(11, 5);
  1570. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1571. var bTopLeft = new Walkontable.CellCoords(0, 0);
  1572. var bBottomRight = new Walkontable.CellCoords(5, 5);
  1573. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1574. expect(a.overlaps(b)).toBe(false);
  1575. });
  1576. });
  1577. });
  1578. describe('expand by range', function () {
  1579. it('should not expand range A with range B if A includes B', function () {
  1580. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1581. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1582. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1583. var bTopLeft = new Walkontable.CellCoords(2, 2);
  1584. var bBottomRight = new Walkontable.CellCoords(4, 4);
  1585. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1586. expect(a.expandByRange(b)).toBe(false);
  1587. expect(a.getTopLeftCorner().row).toEqual(0);
  1588. expect(a.getTopLeftCorner().col).toEqual(0);
  1589. expect(a.getBottomRightCorner().row).toEqual(5);
  1590. expect(a.getBottomRightCorner().col).toEqual(5);
  1591. });
  1592. it('should not expand range A with range B if A and B don\'t overlap', function () {
  1593. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1594. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1595. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1596. var bTopLeft = new Walkontable.CellCoords(10, 10);
  1597. var bBottomRight = new Walkontable.CellCoords(15, 15);
  1598. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1599. expect(a.expandByRange(b)).toBe(false);
  1600. expect(a.getTopLeftCorner().row).toEqual(0);
  1601. expect(a.getTopLeftCorner().col).toEqual(0);
  1602. expect(a.getBottomRightCorner().row).toEqual(5);
  1603. expect(a.getBottomRightCorner().col).toEqual(5);
  1604. });
  1605. it('should not expand range A with range B', function () {
  1606. var aTopLeft = new Walkontable.CellCoords(0, 0);
  1607. var aBottomRight = new Walkontable.CellCoords(5, 5);
  1608. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  1609. var bTopLeft = new Walkontable.CellCoords(2, 2);
  1610. var bBottomRight = new Walkontable.CellCoords(7, 7);
  1611. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  1612. expect(a.expandByRange(b)).toBe(true);
  1613. expect(a.getTopLeftCorner().row).toEqual(0);
  1614. expect(a.getTopLeftCorner().col).toEqual(0);
  1615. expect(a.getBottomRightCorner().row).toEqual(7);
  1616. expect(a.getBottomRightCorner().col).toEqual(7);
  1617. });
  1618. });
  1619. describe('forAll', function () {
  1620. it('callback should be called for all cells in the range', function () {
  1621. var from = new Walkontable.CellCoords(1, 1);
  1622. var to = new Walkontable.CellCoords(3, 3);
  1623. var range = new Walkontable.CellRange(from, from, to);
  1624. var forAllCallback = jasmine.createSpy('beforeColumnSortHandler');
  1625. range.forAll(forAllCallback);
  1626. expect(forAllCallback.calls.count()).toBe(9);
  1627. });
  1628. it('callback should be called with row, column parameters', function () {
  1629. var from = new Walkontable.CellCoords(1, 1);
  1630. var to = new Walkontable.CellCoords(2, 2);
  1631. var range = new Walkontable.CellRange(from, from, to);
  1632. var rows = [];
  1633. var cols = [];
  1634. range.forAll(function (row, col) {
  1635. rows.push(row);
  1636. cols.push(col);
  1637. });
  1638. expect(rows).toEqual([1, 1, 2, 2]);
  1639. expect(cols).toEqual([1, 2, 1, 2]);
  1640. });
  1641. it('iteration should be interrupted when callback returns false', function () {
  1642. var from = new Walkontable.CellCoords(1, 1);
  1643. var to = new Walkontable.CellCoords(2, 2);
  1644. var range = new Walkontable.CellRange(from, from, to);
  1645. var callCount = 0;
  1646. range.forAll(function (row, col) {
  1647. callCount++;
  1648. if (callCount == 2) {
  1649. return false;
  1650. }
  1651. });
  1652. expect(callCount).toBe(2);
  1653. });
  1654. });
  1655. describe('change direction', function () {
  1656. it('should properly change direction on NW-SE', function () {
  1657. var from = new Walkontable.CellCoords(2, 1);
  1658. var to = new Walkontable.CellCoords(1, 2);
  1659. var range = new Walkontable.CellRange(from, from, to);
  1660. expect(range.getDirection()).toBe('SW-NE');
  1661. range.setDirection('NW-SE');
  1662. expect(range.getDirection()).toBe('NW-SE');
  1663. expect(range.from.row).toBe(1);
  1664. expect(range.from.col).toBe(1);
  1665. expect(range.to.row).toBe(2);
  1666. expect(range.to.col).toBe(2);
  1667. });
  1668. it('should properly change direction on NE-SW', function () {
  1669. var from = new Walkontable.CellCoords(2, 1);
  1670. var to = new Walkontable.CellCoords(1, 2);
  1671. var range = new Walkontable.CellRange(from, from, to);
  1672. expect(range.getDirection()).toBe('SW-NE');
  1673. range.setDirection('NE-SW');
  1674. expect(range.getDirection()).toBe('NE-SW');
  1675. expect(range.from.row).toBe(1);
  1676. expect(range.from.col).toBe(2);
  1677. expect(range.to.row).toBe(2);
  1678. expect(range.to.col).toBe(1);
  1679. });
  1680. it('should properly change direction on SE-NW', function () {
  1681. var from = new Walkontable.CellCoords(1, 1);
  1682. var to = new Walkontable.CellCoords(2, 2);
  1683. var range = new Walkontable.CellRange(from, from, to);
  1684. expect(range.getDirection()).toBe('NW-SE');
  1685. range.setDirection('SE-NW');
  1686. expect(range.getDirection()).toBe('SE-NW');
  1687. expect(range.from.row).toBe(2);
  1688. expect(range.from.col).toBe(2);
  1689. expect(range.to.row).toBe(1);
  1690. expect(range.to.col).toBe(1);
  1691. });
  1692. it('should properly change direction on SW-NE', function () {
  1693. var from = new Walkontable.CellCoords(1, 1);
  1694. var to = new Walkontable.CellCoords(2, 2);
  1695. var range = new Walkontable.CellRange(from, from, to);
  1696. expect(range.getDirection()).toBe('NW-SE');
  1697. range.setDirection('SW-NE');
  1698. expect(range.getDirection()).toBe('SW-NE');
  1699. expect(range.from.row).toBe(2);
  1700. expect(range.from.col).toBe(1);
  1701. expect(range.to.row).toBe(1);
  1702. expect(range.to.col).toBe(2);
  1703. });
  1704. });
  1705. });
  1706. /***/ }),
  1707. /* 9 */
  1708. /***/ (function(module, exports, __webpack_require__) {
  1709. "use strict";
  1710. describe('WalkontableCore', function () {
  1711. var $table,
  1712. $container,
  1713. $wrapper,
  1714. debug = false;
  1715. beforeEach(function () {
  1716. $wrapper = $('<div></div>').css({ overflow: 'hidden' });
  1717. $container = $('<div></div>');
  1718. $table = $('<table></table>'); // create a table that is not attached to document
  1719. $wrapper.append($container);
  1720. $container.append($table);
  1721. $wrapper.appendTo('body');
  1722. createDataArray(100, 4);
  1723. });
  1724. afterEach(function () {
  1725. if (!debug) {
  1726. $('.wtHolder').remove();
  1727. }
  1728. $wrapper.remove();
  1729. });
  1730. it('first row should have the same text as in data source', function () {
  1731. var wt = new Walkontable.Core({
  1732. table: $table[0],
  1733. data: getData,
  1734. totalRows: getTotalRows,
  1735. totalColumns: getTotalColumns
  1736. });
  1737. wt.draw();
  1738. var TDs = $table.find('tbody tr:first td');
  1739. expect(TDs[0].innerHTML).toBe('0');
  1740. expect(TDs[1].innerHTML).toBe('a');
  1741. });
  1742. it('should bootstrap table if empty TABLE is given', function () {
  1743. $wrapper.width(200).height(200);
  1744. var wt = new Walkontable.Core({
  1745. table: $table[0],
  1746. data: getData,
  1747. totalRows: getTotalRows,
  1748. totalColumns: getTotalColumns,
  1749. renderAllRows: true
  1750. });
  1751. wt.draw();
  1752. expect($table.find('td').length).toBe(400);
  1753. });
  1754. it('should bootstrap column headers if THEAD is given', function () {
  1755. $table.remove();
  1756. $table = $('<table><thead><tr><th>A</th><th>B</th><th>C</th><th>D</th></tr></thead></table>');
  1757. $table.appendTo('body');
  1758. var wt = new Walkontable.Core({
  1759. table: $table[0],
  1760. data: getData,
  1761. totalRows: getTotalRows,
  1762. totalColumns: getTotalColumns,
  1763. rowHeaders: [function (row, TH) {
  1764. TH.innerHTML = row + 1;
  1765. }]
  1766. });
  1767. wt.draw();
  1768. expect($table.find('thead th').length).toBe(5); // include corner TH
  1769. expect($table.find('tbody tr:first th').length).toBe(1);
  1770. expect($table.find('tbody tr:first td').length).toBe(4);
  1771. });
  1772. it('should figure out how many columns to display if width param given', function () {
  1773. $wrapper.width(100);
  1774. var wt = new Walkontable.Core({
  1775. table: $table[0],
  1776. data: getData,
  1777. totalRows: getTotalRows,
  1778. totalColumns: getTotalColumns
  1779. });
  1780. wt.draw();
  1781. expect($table.find('tbody tr:first td').length).toBe(2);
  1782. });
  1783. it('should not render table that is removed from DOM', function () {
  1784. $wrapper.remove();
  1785. var wt = new Walkontable.Core({
  1786. table: $table[0],
  1787. data: getData,
  1788. totalRows: getTotalRows,
  1789. totalColumns: getTotalColumns
  1790. });
  1791. wt.draw();
  1792. expect(wt.drawn).toBe(false);
  1793. expect(wt.drawInterrupted).toBe(true);
  1794. });
  1795. it('should not render table that is `display: none`', function () {
  1796. var $div = $('<div style="display: none"></div>').appendTo('body');
  1797. $div.append($table);
  1798. var wt = new Walkontable.Core({
  1799. table: $table[0],
  1800. data: getData,
  1801. totalRows: getTotalRows,
  1802. totalColumns: getTotalColumns
  1803. });
  1804. wt.draw();
  1805. expect(wt.drawn).toBe(false);
  1806. expect(wt.drawInterrupted).toBe(true);
  1807. $div.remove();
  1808. });
  1809. it('should render empty table (limited height)', function () {
  1810. createDataArray(0, 5);
  1811. var wt = new Walkontable.Core({
  1812. table: $table[0],
  1813. data: getData,
  1814. totalRows: getTotalRows,
  1815. totalColumns: getTotalColumns
  1816. });
  1817. wt.draw();
  1818. expect(function () {
  1819. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  1820. }).not.toThrow();
  1821. });
  1822. it('should render empty table (unlimited height)', function () {
  1823. createDataArray(0, 5);
  1824. var wt = new Walkontable.Core({
  1825. table: $table[0],
  1826. data: getData,
  1827. totalRows: getTotalRows,
  1828. totalColumns: getTotalColumns
  1829. });
  1830. wt.draw();
  1831. expect(function () {
  1832. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  1833. }).not.toThrow();
  1834. });
  1835. it('should render empty then filled table (limited height)', function () {
  1836. createDataArray(0, 5);
  1837. var wt = new Walkontable.Core({
  1838. table: $table[0],
  1839. data: getData,
  1840. totalRows: getTotalRows,
  1841. totalColumns: getTotalColumns
  1842. });
  1843. wt.draw();
  1844. createDataArray(1, 5);
  1845. expect(function () {
  1846. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  1847. }).not.toThrow();
  1848. });
  1849. it('should render empty then filled table (unlimited height)', function () {
  1850. createDataArray(0, 5);
  1851. var wt = new Walkontable.Core({
  1852. table: $table[0],
  1853. data: getData,
  1854. totalRows: getTotalRows,
  1855. totalColumns: getTotalColumns
  1856. });
  1857. wt.draw();
  1858. createDataArray(1, 5);
  1859. expect(function () {
  1860. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  1861. }).not.toThrow();
  1862. });
  1863. it('should render table with rows but no columns', function () {
  1864. createDataArray(5, 0);
  1865. var wt = new Walkontable.Core({
  1866. table: $table[0],
  1867. data: getData,
  1868. totalRows: getTotalRows,
  1869. totalColumns: getTotalColumns
  1870. });
  1871. wt.draw();
  1872. expect($table.find('tbody tr').length).toBe(5);
  1873. expect($table.find('tbody td').length).toBe(0);
  1874. expect($table.find('tbody col').length).toBe(0);
  1875. });
  1876. });
  1877. /***/ }),
  1878. /* 10 */
  1879. /***/ (function(module, exports, __webpack_require__) {
  1880. "use strict";
  1881. describe('WalkontableEvent', function () {
  1882. var $table,
  1883. debug = false;
  1884. beforeEach(function () {
  1885. $table = $('<table></table>'); // create a table that is not attached to document
  1886. $table.appendTo('body');
  1887. createDataArray();
  1888. });
  1889. afterEach(function () {
  1890. if (!debug) {
  1891. $('.wtHolder').remove();
  1892. }
  1893. });
  1894. it('should call `onCellMouseDown` callback', function () {
  1895. var myCoords = null,
  1896. myTD = null,
  1897. wt = new Walkontable.Core({
  1898. table: $table[0],
  1899. data: getData,
  1900. totalRows: getTotalRows,
  1901. totalColumns: getTotalColumns,
  1902. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  1903. myCoords = coords;
  1904. myTD = TD;
  1905. }
  1906. });
  1907. wt.draw();
  1908. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  1909. $td.simulate('mousedown');
  1910. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  1911. expect(myTD).toEqual($td[0]);
  1912. });
  1913. it('should call `onCellMouseOver` callback', function () {
  1914. var myCoords = null,
  1915. myTD = null,
  1916. wt = new Walkontable.Core({
  1917. table: $table[0],
  1918. data: getData,
  1919. totalRows: getTotalRows,
  1920. totalColumns: getTotalColumns,
  1921. onCellMouseOver: function onCellMouseOver(event, coords, TD) {
  1922. myCoords = coords;
  1923. myTD = TD;
  1924. }
  1925. });
  1926. wt.draw();
  1927. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  1928. $td.simulate('mouseover');
  1929. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  1930. expect(myTD).toEqual($td[0]);
  1931. });
  1932. it('should call `onCellMouseOver` callback with correctly passed TD element when cell contains another table', function () {
  1933. var fn = jasmine.createSpy();
  1934. var wt = new Walkontable.Core({
  1935. table: $table[0],
  1936. data: [['<table style="width: 50px;"><tr><td class="test">TEST</td></tr></table>']],
  1937. totalRows: 1,
  1938. totalColumns: 1,
  1939. onCellMouseOver: fn,
  1940. cellRenderer: function cellRenderer(row, column, TD) {
  1941. TD.innerHTML = wt.wtSettings.getSetting('data', row, column);
  1942. }
  1943. });
  1944. wt.draw();
  1945. var outerTD = $table.find('tbody td:not(td.test)');
  1946. var innerTD = $table.find('tbody td.test');
  1947. innerTD.simulate('mouseover');
  1948. expect(fn.calls.argsFor(0)[2]).toBe(outerTD[0]);
  1949. });
  1950. it('should call `onCellMouseOut` callback', function () {
  1951. var myCoords = null,
  1952. myTD = null,
  1953. wt = new Walkontable.Core({
  1954. table: $table[0],
  1955. data: getData,
  1956. totalRows: getTotalRows,
  1957. totalColumns: getTotalColumns,
  1958. onCellMouseOut: function onCellMouseOut(event, coords, TD) {
  1959. myCoords = coords;
  1960. myTD = TD;
  1961. }
  1962. });
  1963. wt.draw();
  1964. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  1965. $td.simulate('mouseover');
  1966. $td.simulate('mouseout');
  1967. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  1968. expect(myTD).toEqual($td[0]);
  1969. });
  1970. it('should call `onCellMouseOut` callback with correctly passed TD element when cell contains another table', function () {
  1971. var fn = jasmine.createSpy();
  1972. var wt = new Walkontable.Core({
  1973. table: $table[0],
  1974. data: [['<table style="width: 50px;"><tr><td class="test">TEST</td></tr></table>']],
  1975. totalRows: 1,
  1976. totalColumns: 1,
  1977. onCellMouseOut: fn,
  1978. cellRenderer: function cellRenderer(row, column, TD) {
  1979. TD.innerHTML = wt.wtSettings.getSetting('data', row, column);
  1980. }
  1981. });
  1982. wt.draw();
  1983. var outerTD = $table.find('tbody td:not(td.test)');
  1984. var innerTD = $table.find('tbody td.test');
  1985. innerTD.simulate('mouseover');
  1986. innerTD.simulate('mouseout');
  1987. expect(fn.calls.argsFor(0)[2]).toBe(outerTD[0]);
  1988. });
  1989. it('should call `onCellDblClick` callback', function () {
  1990. var myCoords = null,
  1991. myTD = null,
  1992. wt = new Walkontable.Core({
  1993. table: $table[0],
  1994. data: getData,
  1995. totalRows: getTotalRows,
  1996. totalColumns: getTotalColumns,
  1997. onCellDblClick: function onCellDblClick(event, coords, TD) {
  1998. myCoords = coords;
  1999. myTD = TD;
  2000. }
  2001. });
  2002. wt.draw();
  2003. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  2004. $td.simulate('mousedown');
  2005. $td.simulate('mouseup');
  2006. $td.simulate('mousedown');
  2007. $td.simulate('mouseup');
  2008. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  2009. expect(myTD).toEqual($td[0]);
  2010. });
  2011. it('should call `onCellDblClick` callback, even when it is set only after first click', function () {
  2012. var myCoords = null,
  2013. myTD = null,
  2014. wt = new Walkontable.Core({
  2015. table: $table[0],
  2016. data: getData,
  2017. totalRows: getTotalRows,
  2018. totalColumns: getTotalColumns
  2019. });
  2020. wt.draw();
  2021. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  2022. $td.simulate('mousedown');
  2023. $td.simulate('mouseup');
  2024. $td.simulate('mousedown');
  2025. wt.update('onCellDblClick', function (event, coords, TD) {
  2026. myCoords = coords;
  2027. myTD = TD;
  2028. });
  2029. $td.simulate('mouseup');
  2030. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  2031. expect(myTD).toEqual($td[0]);
  2032. });
  2033. it('should call `onCellMouseDown` callback when clicked on TH', function () {
  2034. var called = false,
  2035. wt = new Walkontable.Core({
  2036. table: $table[0],
  2037. data: getData,
  2038. totalRows: getTotalRows,
  2039. totalColumns: getTotalColumns,
  2040. columnHeaders: [function (col, TH) {
  2041. TH.innerHTML = col + 1;
  2042. }],
  2043. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  2044. called = true;
  2045. }
  2046. });
  2047. wt.draw();
  2048. var $th = $table.find('th:first');
  2049. $th.simulate('mousedown');
  2050. expect(called).toEqual(true);
  2051. });
  2052. it('should not call `onCellMouseDown` callback when clicked on the focusable element (column headers)', function () {
  2053. var opt = ['Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'].map(function (opt) {
  2054. return '<option value="' + opt + '">' + opt + '</option>';
  2055. }).join('');
  2056. var called = false;
  2057. var wt = new Walkontable.Core({
  2058. table: $table[0],
  2059. data: getData,
  2060. totalRows: getTotalRows,
  2061. totalColumns: getTotalColumns,
  2062. columnHeaders: [function (col, TH) {
  2063. TH.innerHTML = '#' + col + '<select>' + opt + '</select>';
  2064. }],
  2065. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  2066. called = true;
  2067. }
  2068. });
  2069. wt.draw();
  2070. var select = $table.find('th:first select');
  2071. select.focus();
  2072. select.simulate('mousedown');
  2073. expect(called).toBe(false);
  2074. });
  2075. it('should not call `onCellMouseDown` callback when clicked on the focusable element (cell renderer)', function () {
  2076. var opt = ['Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'].map(function (opt) {
  2077. return '<option value="' + opt + '">' + opt + '</option>';
  2078. }).join('');
  2079. var called = false;
  2080. var wt = new Walkontable.Core({
  2081. table: $table[0],
  2082. data: getData,
  2083. totalRows: getTotalRows,
  2084. totalColumns: getTotalColumns,
  2085. cellRenderer: function cellRenderer(row, column, TD) {
  2086. TD.innerHTML = '<select>' + opt + '</select>';
  2087. },
  2088. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  2089. called = true;
  2090. }
  2091. });
  2092. wt.draw();
  2093. var select = $table.find('td:first select');
  2094. select.focus();
  2095. select.simulate('mousedown');
  2096. expect(called).toBe(false);
  2097. });
  2098. it('should call `onCellMouseOver` callback when clicked on TH', function () {
  2099. var called = false,
  2100. wt = new Walkontable.Core({
  2101. table: $table[0],
  2102. data: getData,
  2103. totalRows: getTotalRows,
  2104. totalColumns: getTotalColumns,
  2105. columnHeaders: [function (col, TH) {
  2106. TH.innerHTML = col + 1;
  2107. }],
  2108. onCellMouseOver: function onCellMouseOver(event, coords, TD) {
  2109. called = coords;
  2110. }
  2111. });
  2112. wt.draw();
  2113. var $th = $table.find('th:first');
  2114. $th.simulate('mouseover');
  2115. expect(called.row).toEqual(-1);
  2116. expect(called.col).toEqual(0);
  2117. });
  2118. it('should call `onCellDblClick` callback when clicked on TH', function () {
  2119. var called = false,
  2120. wt = new Walkontable.Core({
  2121. table: $table[0],
  2122. data: getData,
  2123. totalRows: getTotalRows,
  2124. totalColumns: getTotalColumns,
  2125. columnHeaders: [function (col, TH) {
  2126. TH.innerHTML = col + 1;
  2127. }],
  2128. onCellDblClick: function onCellDblClick(event, coords, TD) {
  2129. called = true;
  2130. }
  2131. });
  2132. wt.draw();
  2133. var $th = $table.find('th:first');
  2134. $th.simulate('mousedown');
  2135. $th.simulate('mouseup');
  2136. $th.simulate('mousedown');
  2137. $th.simulate('mouseup');
  2138. expect(called).toEqual(true);
  2139. });
  2140. it('should not call `onCellDblClick` callback when right-clicked', function () {
  2141. var called = false,
  2142. wt = new Walkontable.Core({
  2143. table: $table[0],
  2144. data: getData,
  2145. totalRows: getTotalRows,
  2146. totalColumns: getTotalColumns,
  2147. onCellDblClick: function onCellDblClick(event, coords, TD) {
  2148. called = true;
  2149. }
  2150. });
  2151. wt.draw();
  2152. var $td = $table.find('tbody tr:first td:first');
  2153. var options = {
  2154. button: 2
  2155. };
  2156. $td.simulate('mousedown', options);
  2157. $td.simulate('mouseup', options);
  2158. $td.simulate('mousedown', options);
  2159. $td.simulate('mouseup', options);
  2160. expect(called).toEqual(false);
  2161. });
  2162. it('should not call `onCellDblClick` when first mouse up came from mouse drag', function () {
  2163. var called = false,
  2164. wt = new Walkontable.Core({
  2165. table: $table[0],
  2166. data: getData,
  2167. totalRows: getTotalRows,
  2168. totalColumns: getTotalColumns,
  2169. onCellDblClick: function onCellDblClick(event, coords, TD) {
  2170. called = true;
  2171. }
  2172. });
  2173. wt.draw();
  2174. var $td = $table.find('tbody tr:first td:first');
  2175. var $td2 = $table.find('tbody tr:first td:eq(1)');
  2176. $td2.simulate('mousedown');
  2177. $td.simulate('mouseup');
  2178. $td.simulate('mousedown');
  2179. $td.simulate('mouseup');
  2180. expect(called).toEqual(false);
  2181. });
  2182. it('border click should call `onCellMouseDown` callback', function () {
  2183. var myCoords = null,
  2184. myTD = null,
  2185. wt = new Walkontable.Core({
  2186. table: $table[0],
  2187. data: getData,
  2188. totalRows: getTotalRows,
  2189. totalColumns: getTotalColumns,
  2190. selections: [new Walkontable.Selection({
  2191. className: 'current',
  2192. border: {
  2193. width: 1,
  2194. color: 'red',
  2195. style: 'solid'
  2196. }
  2197. })],
  2198. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  2199. myCoords = coords;
  2200. myTD = TD;
  2201. }
  2202. });
  2203. shimSelectionProperties(wt);
  2204. wt.selections.current.add(new Walkontable.CellCoords(1, 1));
  2205. wt.draw();
  2206. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  2207. var $border = $table.parents('.wtHolder').find('.wtBorder:first');
  2208. $border.simulate('mousedown');
  2209. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  2210. expect(myTD).toEqual($td[0]);
  2211. });
  2212. it('border click should call `onCellDblClick` callback', function () {
  2213. var myCoords = null,
  2214. myTD = null,
  2215. wt = new Walkontable.Core({
  2216. table: $table[0],
  2217. data: getData,
  2218. totalRows: getTotalRows,
  2219. totalColumns: getTotalColumns,
  2220. selections: [new Walkontable.Selection({
  2221. className: 'current',
  2222. border: {
  2223. width: 1,
  2224. color: 'red',
  2225. style: 'solid'
  2226. }
  2227. })],
  2228. onCellDblClick: function onCellDblClick(event, coords, TD) {
  2229. myCoords = coords;
  2230. myTD = TD;
  2231. }
  2232. });
  2233. shimSelectionProperties(wt);
  2234. wt.selections.current.add(new Walkontable.CellCoords(1, 1));
  2235. wt.draw();
  2236. var $td = $table.find('tbody tr:eq(1) td:eq(1)');
  2237. var $border = $table.parents('.wtHolder').find('.wtBorder:first');
  2238. $border.simulate('mousedown');
  2239. $border.simulate('mouseup');
  2240. $border.simulate('mousedown');
  2241. $border.simulate('mouseup');
  2242. expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
  2243. expect(myTD).toEqual($td[0]);
  2244. });
  2245. // corner
  2246. it('should call `onCellCornerMouseDown` callback', function () {
  2247. var clicked = false,
  2248. wt = new Walkontable.Core({
  2249. table: $table[0],
  2250. data: getData,
  2251. totalRows: getTotalRows,
  2252. totalColumns: getTotalColumns,
  2253. selections: [new Walkontable.Selection({
  2254. className: 'current',
  2255. border: {
  2256. width: 1,
  2257. color: 'red',
  2258. style: 'solid'
  2259. }
  2260. })],
  2261. onCellCornerMouseDown: function onCellCornerMouseDown(event) {
  2262. clicked = true;
  2263. }
  2264. });
  2265. shimSelectionProperties(wt);
  2266. wt.selections.current.add(new Walkontable.CellCoords(10, 2));
  2267. wt.draw();
  2268. var $td = $table.parents('.wtHolder').find('.current.corner');
  2269. $td.simulate('mousedown');
  2270. expect(clicked).toEqual(true);
  2271. });
  2272. it('should call `onCellCornerDblClick` callback, even when it is set only after first click', function () {
  2273. var clicked = false,
  2274. wt = new Walkontable.Core({
  2275. table: $table[0],
  2276. data: getData,
  2277. totalRows: getTotalRows,
  2278. totalColumns: getTotalColumns,
  2279. selections: [new Walkontable.Selection({
  2280. className: 'current',
  2281. border: {
  2282. width: 1,
  2283. color: 'red',
  2284. style: 'solid'
  2285. }
  2286. })]
  2287. });
  2288. shimSelectionProperties(wt);
  2289. wt.selections.current.add(new Walkontable.CellCoords(10, 2));
  2290. wt.draw();
  2291. var $td = $table.parents('.wtHolder').find('.current.corner');
  2292. $td.simulate('mousedown');
  2293. $td.simulate('mouseup');
  2294. $td.simulate('mousedown');
  2295. wt.update('onCellCornerDblClick', function (event) {
  2296. clicked = true;
  2297. });
  2298. $td.simulate('mouseup');
  2299. expect(clicked).toEqual(true);
  2300. });
  2301. it('should call `onDraw` callback after render', function () {
  2302. var count = 0,
  2303. wt = new Walkontable.Core({
  2304. table: $table[0],
  2305. data: getData,
  2306. totalRows: getTotalRows,
  2307. totalColumns: getTotalColumns,
  2308. onDraw: function onDraw() {
  2309. count++;
  2310. }
  2311. });
  2312. wt.draw();
  2313. expect(count).toEqual(1);
  2314. });
  2315. });
  2316. /***/ }),
  2317. /* 11 */
  2318. /***/ (function(module, exports, __webpack_require__) {
  2319. "use strict";
  2320. describe('Walkontable.ColumnFilter', function () {
  2321. describe('offsettedTH', function () {
  2322. it('should do nothing if row header is not visible', function () {
  2323. var filter = new Walkontable.ColumnFilter();
  2324. filter.countTH = 0;
  2325. expect(filter.offsettedTH(1)).toEqual(1);
  2326. });
  2327. it('should decrease n by 1 if row header is visible', function () {
  2328. var filter = new Walkontable.ColumnFilter();
  2329. filter.countTH = 1;
  2330. expect(filter.offsettedTH(1)).toEqual(0);
  2331. });
  2332. });
  2333. describe('unOffsettedTH', function () {
  2334. it('should do nothing if row header is not visible', function () {
  2335. var filter = new Walkontable.ColumnFilter();
  2336. filter.countTH = 0;
  2337. expect(filter.unOffsettedTH(1)).toEqual(1);
  2338. });
  2339. it('should increase n by 1 if row header is visible', function () {
  2340. var filter = new Walkontable.ColumnFilter();
  2341. filter.countTH = 1;
  2342. expect(filter.unOffsettedTH(0)).toEqual(1);
  2343. });
  2344. });
  2345. });
  2346. /***/ }),
  2347. /* 12 */
  2348. /***/ (function(module, exports, __webpack_require__) {
  2349. "use strict";
  2350. describe('Walkontable.RowFilter', function () {
  2351. describe('offsetted', function () {
  2352. it('should return n, when offset == 0 && n == 0', function () {
  2353. var filter = new Walkontable.RowFilter();
  2354. filter.offset = 0;
  2355. filter.total = 100;
  2356. expect(filter.offsetted(0)).toEqual(0);
  2357. });
  2358. it('should return n, when offset == 0 && n == 5', function () {
  2359. var filter = new Walkontable.RowFilter();
  2360. filter.offset = 0;
  2361. filter.total = 100;
  2362. expect(filter.offsetted(5)).toEqual(5);
  2363. });
  2364. it('should return n + 1, when offset == 1 && n == 0', function () {
  2365. var filter = new Walkontable.RowFilter();
  2366. filter.offset = 1;
  2367. filter.total = 100;
  2368. expect(filter.offsetted(0)).toEqual(1);
  2369. });
  2370. it('should return n + 5, when offset == 5 && n == 0', function () {
  2371. var filter = new Walkontable.RowFilter();
  2372. filter.offset = 5;
  2373. filter.total = 100;
  2374. expect(filter.offsetted(0)).toEqual(5);
  2375. });
  2376. });
  2377. describe('unOffsetted', function () {
  2378. it('should return n, when offset == 0 && n == 0', function () {
  2379. var filter = new Walkontable.RowFilter();
  2380. filter.offset = 0;
  2381. filter.total = 100;
  2382. expect(filter.unOffsetted(0)).toEqual(0);
  2383. });
  2384. it('should return n, when offset == 0 && n == 5', function () {
  2385. var filter = new Walkontable.RowFilter();
  2386. filter.offset = 0;
  2387. filter.total = 100;
  2388. expect(filter.unOffsetted(5)).toEqual(5);
  2389. });
  2390. it('should return n - 1, when offset == 1 && n == 0', function () {
  2391. var filter = new Walkontable.RowFilter();
  2392. filter.offset = 1;
  2393. filter.total = 100;
  2394. expect(filter.unOffsetted(1)).toEqual(0);
  2395. });
  2396. it('should return n - 5, when offset == 5 && n == 0', function () {
  2397. var filter = new Walkontable.RowFilter();
  2398. filter.offset = 5;
  2399. filter.total = 100;
  2400. expect(filter.unOffsetted(5)).toEqual(0);
  2401. });
  2402. });
  2403. describe('renderedToSource', function () {
  2404. it('should translate visible column to source', function () {
  2405. var filter = new Walkontable.RowFilter();
  2406. filter.fixedCount = 1; // only cell index 0 falls into this
  2407. filter.offset = 4;
  2408. expect(filter.renderedToSource(0)).toEqual(4);
  2409. expect(filter.renderedToSource(1)).toEqual(5);
  2410. expect(filter.renderedToSource(2)).toEqual(6);
  2411. });
  2412. });
  2413. });
  2414. /***/ }),
  2415. /* 13 */
  2416. /***/ (function(module, exports, __webpack_require__) {
  2417. "use strict";
  2418. [__webpack_require__(1)].forEach(function (req) {
  2419. req.keys().forEach(function (key) {
  2420. req(key);
  2421. });
  2422. });
  2423. /***/ }),
  2424. /* 14 */
  2425. /***/ (function(module, exports, __webpack_require__) {
  2426. "use strict";
  2427. describe('WalkontableScroll', function () {
  2428. var $table,
  2429. $container,
  2430. $wrapper,
  2431. debug = false;
  2432. beforeEach(function () {
  2433. $wrapper = $('<div></div>').css({ overflow: 'hidden' });
  2434. $container = $('<div></div>');
  2435. $table = $('<table></table>'); // create a table that is not attached to document
  2436. $wrapper.append($container);
  2437. $container.append($table);
  2438. $wrapper.appendTo('body');
  2439. createDataArray(100, 4);
  2440. });
  2441. afterEach(function () {
  2442. if (!debug) {
  2443. $('.wtHolder').remove();
  2444. }
  2445. $wrapper.remove();
  2446. });
  2447. describe('scroll', function () {
  2448. it('should scroll to last column when rowHeaders is not in use', function () {
  2449. var wt = new Walkontable.Core({
  2450. table: $table[0],
  2451. data: getData,
  2452. totalRows: getTotalRows,
  2453. totalColumns: getTotalColumns
  2454. });
  2455. wt.draw().scrollHorizontal(999).draw();
  2456. expect($table.find('tbody tr:eq(0) td:last')[0].innerHTML).toBe('c');
  2457. });
  2458. it('should scroll to last column when rowHeaders is in use', function () {
  2459. function plusOne(i) {
  2460. return i + 1;
  2461. }
  2462. var wt = new Walkontable.Core({
  2463. table: $table[0],
  2464. data: getData,
  2465. totalRows: getTotalRows,
  2466. totalColumns: getTotalColumns,
  2467. columnHeaders: [function (col, TH) {
  2468. TH.innerHTML = plusOne(col);
  2469. }],
  2470. rowHeaders: [function (row, TH) {
  2471. TH.innerHTML = plusOne(row);
  2472. }]
  2473. });
  2474. wt.draw().scrollHorizontal(999).draw();
  2475. expect($table.find('tbody tr:eq(0) td:last')[0].innerHTML).toBe('c');
  2476. });
  2477. it('scroll not scroll the viewport if all rows are visible', function () {
  2478. this.data.splice(5);
  2479. $wrapper.height(201).width(100);
  2480. var wt = new Walkontable.Core({
  2481. table: $table[0],
  2482. data: getData,
  2483. totalRows: getTotalRows,
  2484. totalColumns: getTotalColumns
  2485. });
  2486. wt.draw();
  2487. expect(wt.wtTable.getVisibleRowsCount()).toEqual(5);
  2488. wt.scrollVertical(999).draw();
  2489. expect(wt.wtTable.getCoords($table.find('tbody tr:eq(0) td:eq(0)')[0])).toEqual(new Walkontable.CellCoords(0, 0));
  2490. });
  2491. it('scroll horizontal should take totalColumns if it is smaller than width', function () {
  2492. var wt = new Walkontable.Core({
  2493. table: $table[0],
  2494. data: getData,
  2495. totalRows: getTotalRows,
  2496. totalColumns: getTotalColumns
  2497. });
  2498. wt.draw().scrollHorizontal(999).draw();
  2499. expect(wt.wtTable.getCoords($table.find('tbody tr:eq(0) td:eq(0)')[0])).toEqual(new Walkontable.CellCoords(0, 0));
  2500. });
  2501. it('scroll vertical should scroll to first row if given number smaller than 0', function () {
  2502. var wt = new Walkontable.Core({
  2503. table: $table[0],
  2504. data: getData,
  2505. totalRows: getTotalRows,
  2506. totalColumns: getTotalColumns
  2507. });
  2508. wt.draw().scrollVertical(-1).draw();
  2509. expect(wt.wtTable.getCoords($table.find('tbody tr:first td:first')[0])).toEqual(new Walkontable.CellCoords(0, 0));
  2510. });
  2511. it('scroll vertical should scroll to last row if given number bigger than totalRows', function () {
  2512. this.data.splice(20, this.data.length - 20);
  2513. var wt = new Walkontable.Core({
  2514. table: $table[0],
  2515. data: getData,
  2516. totalRows: getTotalRows,
  2517. totalColumns: getTotalColumns
  2518. });
  2519. wt.draw().scrollVertical(999).draw();
  2520. expect(wt.wtTable.getCoords($table.find('tbody tr:last td:first')[0])).toEqual(new Walkontable.CellCoords(19, 0));
  2521. });
  2522. it('scroll horizontal should scroll to first row if given number smaller than 0', function () {
  2523. var wt = new Walkontable.Core({
  2524. table: $table[0],
  2525. data: getData,
  2526. totalRows: getTotalRows,
  2527. totalColumns: getTotalColumns
  2528. });
  2529. wt.draw().scrollHorizontal(-1).draw();
  2530. expect(wt.wtTable.getCoords($table.find('tbody tr:first td:first')[0])).toEqual(new Walkontable.CellCoords(0, 0));
  2531. });
  2532. it('scroll horizontal should scroll to last row if given number bigger than totalRows', function () {
  2533. var wt = new Walkontable.Core({
  2534. table: $table[0],
  2535. data: getData,
  2536. totalRows: getTotalRows,
  2537. totalColumns: getTotalColumns
  2538. });
  2539. wt.draw().scrollHorizontal(999).draw();
  2540. expect(wt.wtTable.getCoords($table.find('tbody tr:first td:last')[0])).toEqual(new Walkontable.CellCoords(0, 3));
  2541. });
  2542. it('scroll viewport to a cell that is visible should do nothing', function () {
  2543. $wrapper.height(201).width(120);
  2544. var wt = new Walkontable.Core({
  2545. table: $table[0],
  2546. data: getData,
  2547. totalRows: getTotalRows,
  2548. totalColumns: getTotalColumns
  2549. });
  2550. wt.draw();
  2551. var tmp = wt.getViewport();
  2552. wt.scrollViewport(new Walkontable.CellCoords(0, 1)).draw();
  2553. expect(wt.getViewport()).toEqual(tmp);
  2554. });
  2555. it('scroll viewport to a cell on far right should make it visible on right edge', function () {
  2556. $wrapper.width(125).height(201);
  2557. var wt = new Walkontable.Core({
  2558. table: $table[0],
  2559. data: getData,
  2560. totalRows: getTotalRows,
  2561. totalColumns: getTotalColumns
  2562. });
  2563. wt.draw();
  2564. var height = $wrapper[0].clientHeight;
  2565. var visibleRowCount = Math.floor(height / 23);
  2566. wt.scrollViewport(new Walkontable.CellCoords(0, 2)).draw();
  2567. expect(wt.getViewport()).toEqual([0, 1, visibleRowCount - 1, 2]);
  2568. });
  2569. it('scroll viewport to a cell on far left should make it visible on left edge', function () {
  2570. $wrapper.width(100).height(201);
  2571. var wt = new Walkontable.Core({
  2572. table: $table[0],
  2573. data: getData,
  2574. totalRows: getTotalRows,
  2575. totalColumns: getTotalColumns
  2576. });
  2577. wt.draw();
  2578. var height = $wrapper[0].clientHeight;
  2579. var visibleRowCount = Math.floor(height / 23);
  2580. wt.scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  2581. expect(wt.getViewport()).toEqual([0, 3, visibleRowCount - 1, 3]);
  2582. wt.scrollViewport(new Walkontable.CellCoords(0, 1)).draw();
  2583. expect(wt.getViewport()).toEqual([0, 1, visibleRowCount - 1, 1]);
  2584. });
  2585. it('scroll viewport to a cell on far left should make it visible on left edge (with row header)', function () {
  2586. $wrapper.width(140).height(201);
  2587. var wt = new Walkontable.Core({
  2588. table: $table[0],
  2589. data: getData,
  2590. totalRows: getTotalRows,
  2591. totalColumns: getTotalColumns,
  2592. rowHeaders: [function (row, TH) {
  2593. TH.innerHTML = row + 1;
  2594. }]
  2595. });
  2596. wt.draw();
  2597. var height = $wrapper[0].clientHeight;
  2598. var visibleRowCount = Math.floor(height / 23);
  2599. wt.scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  2600. expect(wt.getViewport()).toEqual([0, 3, visibleRowCount - 1, 3]);
  2601. wt.scrollViewport(new Walkontable.CellCoords(0, 1)).draw();
  2602. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(1);
  2603. });
  2604. it('scroll viewport to a cell on far right should make it visible on right edge (with row header)', function () {
  2605. var wt = new Walkontable.Core({
  2606. table: $table[0],
  2607. data: getData,
  2608. totalRows: getTotalRows,
  2609. totalColumns: getTotalColumns,
  2610. rowHeaders: [function (row, TH) {
  2611. TH.innerHTML = row + 1;
  2612. }]
  2613. });
  2614. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 2)).draw();
  2615. expect(wt.wtTable.getCoords($table.find('tbody tr:first td:last')[0])).toEqual(new Walkontable.CellCoords(0, 3));
  2616. });
  2617. it('scroll viewport to a cell on far bottom should make it visible on bottom edge', function () {
  2618. $wrapper.width(125).height(201);
  2619. var wt = new Walkontable.Core({
  2620. table: $table[0],
  2621. data: getData,
  2622. totalRows: getTotalRows,
  2623. totalColumns: getTotalColumns
  2624. });
  2625. wt.draw();
  2626. wt.scrollViewport(new Walkontable.CellCoords(12, 0)).draw();
  2627. expect(wt.getViewport()[0]).toBeAroundValue(5);
  2628. expect(wt.getViewport()[1]).toBeAroundValue(0);
  2629. expect(wt.getViewport()[2]).toBeAroundValue(12);
  2630. expect(wt.getViewport()[3]).toBeAroundValue(1);
  2631. });
  2632. it('scroll viewport to a cell on far top should make it visible on top edge', function () {
  2633. $wrapper.width(100).height(201);
  2634. var wt = new Walkontable.Core({
  2635. table: $table[0],
  2636. data: getData,
  2637. totalRows: getTotalRows,
  2638. totalColumns: getTotalColumns
  2639. });
  2640. wt.draw();
  2641. wt.scrollViewport(new Walkontable.CellCoords(20, 0)).draw();
  2642. wt.scrollViewport(new Walkontable.CellCoords(12, 0)).draw();
  2643. expect(wt.wtTable.getCoords($table.find('tbody tr:first td:first')[0])).toEqual(new Walkontable.CellCoords(12, 0));
  2644. });
  2645. it('scroll viewport to a cell that does not exist (vertically) should throw an error', function () {
  2646. this.data.splice(20, this.data.length - 20);
  2647. expect(function () {
  2648. $wrapper.width(100).height(201);
  2649. var wt = new Walkontable.Core({
  2650. table: $table[0],
  2651. data: getData,
  2652. totalRows: getTotalRows,
  2653. totalColumns: getTotalColumns
  2654. });
  2655. wt.draw();
  2656. wt.scrollViewport(new Walkontable.CellCoords(40, 0)).draw();
  2657. }).toThrow();
  2658. });
  2659. it('scroll viewport to a cell that does not exist (horizontally) should throw an error', function () {
  2660. expect(function () {
  2661. $wrapper.width(100).height(201);
  2662. var wt = new Walkontable.Core({
  2663. table: $table[0],
  2664. data: getData,
  2665. totalRows: getTotalRows,
  2666. totalColumns: getTotalColumns
  2667. });
  2668. wt.draw();
  2669. wt.scrollViewport(new Walkontable.CellCoords(0, 40)).draw();
  2670. }).toThrow();
  2671. });
  2672. it('remove row from the last scroll page should scroll viewport a row up if needed', function () {
  2673. $wrapper.width(100).height(210);
  2674. var wt = new Walkontable.Core({
  2675. table: $table[0],
  2676. data: getData,
  2677. totalRows: getTotalRows,
  2678. totalColumns: getTotalColumns
  2679. });
  2680. wt.draw().scrollViewport(new Walkontable.CellCoords(getTotalRows() - 1, 0)).draw();
  2681. var originalViewportStartRow = wt.getViewport()[0];
  2682. this.data.splice(getTotalRows() - 4, 1); // remove row at index 96
  2683. wt.draw();
  2684. expect(originalViewportStartRow - 1).toEqual(wt.getViewport()[0]);
  2685. });
  2686. it('should scroll to last row if smaller data source is loaded that does not have currently displayed row', function () {
  2687. $wrapper.width(100).height(260);
  2688. var wt = new Walkontable.Core({
  2689. table: $table[0],
  2690. data: getData,
  2691. totalRows: getTotalRows,
  2692. totalColumns: getTotalColumns
  2693. });
  2694. wt.draw();
  2695. wt.scrollVertical(50).draw();
  2696. this.data.splice(30, this.data.length - 30);
  2697. wt.draw();
  2698. expect($table.find('tbody tr').length).toBeGreaterThan(9);
  2699. });
  2700. it('should scroll to last column if smaller data source is loaded that does not have currently displayed column', function () {
  2701. createDataArray(20, 100);
  2702. var wt = new Walkontable.Core({
  2703. table: $table[0],
  2704. data: getData,
  2705. totalRows: getTotalRows,
  2706. totalColumns: getTotalColumns
  2707. });
  2708. wt.draw().scrollHorizontal(50).draw();
  2709. createDataArray(100, 30);
  2710. wt.draw();
  2711. expect($table.find('tbody tr:first td').length).toBeGreaterThan(3);
  2712. });
  2713. it('should scroll to last row with very high rows', function () {
  2714. createDataArray(20, 100);
  2715. for (var i = 0, ilen = this.data.length; i < ilen; i++) {
  2716. this.data[i][0] += '\n this \nis \na \nmultiline \ncell';
  2717. }
  2718. $wrapper.width(260).height(201);
  2719. var wt = new Walkontable.Core({
  2720. table: $table[0],
  2721. data: getData,
  2722. totalRows: getTotalRows,
  2723. totalColumns: getTotalColumns
  2724. });
  2725. wt.draw();
  2726. wt.scrollVertical(20).draw();
  2727. expect($table.find('tbody tr:last td:first')[0]).toBe(wt.wtTable.getCell(new Walkontable.CellCoords(this.data.length - 1, 0))); // last rendered row should be last data row
  2728. });
  2729. xit('should scroll to last row with very high rows (respecting fixedRows)', function () {
  2730. createDataArray(20, 100);
  2731. for (var i = 0, ilen = this.data.length; i < ilen; i++) {
  2732. this.data[i][0] += '\n this \nis \na \nmultiline \ncell';
  2733. }
  2734. var wt = new Walkontable.Core({
  2735. table: $table[0],
  2736. data: getData,
  2737. totalRows: getTotalRows,
  2738. totalColumns: getTotalColumns,
  2739. fixedRowsTop: 2
  2740. });
  2741. wt.draw().scrollVertical(2000).draw();
  2742. expect($table.find('tbody tr:eq(0) td:first')[0]).toBe(wt.wtTable.getCell(new Walkontable.CellCoords(0, 0))); // first rendered row should fixed row 0
  2743. expect($table.find('tbody tr:eq(1) td:first')[0]).toBe(wt.wtTable.getCell(new Walkontable.CellCoords(1, 0))); // second rendered row should fixed row 1
  2744. expect($table.find('tbody tr:eq(2) td:first')[0]).toBe(wt.wtTable.getCell(new Walkontable.CellCoords(2, 0))); // third rendered row should fixed row 1
  2745. expect($table.find('tbody tr:last td:first')[0]).toBe(wt.wtTable.getCell(new Walkontable.CellCoords(this.data.length - 1, 0))); // last rendered row should be last data row
  2746. });
  2747. it('should scroll to last column with very wide cells', function () {
  2748. createDataArray(20, 100);
  2749. $wrapper.width(260).height(201);
  2750. var wt = new Walkontable.Core({
  2751. table: $table[0],
  2752. data: getData,
  2753. totalRows: getTotalRows,
  2754. totalColumns: getTotalColumns
  2755. });
  2756. wt.draw().scrollHorizontal(50).draw();
  2757. createDataArray(100, 30);
  2758. wt.draw();
  2759. expect($table.find('tbody tr:first td').length).toBeGreaterThan(3);
  2760. });
  2761. it('should scroll the desired cell to the bottom edge even if it\'s located in a fixed column', function (done) {
  2762. createDataArray(20, 100);
  2763. $wrapper.width(260).height(201);
  2764. var wt = new Walkontable.Core({
  2765. table: $table[0],
  2766. data: getData,
  2767. totalRows: getTotalRows,
  2768. totalColumns: getTotalColumns,
  2769. fixedColumnsLeft: 2
  2770. });
  2771. wt.draw().scrollViewport(new Walkontable.CellCoords(8, 1)).draw();
  2772. setTimeout(function () {
  2773. expect(wt.wtTable.getLastVisibleRow()).toBe(8);
  2774. done();
  2775. }, 20);
  2776. });
  2777. it('should update the scroll position of overlays only once, when scrolling the master table', function (done) {
  2778. createDataArray(100, 100);
  2779. $wrapper.width(260).height(201);
  2780. var topOverlayCallback = jasmine.createSpy('topOverlayCallback');
  2781. var leftOverlayCallback = jasmine.createSpy('leftOverlayCallback');
  2782. var wt = new Walkontable.Core({
  2783. table: $table[0],
  2784. data: getData,
  2785. totalRows: getTotalRows,
  2786. totalColumns: getTotalColumns,
  2787. fixedColumnsLeft: 2,
  2788. fixedRowsTop: 2
  2789. });
  2790. var masterHolder = wt.wtTable.holder;
  2791. var leftOverlayHolder = wt.wtOverlays.leftOverlay.clone.wtTable.holder;
  2792. var topOverlayHolder = wt.wtOverlays.topOverlay.clone.wtTable.holder;
  2793. topOverlayHolder.addEventListener('scroll', topOverlayCallback);
  2794. leftOverlayHolder.addEventListener('scroll', leftOverlayCallback);
  2795. wt.draw();
  2796. wt.scrollViewport(new Walkontable.CellCoords(50, 50)).draw();
  2797. setTimeout(function () {
  2798. expect(topOverlayCallback.calls.count()).toEqual(1);
  2799. expect(leftOverlayCallback.calls.count()).toEqual(1);
  2800. expect(topOverlayHolder.scrollLeft).toEqual(masterHolder.scrollLeft);
  2801. expect(leftOverlayHolder.scrollTop).toEqual(masterHolder.scrollTop);
  2802. topOverlayHolder.removeEventListener('scroll', topOverlayCallback);
  2803. leftOverlayHolder.removeEventListener('scroll', leftOverlayCallback);
  2804. done();
  2805. }, 20);
  2806. });
  2807. it('should update the scroll position of the master table only once, when scrolling the overlay', function (done) {
  2808. createDataArray(100, 100);
  2809. $wrapper.width(260).height(201);
  2810. var masterCallback = jasmine.createSpy('masterCallback');
  2811. var topOverlayCallback = jasmine.createSpy('topOverlayCallback');
  2812. var leftOverlayCallback = jasmine.createSpy('leftOverlayCallback');
  2813. var wt = new Walkontable.Core({
  2814. table: $table[0],
  2815. data: getData,
  2816. totalRows: getTotalRows,
  2817. totalColumns: getTotalColumns,
  2818. fixedColumnsLeft: 2,
  2819. fixedRowsTop: 2
  2820. });
  2821. var masterHolder = wt.wtTable.holder;
  2822. var leftOverlayHolder = wt.wtOverlays.leftOverlay.clone.wtTable.holder;
  2823. var topOverlayHolder = wt.wtOverlays.topOverlay.clone.wtTable.holder;
  2824. masterHolder.addEventListener('scroll', masterCallback);
  2825. leftOverlayHolder.addEventListener('scroll', leftOverlayCallback);
  2826. wt.draw();
  2827. topOverlayHolder.scrollLeft = 400;
  2828. wt.draw();
  2829. setTimeout(function () {
  2830. expect(masterCallback.calls.count()).toEqual(1);
  2831. expect(leftOverlayCallback.calls.count()).toEqual(0);
  2832. expect(topOverlayHolder.scrollLeft).toEqual(masterHolder.scrollLeft);
  2833. leftOverlayHolder.scrollTop = 200;
  2834. wt.draw();
  2835. }, 50);
  2836. setTimeout(function () {
  2837. expect(masterCallback.calls.count()).toEqual(2);
  2838. expect(leftOverlayCallback.calls.count()).toEqual(1);
  2839. expect(leftOverlayHolder.scrollTop).toEqual(masterHolder.scrollTop);
  2840. masterHolder.removeEventListener('scroll', masterCallback);
  2841. leftOverlayHolder.removeEventListener('scroll', leftOverlayCallback);
  2842. done();
  2843. }, 100);
  2844. });
  2845. // Commented due to PhantomJS WheelEvent problem.
  2846. // Throws an error: TypeError: '[object WheelEventConstructor]' is not a constructor
  2847. xit('should scroll the table when the `wheel` event is triggered on the corner overlay', function () {
  2848. createDataArray(100, 100);
  2849. $wrapper.width(260).height(201);
  2850. var masterCallback = jasmine.createSpy('masterCallback');
  2851. var topCallback = jasmine.createSpy('topCallback');
  2852. var leftCallback = jasmine.createSpy('leftCallback');
  2853. var wt = new Walkontable.Core({
  2854. table: $table[0],
  2855. data: getData,
  2856. totalRows: getTotalRows,
  2857. totalColumns: getTotalColumns,
  2858. fixedColumnsLeft: 2,
  2859. fixedRowsTop: 2
  2860. });
  2861. wt.draw();
  2862. var topLeftCornerOverlayHolder = wt.wtOverlays.topLeftCornerOverlay.clone.wtTable.holder;
  2863. var topHolder = wt.wtOverlays.topOverlay.clone.wtTable.holder;
  2864. var leftHolder = wt.wtOverlays.leftOverlay.clone.wtTable.holder;
  2865. var masterHolder = wt.wtTable.holder;
  2866. masterHolder.addEventListener('scroll', masterCallback);
  2867. topHolder.addEventListener('scroll', topCallback);
  2868. leftHolder.addEventListener('scroll', leftCallback);
  2869. var wheelEvent = new WheelEvent('wheel', {
  2870. deltaX: 400
  2871. });
  2872. topLeftCornerOverlayHolder.dispatchEvent(wheelEvent);
  2873. wt.draw();
  2874. waits(20);
  2875. runs(function () {
  2876. expect(masterCallback.callCount).toEqual(1);
  2877. expect(topCallback.callCount).toEqual(1);
  2878. expect(leftCallback.callCount).toEqual(0);
  2879. wheelEvent = new WheelEvent('wheel', {
  2880. deltaY: 400
  2881. });
  2882. topLeftCornerOverlayHolder.dispatchEvent(wheelEvent);
  2883. wt.draw();
  2884. });
  2885. waits(20);
  2886. runs(function () {
  2887. expect(masterCallback.callCount).toEqual(2);
  2888. expect(topCallback.callCount).toEqual(1);
  2889. expect(leftCallback.callCount).toEqual(1);
  2890. });
  2891. });
  2892. });
  2893. describe('scrollViewport - horizontally', function () {
  2894. beforeEach(function () {
  2895. $wrapper.width(201).height(201);
  2896. });
  2897. it('should scroll to last column on the right', function () {
  2898. this.data = createSpreadsheetData(10, 10);
  2899. $wrapper.width(201).height(201);
  2900. var wt = new Walkontable.Core({
  2901. table: $table[0],
  2902. data: getData,
  2903. totalRows: getTotalRows,
  2904. totalColumns: getTotalColumns,
  2905. columnWidth: 50
  2906. });
  2907. wt.draw();
  2908. expect(wt.wtTable.getLastVisibleColumn()).toEqual(2);
  2909. wt.scrollViewport(new Walkontable.CellCoords(0, 9)).draw();
  2910. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9);
  2911. });
  2912. it('should not scroll back to a column that is in viewport', function () {
  2913. this.data = createSpreadsheetData(10, 10);
  2914. var wt = new Walkontable.Core({
  2915. table: $table[0],
  2916. data: getData,
  2917. totalRows: getTotalRows,
  2918. totalColumns: getTotalColumns,
  2919. columnWidth: 50
  2920. });
  2921. wt.draw();
  2922. expect(wt.wtTable.getLastVisibleColumn()).toEqual(2);
  2923. wt.scrollViewport(new Walkontable.CellCoords(0, 9)).draw();
  2924. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9);
  2925. wt.scrollViewport(new Walkontable.CellCoords(0, 9)).draw();
  2926. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9); // nothing changed
  2927. wt.scrollViewport(new Walkontable.CellCoords(0, 8)).draw();
  2928. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9); // nothing changed
  2929. wt.scrollViewport(new Walkontable.CellCoords(0, 7)).draw();
  2930. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9); // nothing changed
  2931. });
  2932. it('should scroll back to a column that is before viewport', function () {
  2933. this.data = createSpreadsheetData(10, 10);
  2934. var wt = new Walkontable.Core({
  2935. table: $table[0],
  2936. data: getData,
  2937. totalRows: getTotalRows,
  2938. totalColumns: getTotalColumns,
  2939. columnWidth: 50
  2940. });
  2941. wt.draw();
  2942. expect(wt.wtTable.getLastVisibleColumn()).toEqual(2);
  2943. wt.scrollViewport(new Walkontable.CellCoords(0, 9)).draw();
  2944. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9);
  2945. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  2946. expect(wt.wtTable.getLastVisibleColumn()).toEqual(5);
  2947. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 4)).draw();
  2948. expect(wt.wtTable.getLastVisibleColumn()).toEqual(5); // nothing changed
  2949. wt.scrollViewport(new Walkontable.CellCoords(0, 9)).draw();
  2950. expect(wt.wtTable.getLastVisibleColumn()).toEqual(9);
  2951. });
  2952. it('should scroll to a column that is after viewport', function () {
  2953. this.data = createSpreadsheetData(10, 10);
  2954. var wt = new Walkontable.Core({
  2955. table: $table[0],
  2956. data: getData,
  2957. totalRows: getTotalRows,
  2958. totalColumns: getTotalColumns,
  2959. columnWidth: 50
  2960. });
  2961. wt.draw();
  2962. wt.scrollViewport(new Walkontable.CellCoords(0, 2)).draw();
  2963. expect(wt.wtTable.getLastVisibleColumn()).toEqual(2);
  2964. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 4)).draw();
  2965. expect(wt.wtTable.getLastVisibleColumn()).toEqual(4);
  2966. });
  2967. it('should scroll to a wide column that is after viewport', function () {
  2968. this.data = createSpreadsheetData(10, 10);
  2969. var wt = new Walkontable.Core({
  2970. table: $table[0],
  2971. data: getData,
  2972. totalRows: getTotalRows,
  2973. totalColumns: getTotalColumns,
  2974. columnWidth: function columnWidth(col) {
  2975. if (col === 3) {
  2976. return 100;
  2977. }
  2978. return 50;
  2979. }
  2980. });
  2981. wt.draw();
  2982. expect(wt.wtTable.getLastVisibleColumn()).toEqual(2);
  2983. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(0);
  2984. wt.scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  2985. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  2986. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(2);
  2987. });
  2988. xit('should scroll to a very wide column that is after viewport', function () {
  2989. this.data = createSpreadsheetData(10, 10);
  2990. var wt = new Walkontable.Core({
  2991. table: $table[0],
  2992. data: getData,
  2993. totalRows: getTotalRows,
  2994. totalColumns: getTotalColumns,
  2995. columnWidth: function columnWidth(col) {
  2996. if (col === 3) {
  2997. return 300;
  2998. }
  2999. return 50;
  3000. }
  3001. });
  3002. wt.draw();
  3003. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  3004. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(0);
  3005. wt.scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  3006. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  3007. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(3);
  3008. wt.scrollViewport(new Walkontable.CellCoords(0, 2)).draw();
  3009. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  3010. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(2);
  3011. wt.scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  3012. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  3013. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(3);
  3014. wt.scrollViewport(new Walkontable.CellCoords(0, 4)).draw();
  3015. expect(wt.wtTable.getLastVisibleColumn()).toEqual(4);
  3016. expect(wt.wtTable.getFirstVisibleColumn()).toEqual(3);
  3017. });
  3018. xit('should scroll to a very wide column that is after viewport (with fixedColumnsLeft)', function () {
  3019. this.data = createSpreadsheetData(1, 10);
  3020. var wt = new Walkontable.Core({
  3021. table: $table[0],
  3022. data: getData,
  3023. totalRows: getTotalRows,
  3024. totalColumns: getTotalColumns,
  3025. columnWidth: function columnWidth(col) {
  3026. if (col === 3) {
  3027. return 300;
  3028. }
  3029. return 50;
  3030. },
  3031. fixedColumnsLeft: 2
  3032. });
  3033. wt.draw();
  3034. wt.scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  3035. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  3036. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 2)).draw();
  3037. expect(wt.wtTable.getFirstVisibleColumn()).toBeGreaterThan(2);
  3038. expect(wt.wtTable.getLastVisibleColumn()).toBeGreaterThan(2);
  3039. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 3)).draw();
  3040. expect(wt.wtTable.getLastVisibleColumn()).toEqual(3);
  3041. wt.draw().scrollViewport(new Walkontable.CellCoords(0, 4)).draw();
  3042. expect(wt.wtTable.getLastVisibleColumn()).toEqual(4);
  3043. });
  3044. });
  3045. describe('scrollViewport - vertically', function () {
  3046. beforeEach(function () {
  3047. $wrapper.width(201).height(201);
  3048. });
  3049. xit('should scroll to a very high row that is after viewport', function () {
  3050. this.data = createSpreadsheetData(20, 1);
  3051. var txt = 'Very very very very very very very very very very very very very very very very very long text.';
  3052. this.data[4][0] = txt;
  3053. var wt = new Walkontable.Core({
  3054. table: $table[0],
  3055. data: getData,
  3056. totalRows: getTotalRows,
  3057. totalColumns: getTotalColumns
  3058. });
  3059. wt.draw();
  3060. expect(wt.wtTable.getFirstVisibleRow()).toEqual(0);
  3061. wt.scrollViewport(new Walkontable.CellCoords(4, 0)).draw();
  3062. expect(wt.wtTable.getLastVisibleRow()).toEqual(4);
  3063. wt.draw().scrollViewport(new Walkontable.CellCoords(5, 0)).draw();
  3064. expect(wt.wtTable.getLastVisibleRow()).toEqual(5);
  3065. wt.draw().scrollViewport(new Walkontable.CellCoords(4, 0)).draw();
  3066. expect(wt.wtTable.getFirstVisibleRow()).toEqual(4);
  3067. wt.draw().scrollViewport(new Walkontable.CellCoords(3, 0)).draw();
  3068. expect(wt.wtTable.getFirstVisibleRow()).toEqual(3);
  3069. });
  3070. xit('should scroll to a very high row that is after viewport (at the end)', function () {
  3071. this.data = createSpreadsheetData(20, 1);
  3072. var txt = 'Very very very very very very very very very very very very very very very very very long text.';
  3073. this.data[19][0] = txt;
  3074. var wt = new Walkontable.Core({
  3075. table: $table[0],
  3076. data: getData,
  3077. totalRows: getTotalRows,
  3078. totalColumns: getTotalColumns
  3079. });
  3080. wt.draw().scrollViewport(new Walkontable.CellCoords(18, 0)).draw();
  3081. expect($table.find('tbody tr').length).toBe(2);
  3082. expect($table.find('tbody tr:eq(0) td:eq(0)').html()).toBe('A18');
  3083. expect($table.find('tbody tr:eq(1) td:eq(0)').html()).toBe(txt);
  3084. wt.draw().scrollViewport(new Walkontable.CellCoords(19, 0)).draw();
  3085. expect($table.find('tbody tr').length).toBe(1);
  3086. expect($table.find('tbody tr:eq(0) td:eq(0)').html()).toBe(txt); // scrolled down
  3087. wt.draw().scrollViewport(new Walkontable.CellCoords(18, 0)).draw();
  3088. expect($table.find('tbody tr').length).toBe(2);
  3089. expect($table.find('tbody tr:eq(0) td:eq(0)').html()).toBe('A18'); // scrolled up
  3090. expect($table.find('tbody tr:eq(1) td:eq(0)').html()).toBe(txt);
  3091. wt.draw().scrollViewport(new Walkontable.CellCoords(17, 0)).draw();
  3092. expect($table.find('tbody tr').length).toBe(3);
  3093. expect($table.find('tbody tr:eq(0) td:eq(0)').html()).toBe('A17'); // scrolled up
  3094. expect($table.find('tbody tr:eq(1) td:eq(0)').html()).toBe('A18');
  3095. expect($table.find('tbody tr:eq(2) td:eq(0)').html()).toBe(txt);
  3096. });
  3097. });
  3098. });
  3099. /***/ }),
  3100. /* 15 */
  3101. /***/ (function(module, exports, __webpack_require__) {
  3102. "use strict";
  3103. describe('WalkontableScrollbar', function () {
  3104. var $table,
  3105. $container,
  3106. $wrapper,
  3107. debug = false;
  3108. beforeEach(function () {
  3109. $wrapper = $('<div></div>').css({ overflow: 'hidden' });
  3110. $container = $('<div></div>');
  3111. $table = $('<table></table>'); // create a table that is not attached to document
  3112. $wrapper.append($container);
  3113. $container.append($table);
  3114. $wrapper.appendTo('body');
  3115. createDataArray();
  3116. });
  3117. afterEach(function () {
  3118. if (!debug) {
  3119. $('.wtHolder').remove();
  3120. }
  3121. $wrapper.remove();
  3122. });
  3123. it('should table in DIV.wtHolder that contains 2 scrollbars', function () {
  3124. var wt = new Walkontable.Core({
  3125. table: $table[0],
  3126. data: getData,
  3127. totalRows: getTotalRows,
  3128. totalColumns: getTotalColumns
  3129. });
  3130. wt.draw();
  3131. expect($table.parents('.wtHolder').length).toEqual(1);
  3132. });
  3133. it('scrolling should have no effect when totalRows is smaller than height', function () {
  3134. this.data.splice(5, this.data.length - 5);
  3135. try {
  3136. var wt = new Walkontable.Core({
  3137. table: $table[0],
  3138. data: getData,
  3139. totalRows: getTotalRows,
  3140. totalColumns: getTotalColumns
  3141. });
  3142. wt.draw();
  3143. wt.wtOverlays.topOverlay.onScroll(1);
  3144. expect(wt.getViewport()[0]).toEqual(0);
  3145. wt.wtOverlays.topOverlay.onScroll(-1);
  3146. expect(wt.getViewport()[0]).toEqual(0);
  3147. } catch (e) {
  3148. expect(e).toBeUndefined();
  3149. }
  3150. });
  3151. });
  3152. /***/ }),
  3153. /* 16 */
  3154. /***/ (function(module, exports, __webpack_require__) {
  3155. "use strict";
  3156. describe('WalkontableScrollbarNative', function () {
  3157. var $table,
  3158. $container,
  3159. $wrapper,
  3160. debug = false;
  3161. beforeEach(function () {
  3162. $wrapper = $('<div></div>').css({ overflow: 'hidden' });
  3163. $wrapper.width(100).height(200);
  3164. $container = $('<div></div>');
  3165. $table = $('<table></table>'); // create a table that is not attached to document
  3166. $wrapper.append($container);
  3167. $container.append($table);
  3168. $wrapper.appendTo('body');
  3169. createDataArray();
  3170. });
  3171. afterEach(function () {
  3172. if (!debug) {
  3173. $('.wtHolder').remove();
  3174. }
  3175. $wrapper.remove();
  3176. });
  3177. it('initial render should be no different than the redraw (vertical)', function () {
  3178. createDataArray(100, 1);
  3179. var wt = new Walkontable.Core({
  3180. table: $table[0],
  3181. data: getData,
  3182. totalRows: getTotalRows,
  3183. totalColumns: getTotalColumns
  3184. });
  3185. wt.draw();
  3186. var tds = $table.find('td').length;
  3187. wt.draw();
  3188. expect($table.find('td').length).toEqual(tds);
  3189. });
  3190. it('initial render should be no different than the redraw (horizontal)', function () {
  3191. createDataArray(1, 50);
  3192. var wt = new Walkontable.Core({
  3193. table: $table[0],
  3194. data: getData,
  3195. totalRows: getTotalRows,
  3196. totalColumns: getTotalColumns
  3197. });
  3198. wt.draw();
  3199. var tds = $table.find('td').length;
  3200. wt.draw();
  3201. expect($table.find('td').length).toEqual(tds);
  3202. });
  3203. it('scrolling 50px down should render 2 more rows', function () {
  3204. createDataArray(20, 4);
  3205. var wt = new Walkontable.Core({
  3206. table: $table[0],
  3207. data: getData,
  3208. totalRows: getTotalRows,
  3209. totalColumns: getTotalColumns
  3210. });
  3211. wt.draw();
  3212. var lastRenderedRow = wt.wtTable.getLastRenderedRow();
  3213. $(wt.wtTable.holder).scrollTop(50);
  3214. wt.draw();
  3215. expect(wt.wtTable.getLastRenderedRow()).toEqual(lastRenderedRow + 2);
  3216. });
  3217. it('should recognize the scrollHandler properly, even if the \'overflow\' property is assigned in an external stylesheet', function () {
  3218. $wrapper.css({
  3219. overflow: ''
  3220. });
  3221. $wrapper.addClass('testOverflowHidden');
  3222. createDataArray(20, 4);
  3223. var wt = new Walkontable.Core({
  3224. table: $table[0],
  3225. data: getData,
  3226. totalRows: getTotalRows,
  3227. totalColumns: getTotalColumns
  3228. });
  3229. wt.draw();
  3230. wt.wtOverlays.topOverlay.scrollTo(3);
  3231. expect($(wt.wtTable.holder).scrollTop()).toEqual(69);
  3232. });
  3233. });
  3234. /***/ }),
  3235. /* 17 */
  3236. /***/ (function(module, exports, __webpack_require__) {
  3237. "use strict";
  3238. describe('Walkontable.Selection', function () {
  3239. var $table,
  3240. $container,
  3241. $wrapper,
  3242. debug = false;
  3243. beforeEach(function () {
  3244. $wrapper = $('<div></div>').css({ overflow: 'hidden' });
  3245. $wrapper.width(100).height(200);
  3246. $container = $('<div></div>');
  3247. $table = $('<table></table>'); // create a table that is not attached to document
  3248. $wrapper.append($container);
  3249. $container.append($table);
  3250. $wrapper.appendTo('body');
  3251. createDataArray();
  3252. });
  3253. afterEach(function () {
  3254. if (!debug) {
  3255. $('.wtHolder').remove();
  3256. }
  3257. $wrapper.remove();
  3258. });
  3259. it('should add/remove class to selection when cell is clicked', function () {
  3260. var wt = new Walkontable.Core({
  3261. table: $table[0],
  3262. data: getData,
  3263. totalRows: getTotalRows,
  3264. totalColumns: getTotalColumns,
  3265. selections: [new Walkontable.Selection({
  3266. className: 'current'
  3267. })],
  3268. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  3269. wt.selections.current.clear();
  3270. wt.selections.current.add(coords);
  3271. wt.draw();
  3272. }
  3273. });
  3274. shimSelectionProperties(wt);
  3275. wt.draw();
  3276. var $td1 = $table.find('tbody td:eq(0)');
  3277. var $td2 = $table.find('tbody td:eq(1)');
  3278. $td1.simulate('mousedown');
  3279. expect($td1.hasClass('current')).toEqual(true);
  3280. $td2.simulate('mousedown');
  3281. expect($td1.hasClass('current')).toEqual(false);
  3282. expect($td2.hasClass('current')).toEqual(true);
  3283. });
  3284. it('should add class to selection on all overlays', function () {
  3285. $wrapper.width(300).height(300);
  3286. this.data = createSpreadsheetData(10, 10);
  3287. var wt = new Walkontable.Core({
  3288. table: $table[0],
  3289. data: getData,
  3290. totalRows: getTotalRows,
  3291. totalColumns: getTotalColumns,
  3292. selections: [new Walkontable.Selection({
  3293. className: 'current'
  3294. }), new Walkontable.Selection({
  3295. className: 'area'
  3296. })],
  3297. fixedColumnsLeft: 2,
  3298. fixedRowsTop: 2
  3299. });
  3300. shimSelectionProperties(wt);
  3301. wt.selections.area.add(new Walkontable.CellCoords(1, 1));
  3302. wt.selections.area.add(new Walkontable.CellCoords(1, 2));
  3303. wt.selections.area.add(new Walkontable.CellCoords(2, 1));
  3304. wt.selections.area.add(new Walkontable.CellCoords(2, 2));
  3305. wt.draw();
  3306. var tds = $wrapper.find('td:contains(B2), td:contains(B3), td:contains(C2), td:contains(C3)');
  3307. expect(tds.length).toBeGreaterThan(4);
  3308. for (var i = 0, ilen = tds.length; i < ilen; i++) {
  3309. expect(tds[i].className).toContain('area');
  3310. }
  3311. });
  3312. it('should not add class to selection until it is rerendered', function () {
  3313. var wt = new Walkontable.Core({
  3314. table: $table[0],
  3315. data: getData,
  3316. totalRows: getTotalRows,
  3317. totalColumns: getTotalColumns,
  3318. selections: [new Walkontable.Selection({
  3319. className: 'current'
  3320. })]
  3321. });
  3322. shimSelectionProperties(wt);
  3323. wt.draw();
  3324. wt.selections.current.add(new Walkontable.CellCoords(0, 0));
  3325. var $td1 = $table.find('tbody td:eq(0)');
  3326. expect($td1.hasClass('current')).toEqual(false);
  3327. wt.draw();
  3328. expect($td1.hasClass('current')).toEqual(true);
  3329. });
  3330. it('should add/remove border to selection when cell is clicked', function (done) {
  3331. var wt = new Walkontable.Core({
  3332. table: $table[0],
  3333. data: getData,
  3334. totalRows: getTotalRows,
  3335. totalColumns: getTotalColumns,
  3336. selections: [new Walkontable.Selection({
  3337. border: {
  3338. width: 1,
  3339. color: 'red',
  3340. style: 'solid'
  3341. }
  3342. })],
  3343. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  3344. wt.selections.current.clear();
  3345. wt.selections.current.add(coords);
  3346. wt.draw();
  3347. }
  3348. });
  3349. shimSelectionProperties(wt);
  3350. wt.draw();
  3351. setTimeout(function () {
  3352. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  3353. var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
  3354. var $top = $(wt.selections.current.getBorder(wt).top); // cheat... get border for ht_master
  3355. $td1.simulate('mousedown');
  3356. var pos1 = $top.position();
  3357. expect(pos1.top).toBeGreaterThan(0);
  3358. expect(pos1.left).toBe(0);
  3359. $td2.simulate('mousedown');
  3360. var pos2 = $top.position();
  3361. expect(pos2.top).toBeGreaterThan(pos1.top);
  3362. expect(pos2.left).toBeGreaterThan(pos1.left);
  3363. done();
  3364. }, 1500);
  3365. });
  3366. it('should add a selection that is outside of the viewport', function () {
  3367. var wt = new Walkontable.Core({
  3368. table: $table[0],
  3369. data: getData,
  3370. totalRows: getTotalRows,
  3371. totalColumns: getTotalColumns,
  3372. selections: [new Walkontable.Selection({
  3373. border: {
  3374. width: 1,
  3375. color: 'red',
  3376. style: 'solid'
  3377. }
  3378. })]
  3379. });
  3380. shimSelectionProperties(wt);
  3381. wt.draw();
  3382. wt.selections.current.add([20, 0]);
  3383. expect(wt.wtTable.getCoords($table.find('tbody tr:first td:first')[0])).toEqual(new Walkontable.CellCoords(0, 0));
  3384. });
  3385. it('should not scroll the viewport after selection is cleared', function () {
  3386. var wt = new Walkontable.Core({
  3387. table: $table[0],
  3388. data: getData,
  3389. totalRows: getTotalRows,
  3390. totalColumns: getTotalColumns,
  3391. selections: [new Walkontable.Selection({
  3392. border: {
  3393. width: 1,
  3394. color: 'red',
  3395. style: 'solid'
  3396. }
  3397. })]
  3398. });
  3399. shimSelectionProperties(wt);
  3400. wt.draw();
  3401. wt.selections.current.add(new Walkontable.CellCoords(0, 0));
  3402. wt.draw();
  3403. expect(wt.wtTable.getFirstVisibleRow()).toEqual(0);
  3404. wt.scrollVertical(10).draw();
  3405. expect(wt.wtTable.getFirstVisibleRow()).toEqual(10);
  3406. expect(wt.wtTable.getLastVisibleRow()).toBeAroundValue(17);
  3407. wt.selections.current.clear();
  3408. expect(wt.wtTable.getFirstVisibleRow()).toEqual(10);
  3409. expect(wt.wtTable.getLastVisibleRow()).toBeAroundValue(17);
  3410. });
  3411. it('should clear a selection that has more than one cell', function () {
  3412. var wt = new Walkontable.Core({
  3413. table: $table[0],
  3414. data: getData,
  3415. totalRows: getTotalRows,
  3416. totalColumns: getTotalColumns,
  3417. selections: [new Walkontable.Selection({
  3418. border: {
  3419. width: 1,
  3420. color: 'red',
  3421. style: 'solid'
  3422. }
  3423. })]
  3424. });
  3425. shimSelectionProperties(wt);
  3426. wt.draw();
  3427. wt.selections.current.add(new Walkontable.CellCoords(0, 0));
  3428. wt.selections.current.add(new Walkontable.CellCoords(0, 1));
  3429. wt.selections.current.clear();
  3430. expect(wt.selections.current.cellRange).toEqual(null);
  3431. });
  3432. it('should highlight cells in selected row & column', function () {
  3433. $wrapper.width(300);
  3434. var wt = new Walkontable.Core({
  3435. table: $table[0],
  3436. data: getData,
  3437. totalRows: getTotalRows,
  3438. totalColumns: getTotalColumns,
  3439. selections: [new Walkontable.Selection({
  3440. highlightRowClassName: 'highlightRow',
  3441. highlightColumnClassName: 'highlightColumn'
  3442. })]
  3443. });
  3444. shimSelectionProperties(wt);
  3445. wt.draw();
  3446. wt.selections.current.add(new Walkontable.CellCoords(0, 0));
  3447. wt.selections.current.add(new Walkontable.CellCoords(0, 1));
  3448. wt.draw(true);
  3449. expect($table.find('.highlightRow').length).toEqual(2);
  3450. expect($table.find('.highlightColumn').length).toEqual(wt.wtTable.getRenderedRowsCount() * 2 - 2);
  3451. });
  3452. it('should highlight cells in selected row & column, when same class is shared between 2 selection definitions', function () {
  3453. $wrapper.width(300);
  3454. var wt = new Walkontable.Core({
  3455. table: $table[0],
  3456. data: getData,
  3457. totalRows: getTotalRows,
  3458. totalColumns: getTotalColumns,
  3459. selections: [new Walkontable.Selection({
  3460. highlightRowClassName: 'highlightRow',
  3461. highlightColumnClassName: 'highlightColumn'
  3462. }), new Walkontable.Selection({
  3463. highlightRowClassName: 'highlightRow',
  3464. highlightColumnClassName: 'highlightColumn'
  3465. })]
  3466. });
  3467. shimSelectionProperties(wt);
  3468. wt.draw();
  3469. wt.selections.current.add(new Walkontable.CellCoords(0, 0));
  3470. wt.draw(true);
  3471. expect($table.find('.highlightRow').length).toEqual(3);
  3472. expect($table.find('.highlightColumn').length).toEqual(wt.wtTable.getRenderedRowsCount() - 1);
  3473. });
  3474. it('should remove highlight when selection is deselected', function () {
  3475. var wt = new Walkontable.Core({
  3476. table: $table[0],
  3477. data: getData,
  3478. totalRows: getTotalRows,
  3479. totalColumns: getTotalColumns,
  3480. selections: [new Walkontable.Selection({
  3481. highlightRowClassName: 'highlightRow',
  3482. highlightColumnClassName: 'highlightColumn'
  3483. })]
  3484. });
  3485. shimSelectionProperties(wt);
  3486. wt.draw();
  3487. wt.selections.current.add(new Walkontable.CellCoords(0, 0));
  3488. wt.selections.current.add(new Walkontable.CellCoords(0, 1));
  3489. wt.draw();
  3490. wt.selections.current.clear();
  3491. wt.draw();
  3492. expect($table.find('.highlightRow').length).toEqual(0);
  3493. expect($table.find('.highlightColumn').length).toEqual(0);
  3494. });
  3495. it('should add/remove appropriate class to the row/column headers of selected cells', function () {
  3496. $wrapper.width(300);
  3497. var wt = new Walkontable.Core({
  3498. table: $table[0],
  3499. data: getData,
  3500. totalRows: getTotalRows,
  3501. totalColumns: getTotalColumns,
  3502. rowHeaders: [function (row, TH) {
  3503. TH.innerHTML = row + 1;
  3504. }],
  3505. columnHeaders: [function (row, TH) {
  3506. TH.innerHTML = row + 1;
  3507. }],
  3508. selections: [new Walkontable.Selection({
  3509. highlightRowClassName: 'highlightRow',
  3510. highlightColumnClassName: 'highlightColumn'
  3511. })]
  3512. });
  3513. shimSelectionProperties(wt);
  3514. wt.draw();
  3515. wt.selections.current.add(new Walkontable.CellCoords(1, 1));
  3516. wt.selections.current.add(new Walkontable.CellCoords(2, 2));
  3517. wt.draw();
  3518. // left side:
  3519. // -2 -> because one row is partially visible
  3520. // right side:
  3521. // *2 -> because there are 2 columns selected
  3522. // +2 -> because there are the headers
  3523. // -4 -> because 4 cells are selected = there are overlapping highlightRow class
  3524. expect($table.find('.highlightRow').length).toEqual(wt.wtViewport.columnsVisibleCalculator.count * 2 + 2 - 4);
  3525. expect($table.find('.highlightColumn').length - 2).toEqual(wt.wtViewport.rowsVisibleCalculator.count * 2 + 2 - 4);
  3526. expect($table.find('.highlightColumn').length).toEqual(14);
  3527. expect(getTableTopClone().find('.highlightColumn').length).toEqual(2);
  3528. expect(getTableTopClone().find('.highlightRow').length).toEqual(0);
  3529. expect(getTableLeftClone().find('.highlightColumn').length).toEqual(0);
  3530. expect(getTableLeftClone().find('.highlightRow').length).toEqual(2);
  3531. var $colHeaders = $table.find('thead tr:first-child th'),
  3532. $rowHeaders = $table.find('tbody tr th:first-child');
  3533. expect($colHeaders.eq(2).hasClass('highlightColumn')).toBe(true);
  3534. expect($colHeaders.eq(3).hasClass('highlightColumn')).toBe(true);
  3535. expect($rowHeaders.eq(1).hasClass('highlightRow')).toBe(true);
  3536. expect($rowHeaders.eq(2).hasClass('highlightRow')).toBe(true);
  3537. wt.selections.current.clear();
  3538. wt.draw();
  3539. expect($table.find('.highlightRow').length).toEqual(0);
  3540. expect($table.find('.highlightColumn').length).toEqual(0);
  3541. expect(getTableTopClone().find('.highlightColumn').length).toEqual(0);
  3542. expect(getTableTopClone().find('.highlightRow').length).toEqual(0);
  3543. expect(getTableLeftClone().find('.highlightColumn').length).toEqual(0);
  3544. expect(getTableLeftClone().find('.highlightRow').length).toEqual(0);
  3545. });
  3546. describe('replace', function () {
  3547. it('should replace range from property and return true', function () {
  3548. var wt = new Walkontable.Core({
  3549. table: $table[0],
  3550. data: getData,
  3551. totalRows: getTotalRows,
  3552. totalColumns: getTotalColumns,
  3553. selections: [new Walkontable.Selection({
  3554. border: {
  3555. width: 1,
  3556. color: 'red',
  3557. style: 'solid'
  3558. }
  3559. })]
  3560. });
  3561. shimSelectionProperties(wt);
  3562. wt.selections.current.add(new Walkontable.CellCoords(1, 1));
  3563. wt.selections.current.add(new Walkontable.CellCoords(3, 3));
  3564. var result = wt.selections.current.replace(new Walkontable.CellCoords(3, 3), new Walkontable.CellCoords(4, 4));
  3565. expect(result).toBe(true);
  3566. expect(wt.selections.current.getCorners()).toEqual([1, 1, 4, 4]);
  3567. });
  3568. });
  3569. });
  3570. /***/ }),
  3571. /* 18 */
  3572. /***/ (function(module, exports, __webpack_require__) {
  3573. "use strict";
  3574. describe('columnHeaders option', function () {
  3575. var $table,
  3576. $container,
  3577. $wrapper,
  3578. debug = false;
  3579. beforeEach(function () {
  3580. $wrapper = $('<div></div>').css({ overflow: 'hidden', position: 'relative' });
  3581. $wrapper.width(500).height(201);
  3582. $container = $('<div></div>');
  3583. $table = $('<table></table>'); // create a table that is not attached to document
  3584. $wrapper.append($container);
  3585. $container.append($table);
  3586. $wrapper.appendTo('body');
  3587. createDataArray();
  3588. });
  3589. afterEach(function () {
  3590. if (!debug) {
  3591. $('.wtHolder').remove();
  3592. }
  3593. $wrapper.remove();
  3594. });
  3595. it('should not add class `htColumnHeaders` when column headers are disabled', function () {
  3596. var wt = new Walkontable.Core({
  3597. table: $table[0],
  3598. data: getData,
  3599. totalRows: getTotalRows,
  3600. totalColumns: getTotalColumns
  3601. });
  3602. wt.draw();
  3603. expect($wrapper.hasClass('htColumnHeaders')).toBe(false);
  3604. });
  3605. it('should add class `htColumnHeaders` when column headers are enabled', function () {
  3606. var wt = new Walkontable.Core({
  3607. table: $table[0],
  3608. data: getData,
  3609. totalRows: getTotalRows,
  3610. totalColumns: getTotalColumns,
  3611. columnHeaders: [function (col, TH) {
  3612. TH.innerHTML = col + 1;
  3613. }]
  3614. });
  3615. wt.draw();
  3616. expect($wrapper.hasClass('htColumnHeaders')).toBe(true);
  3617. });
  3618. it('should create table with column headers', function () {
  3619. var wt = new Walkontable.Core({
  3620. table: $table[0],
  3621. data: getData,
  3622. totalRows: getTotalRows,
  3623. totalColumns: getTotalColumns,
  3624. columnHeaders: [function (col, TH) {
  3625. TH.innerHTML = col + 1;
  3626. }]
  3627. });
  3628. wt.draw();
  3629. expect($wrapper.find('.ht_clone_left colgroup col').length).toBe(0);
  3630. expect($wrapper.find('.ht_clone_left thead tr').length).toBe(1);
  3631. expect($wrapper.find('.ht_clone_left tbody tr').length).toBe(0);
  3632. expect($wrapper.find('.ht_clone_top colgroup col').length).toBe(4);
  3633. expect($wrapper.find('.ht_clone_top thead tr').length).toBe(1);
  3634. expect($wrapper.find('.ht_clone_top tbody tr').length).toBe(0);
  3635. expect($wrapper.find('.ht_master colgroup col').length).toBe(4);
  3636. expect($wrapper.find('.ht_master thead tr').length).toBe(1);
  3637. expect($wrapper.find('.ht_master tbody tr').length).toBe(9);
  3638. });
  3639. it('should create column headers with correct height when th has css `white-space: normal`', function () {
  3640. var style = $('<style>.handsontable thead th {white-space: normal;}</style>').appendTo('head');
  3641. var wt = new Walkontable.Core({
  3642. table: $table[0],
  3643. data: getData,
  3644. totalRows: getTotalRows,
  3645. totalColumns: getTotalColumns,
  3646. columnHeaders: [function (col, TH) {
  3647. TH.innerHTML = 'Client State State';
  3648. }],
  3649. columnWidth: 80
  3650. });
  3651. wt.draw();
  3652. expect($wrapper.find('.ht_clone_top thead tr').height()).toBe(43);
  3653. style.remove();
  3654. });
  3655. it('should create column headers with correct height when th has css `white-space: pre-line` (default)', function () {
  3656. var wt = new Walkontable.Core({
  3657. table: $table[0],
  3658. data: getData,
  3659. totalRows: getTotalRows,
  3660. totalColumns: getTotalColumns,
  3661. columnHeaders: [function (col, TH) {
  3662. TH.innerHTML = 'Client State State';
  3663. }],
  3664. columnWidth: 80
  3665. });
  3666. wt.draw();
  3667. expect($wrapper.find('.ht_clone_top thead tr').height()).toBe(23);
  3668. });
  3669. it('should generate column headers from function', function () {
  3670. var headers = ['Description', 2012, 2013, 2014];
  3671. var wt = new Walkontable.Core({
  3672. table: $table[0],
  3673. data: getData,
  3674. totalRows: getTotalRows,
  3675. totalColumns: getTotalColumns,
  3676. columnHeaders: [function (column, TH) {
  3677. TH.innerHTML = headers[column];
  3678. }]
  3679. });
  3680. wt.draw();
  3681. var visibleHeaders = headers.slice(0, wt.wtTable.getLastRenderedColumn() + 1); // headers for rendered columns only
  3682. expect($table.find('thead tr:first th').length).toBe(visibleHeaders.length);
  3683. expect($table.find('thead tr:first th').text()).toEqual(visibleHeaders.join(''));
  3684. });
  3685. });
  3686. /***/ }),
  3687. /* 19 */
  3688. /***/ (function(module, exports, __webpack_require__) {
  3689. "use strict";
  3690. describe('preventOverflow option', function () {
  3691. var $table,
  3692. $container,
  3693. $wrapper,
  3694. debug = false;
  3695. beforeEach(function () {
  3696. $wrapper = $('<div></div>').css({ position: 'relative' });
  3697. $wrapper.width(500).height(201);
  3698. $container = $('<div></div>');
  3699. $table = $('<table></table>'); // create a table that is not attached to document
  3700. $wrapper.append($container);
  3701. $container.append($table);
  3702. $wrapper.appendTo('body');
  3703. createDataArray(100, 100);
  3704. });
  3705. afterEach(function () {
  3706. if (!debug) {
  3707. $('.wtHolder').remove();
  3708. }
  3709. $wrapper.remove();
  3710. });
  3711. it('should set overflow to `auto` for master table when `horizontal` value is passed', function () {
  3712. var wt = new Walkontable.Core({
  3713. table: $table[0],
  3714. data: getData,
  3715. totalRows: getTotalRows,
  3716. totalColumns: getTotalColumns,
  3717. preventOverflow: function preventOverflow() {
  3718. return 'horizontal';
  3719. }
  3720. });
  3721. wt.draw();
  3722. expect($table.parents('.wtHolder').css('overflow')).toBe('auto');
  3723. expect($table.parents('.ht_master').css('overflow')).toBe('visible');
  3724. });
  3725. it('should set overflow-x to `auto` for top clone when `horizontal` value is passed', function () {
  3726. var wt = new Walkontable.Core({
  3727. table: $table[0],
  3728. data: getData,
  3729. totalRows: getTotalRows,
  3730. totalColumns: getTotalColumns,
  3731. columnHeaders: [function (column, TH) {
  3732. TH.innerHTML = column + 1;
  3733. }],
  3734. preventOverflow: function preventOverflow() {
  3735. return 'horizontal';
  3736. }
  3737. });
  3738. wt.draw();
  3739. expect($(wt.wtTable.wtRootElement.parentNode).find('.ht_clone_top .wtHolder').css('overflow-x')).toBe('auto');
  3740. expect($(wt.wtTable.wtRootElement.parentNode).find('.ht_clone_top .wtHolder').css('overflow-y')).toBe('hidden');
  3741. });
  3742. });
  3743. /***/ }),
  3744. /* 20 */
  3745. /***/ (function(module, exports, __webpack_require__) {
  3746. "use strict";
  3747. describe('rowHeaders option', function () {
  3748. var $table,
  3749. $container,
  3750. $wrapper,
  3751. debug = false;
  3752. beforeEach(function () {
  3753. $wrapper = $('<div></div>').css({ overflow: 'hidden', position: 'relative' });
  3754. $wrapper.width(500).height(201);
  3755. $container = $('<div></div>');
  3756. $table = $('<table></table>'); // create a table that is not attached to document
  3757. $wrapper.append($container);
  3758. $container.append($table);
  3759. $wrapper.appendTo('body');
  3760. createDataArray();
  3761. });
  3762. afterEach(function () {
  3763. if (!debug) {
  3764. $('.wtHolder').remove();
  3765. }
  3766. $wrapper.remove();
  3767. });
  3768. it('should not add class `htRowHeader` when row headers are disabled', function () {
  3769. var wt = new Walkontable.Core({
  3770. table: $table[0],
  3771. data: getData,
  3772. totalRows: getTotalRows,
  3773. totalColumns: getTotalColumns
  3774. });
  3775. wt.draw();
  3776. expect($wrapper.hasClass('htRowHeaders')).toBe(false);
  3777. });
  3778. it('should add class `htRowHeader` when row headers are enabled', function () {
  3779. var wt = new Walkontable.Core({
  3780. table: $table[0],
  3781. data: getData,
  3782. totalRows: getTotalRows,
  3783. totalColumns: getTotalColumns,
  3784. rowHeaders: [function (row, TH) {
  3785. TH.innerHTML = row + 1;
  3786. }]
  3787. });
  3788. wt.draw();
  3789. expect($wrapper.hasClass('htRowHeaders')).toBe(true);
  3790. });
  3791. it('should create table row headers', function () {
  3792. var wt = new Walkontable.Core({
  3793. table: $table[0],
  3794. data: getData,
  3795. totalRows: getTotalRows,
  3796. totalColumns: getTotalColumns,
  3797. rowHeaders: [function (row, TH) {
  3798. TH.innerHTML = row + 1;
  3799. }]
  3800. });
  3801. wt.draw();
  3802. expect($wrapper.find('.ht_clone_left colgroup col').length).toBe(1);
  3803. expect($wrapper.find('.ht_clone_left thead tr').length).toBe(0);
  3804. expect($wrapper.find('.ht_clone_left tbody tr').length).toBe(9);
  3805. expect($wrapper.find('.ht_clone_top colgroup col').length).toBe(0);
  3806. expect($wrapper.find('.ht_clone_top thead tr').length).toBe(0);
  3807. expect($wrapper.find('.ht_clone_top tbody tr').length).toBe(0);
  3808. expect($wrapper.find('.ht_master colgroup col').length).toBe(5);
  3809. expect($wrapper.find('.ht_master thead tr').length).toBe(0);
  3810. expect($wrapper.find('.ht_master tbody tr').length).toBe(9);
  3811. });
  3812. it('should generate headers from function', function () {
  3813. var wt = new Walkontable.Core({
  3814. table: $table[0],
  3815. data: getData,
  3816. totalRows: getTotalRows,
  3817. totalColumns: getTotalColumns,
  3818. rowHeaders: [function (row, TH) {
  3819. TH.innerHTML = row + 1;
  3820. }]
  3821. });
  3822. wt.draw();
  3823. var potentialRowCount = 9;
  3824. expect($table.find('tbody td').length).toBe(potentialRowCount * wt.wtTable.getRenderedColumnsCount()); // displayed cells
  3825. expect($table.find('tbody th').length).toBe(potentialRowCount); // 9*1=9 displayed row headers
  3826. expect($table.find('tbody tr:first th').length).toBe(1); // only one th per row
  3827. expect($table.find('tbody tr:first th')[0].innerHTML).toBe('1'); // this should be the first row header
  3828. });
  3829. it('should add \'rowHeader\' class to row header column', function () {
  3830. var wt = new Walkontable.Core({
  3831. table: $table[0],
  3832. data: getData,
  3833. totalRows: getTotalRows,
  3834. totalColumns: getTotalColumns,
  3835. rowHeaders: [function (row, TH) {
  3836. TH.innerHTML = row + 1;
  3837. }],
  3838. columnHeaders: [function (col, TH) {
  3839. TH.innerHTML = col + 1;
  3840. }]
  3841. });
  3842. wt.draw();
  3843. expect($table.find('col:first').hasClass('rowHeader')).toBe(true);
  3844. });
  3845. });
  3846. /***/ }),
  3847. /* 21 */
  3848. /***/ (function(module, exports, __webpack_require__) {
  3849. "use strict";
  3850. describe('stretchH option', function () {
  3851. var $table,
  3852. $container,
  3853. $wrapper,
  3854. debug = false;
  3855. beforeEach(function () {
  3856. $wrapper = $('<div></div>').css({ overflow: 'hidden', position: 'relative' });
  3857. $wrapper.width(500).height(201);
  3858. $container = $('<div></div>');
  3859. $table = $('<table></table>'); // create a table that is not attached to document
  3860. $wrapper.append($container);
  3861. $container.append($table);
  3862. $wrapper.appendTo('body');
  3863. createDataArray();
  3864. });
  3865. afterEach(function () {
  3866. if (!debug) {
  3867. $('.wtHolder').remove();
  3868. }
  3869. $wrapper.remove();
  3870. });
  3871. it('should stretch all visible columns when stretchH equals \'all\'', function () {
  3872. createDataArray(20, 2);
  3873. $wrapper.width(500).height(400);
  3874. var wt = new Walkontable.Core({
  3875. table: $table[0],
  3876. data: getData,
  3877. totalRows: getTotalRows,
  3878. totalColumns: getTotalColumns,
  3879. stretchH: 'all',
  3880. rowHeaders: [function (row, TH) {
  3881. TH.innerHTML = row + 1;
  3882. }]
  3883. });
  3884. wt.draw();
  3885. expect($table.outerWidth()).toBeAroundValue(wt.wtTable.holder.clientWidth);
  3886. // fix differences between Mac and Linux PhantomJS
  3887. expect($table.find('col:eq(2)').width() - $table.find('col:eq(1)').width()).toBeInArray([-1, 0, 1]);
  3888. });
  3889. it('should stretch all visible columns when stretchH equals \'all\' and window is resized', function (done) {
  3890. createDataArray(20, 2);
  3891. $wrapper.width(500).height(400);
  3892. var wt = new Walkontable.Core({
  3893. table: $table[0],
  3894. data: getData,
  3895. totalRows: getTotalRows,
  3896. totalColumns: getTotalColumns,
  3897. stretchH: 'all',
  3898. rowHeaders: [function (row, TH) {
  3899. TH.innerHTML = row + 1;
  3900. }]
  3901. });
  3902. wt.draw();
  3903. var initialTableWidth = $table.outerWidth();
  3904. expect(initialTableWidth).toBeAroundValue($table[0].clientWidth);
  3905. $wrapper.width(600).height(500);
  3906. var evt = document.createEvent('CustomEvent'); // MUST be 'CustomEvent'
  3907. evt.initCustomEvent('resize', false, false, null);
  3908. window.dispatchEvent(evt);
  3909. setTimeout(function () {
  3910. var currentTableWidth = $table.outerWidth();
  3911. expect(currentTableWidth).toBeAroundValue($table[0].clientWidth);
  3912. expect(currentTableWidth).toBeGreaterThan(initialTableWidth);
  3913. done();
  3914. }, 10);
  3915. });
  3916. it('should stretch all visible columns when stretchH equals \'all\' (when rows are of variable height)', function () {
  3917. createDataArray(20, 2);
  3918. for (var i = 0, ilen = this.data.length; i < ilen; i++) {
  3919. if (i % 2) {
  3920. this.data[i][0] += ' this is a cell that contains a lot of text, which will make it multi-line';
  3921. }
  3922. }
  3923. $wrapper.width(300);
  3924. $wrapper.css({
  3925. overflow: 'hidden'
  3926. });
  3927. var wt = new Walkontable.Core({
  3928. table: $table[0],
  3929. data: getData,
  3930. totalRows: getTotalRows,
  3931. totalColumns: getTotalColumns,
  3932. stretchH: 'all'
  3933. });
  3934. wt.draw();
  3935. var expectedColWidth = (300 - getScrollbarWidth()) / 2;
  3936. expectedColWidth = Math.floor(expectedColWidth);
  3937. var wtHider = $table.parents('.wtHider');
  3938. expect(wtHider.find('col:eq(0)').width()).toBeAroundValue(expectedColWidth);
  3939. expect(wtHider.find('col:eq(1)').width() - expectedColWidth).toBeInArray([0, 1]); // fix differences between Mac and Linux PhantomJS
  3940. });
  3941. it('should stretch last visible column when stretchH equals \'last\' (vertical scroll)', function () {
  3942. createDataArray(20, 2);
  3943. $wrapper.width(300).height(201);
  3944. var wt = new Walkontable.Core({
  3945. table: $table[0],
  3946. data: getData,
  3947. totalRows: getTotalRows,
  3948. totalColumns: getTotalColumns,
  3949. stretchH: 'last',
  3950. rowHeaders: [function (row, TH) {
  3951. TH.innerHTML = row + 1;
  3952. }]
  3953. });
  3954. wt.draw();
  3955. var wtHider = $table.parents('.wtHider');
  3956. expect(wtHider.outerWidth()).toBe(getTableWidth($table));
  3957. expect(wtHider.find('col:eq(1)').width()).toBeLessThan(wtHider.find('col:eq(2)').width());
  3958. });
  3959. it('should stretch last column when stretchH equals \'last\' (horizontal scroll)', function () {
  3960. createDataArray(5, 20);
  3961. $wrapper.width(400).height(201);
  3962. spec().data[0][19] = 'longer text';
  3963. var wt = new Walkontable.Core({
  3964. table: $table[0],
  3965. data: getData,
  3966. totalRows: getTotalRows,
  3967. totalColumns: getTotalColumns,
  3968. stretchH: 'last',
  3969. columnHeaders: [function (index, TH) {
  3970. TH.innerHTML = index + 1;
  3971. }],
  3972. columnWidth: function columnWidth(index) {
  3973. return index === 19 ? 100 : 50;
  3974. }
  3975. });
  3976. wt.draw();
  3977. wt.scrollHorizontal(19);
  3978. wt.draw();
  3979. var wtHider = $table.parents('.wtHider');
  3980. expect(wtHider.find('col:eq(6)').width()).toBe(100);
  3981. });
  3982. it('should stretch last visible column when stretchH equals \'last\' (no scrolls)', function () {
  3983. createDataArray(2, 2);
  3984. $wrapper.width(300).height(201);
  3985. var wt = new Walkontable.Core({
  3986. table: $table[0],
  3987. data: getData,
  3988. totalRows: getTotalRows,
  3989. totalColumns: getTotalColumns,
  3990. stretchH: 'last',
  3991. rowHeaders: [function (row, TH) {
  3992. TH.innerHTML = row + 1;
  3993. }]
  3994. });
  3995. wt.draw();
  3996. var wtHider = $table.parents('.wtHider');
  3997. expect(wtHider.outerWidth()).toBe(getTableWidth($table));
  3998. expect(wtHider.find('col:eq(1)').width()).toBeLessThan(wtHider.find('col:eq(2)').width());
  3999. });
  4000. it('should not stretch when stretchH equals \'none\'', function () {
  4001. createDataArray(20, 2);
  4002. $wrapper.width(300).height(201);
  4003. var wt = new Walkontable.Core({
  4004. table: $table[0],
  4005. data: getData,
  4006. totalRows: getTotalRows,
  4007. totalColumns: getTotalColumns,
  4008. stretchH: 'none',
  4009. rowHeaders: [function (row, TH) {
  4010. TH.innerHTML = row + 1;
  4011. }]
  4012. });
  4013. wt.draw();
  4014. var wtHider = $table.parents('.wtHider');
  4015. expect($table.width()).toBeLessThan($wrapper.width());
  4016. expect($table.find('col:eq(1)').width()).toBe($table.find('col:eq(2)').width());
  4017. });
  4018. });
  4019. /***/ }),
  4020. /* 22 */
  4021. /***/ (function(module, exports, __webpack_require__) {
  4022. "use strict";
  4023. describe('WalkontableTable', function () {
  4024. var $table,
  4025. $container,
  4026. $wrapper,
  4027. debug = false;
  4028. beforeEach(function () {
  4029. $wrapper = $('<div></div>').css({ overflow: 'hidden', position: 'relative' });
  4030. $wrapper.width(100).height(201);
  4031. $container = $('<div></div>');
  4032. $table = $('<table></table>'); // create a table that is not attached to document
  4033. $wrapper.append($container);
  4034. $container.append($table);
  4035. $wrapper.appendTo('body');
  4036. createDataArray();
  4037. });
  4038. afterEach(function () {
  4039. if (!debug) {
  4040. $('.wtHolder').remove();
  4041. }
  4042. $wrapper.remove();
  4043. });
  4044. it('should create as many rows as fits in height', function () {
  4045. var wt = new Walkontable.Core({
  4046. table: $table[0],
  4047. data: getData,
  4048. totalRows: getTotalRows,
  4049. totalColumns: getTotalColumns
  4050. });
  4051. wt.draw();
  4052. expect($table.find('tbody tr').length).toBe(9);
  4053. });
  4054. it('should create as many rows as in `totalRows` if it is smaller than `height`', function () {
  4055. this.data.splice(5, this.data.length - 5);
  4056. var wt = new Walkontable.Core({
  4057. table: $table[0],
  4058. data: getData,
  4059. totalRows: getTotalRows,
  4060. totalColumns: getTotalColumns
  4061. });
  4062. wt.draw();
  4063. expect($table.find('tbody tr').length).toBe(5);
  4064. });
  4065. it('first row should have as many columns as in THEAD', function () {
  4066. var wt = new Walkontable.Core({
  4067. table: $table[0],
  4068. data: getData,
  4069. totalRows: getTotalRows,
  4070. totalColumns: getTotalColumns,
  4071. columnHeaders: [function (col, TH) {
  4072. TH.innerHTML = col + 1;
  4073. }]
  4074. });
  4075. wt.draw();
  4076. expect($table.find('tbody tr:first td').length).toBe($table.find('thead th').length);
  4077. });
  4078. it('should put a blank cell in the corner if both rowHeaders and colHeaders are set', function () {
  4079. var wt = new Walkontable.Core({
  4080. table: $table[0],
  4081. data: getData,
  4082. totalRows: getTotalRows,
  4083. totalColumns: getTotalColumns,
  4084. columnHeaders: [function (col, TH) {
  4085. if (col > -1) {
  4086. TH.innerHTML = 'Column';
  4087. }
  4088. }],
  4089. rowHeaders: [function (row, TH) {
  4090. if (row > -1) {
  4091. TH.innerHTML = 'Row';
  4092. }
  4093. }]
  4094. });
  4095. wt.draw();
  4096. expect($table.find('thead tr:first th').length).toBe(wt.wtTable.getRenderedColumnsCount() + 1); // 4 columns in THEAD + 1 empty cell in the corner
  4097. expect($table.find('thead tr:first th:eq(0)')[0].innerHTML.replace(/&nbsp;/, '')).toBe(''); // corner row is empty (or contains only &nbsp;)
  4098. expect($table.find('thead tr:first th:eq(1)')[0].innerHTML).toBe('Column');
  4099. expect($table.find('tbody tr:first th:eq(0)')[0].innerHTML).toBe('Row');
  4100. });
  4101. it('getCell should only return cells from rendered rows', function () {
  4102. var wt = new Walkontable.Core({
  4103. table: $table[0],
  4104. data: getData,
  4105. totalRows: getTotalRows,
  4106. totalColumns: getTotalColumns
  4107. });
  4108. wt.draw();
  4109. expect(wt.wtTable.getCell(new Walkontable.CellCoords(7, 0)) instanceof HTMLElement).toBe(true);
  4110. expect($table.find('tr:eq(8) td:first-child').text()).toEqual(this.data[8][0].toString());
  4111. expect(wt.wtTable.getCell(new Walkontable.CellCoords(20, 0))).toBe(-2); // exit code
  4112. expect(wt.wtTable.getCell(new Walkontable.CellCoords(25, 0))).toBe(-2); // exit code
  4113. });
  4114. it('getCoords should return coords of TD', function () {
  4115. var wt = new Walkontable.Core({
  4116. table: $table[0],
  4117. data: getData,
  4118. totalRows: getTotalRows,
  4119. totalColumns: getTotalColumns
  4120. });
  4121. wt.draw();
  4122. var $td2 = $table.find('tbody tr:eq(1) td:eq(1)');
  4123. expect(wt.wtTable.getCoords($td2[0])).toEqual(new Walkontable.CellCoords(1, 1));
  4124. });
  4125. it('getCoords should return coords of TD (with row header)', function () {
  4126. $wrapper.width(300);
  4127. function plusOne(i) {
  4128. return i + 1;
  4129. }
  4130. var wt = new Walkontable.Core({
  4131. table: $table[0],
  4132. data: getData,
  4133. totalRows: getTotalRows,
  4134. totalColumns: getTotalColumns,
  4135. rowHeaders: [function (row, TH) {
  4136. TH.innerHTML = plusOne(row);
  4137. }]
  4138. });
  4139. wt.draw();
  4140. var $td2 = $table.find('tbody tr:eq(1) td:eq(1)');
  4141. expect(wt.wtTable.getCoords($td2[0])).toEqual(new Walkontable.CellCoords(1, 1));
  4142. });
  4143. it('getStretchedColumnWidth should return valid column width when stretchH is set as \'all\'', function () {
  4144. var wt = new Walkontable.Core({
  4145. table: $table[0],
  4146. data: getData,
  4147. totalRows: getTotalRows,
  4148. totalColumns: getTotalColumns,
  4149. rowHeaders: [function (row, TH) {
  4150. TH.innerHTML = row + 1;
  4151. }],
  4152. stretchH: 'all'
  4153. });
  4154. wt.draw();
  4155. wt.wtViewport.columnsRenderCalculator.refreshStretching(502);
  4156. expect(wt.wtTable.getStretchedColumnWidth(0, 50)).toBe(125);
  4157. expect(wt.wtTable.getStretchedColumnWidth(1, 50)).toBe(125);
  4158. expect(wt.wtTable.getStretchedColumnWidth(2, 50)).toBe(125);
  4159. expect(wt.wtTable.getStretchedColumnWidth(3, 50)).toBe(127);
  4160. });
  4161. it('getStretchedColumnWidth should return valid column width when stretchH is set as \'last\'', function () {
  4162. var wt = new Walkontable.Core({
  4163. table: $table[0],
  4164. data: getData,
  4165. totalRows: getTotalRows,
  4166. totalColumns: getTotalColumns,
  4167. rowHeaders: [function (row, TH) {
  4168. TH.innerHTML = row + 1;
  4169. }],
  4170. stretchH: 'last'
  4171. });
  4172. wt.draw();
  4173. wt.wtViewport.columnsRenderCalculator.refreshStretching(502);
  4174. expect(wt.wtTable.getStretchedColumnWidth(0, 50)).toBe(50);
  4175. expect(wt.wtTable.getStretchedColumnWidth(1, 50)).toBe(50);
  4176. expect(wt.wtTable.getStretchedColumnWidth(2, 50)).toBe(50);
  4177. expect(wt.wtTable.getStretchedColumnWidth(3, 50)).toBe(352);
  4178. });
  4179. it('should use custom cell renderer if provided', function () {
  4180. var wt = new Walkontable.Core({
  4181. table: $table[0],
  4182. data: getData,
  4183. totalRows: getTotalRows,
  4184. totalColumns: getTotalColumns,
  4185. cellRenderer: function cellRenderer(row, column, TD) {
  4186. var cellData = getData(row, column);
  4187. if (cellData === void 0) {
  4188. TD.innerHTML = '';
  4189. } else {
  4190. TD.innerHTML = cellData;
  4191. }
  4192. TD.className = '';
  4193. TD.style.backgroundColor = 'yellow';
  4194. }
  4195. });
  4196. wt.draw();
  4197. expect($table.find('td:first')[0].style.backgroundColor).toBe('yellow');
  4198. });
  4199. it('should remove rows if they were removed in data source', function () {
  4200. this.data.splice(8, this.data.length - 8); // second param is required by IE8
  4201. var wt = new Walkontable.Core({
  4202. table: $table[0],
  4203. data: getData,
  4204. totalRows: getTotalRows,
  4205. totalColumns: getTotalColumns
  4206. });
  4207. wt.draw();
  4208. expect($table.find('tbody tr').length).toBe(8);
  4209. this.data.splice(7, this.data.length - 7); // second param is required by IE8
  4210. wt.draw();
  4211. expect($table.find('tbody tr').length).toBe(7);
  4212. });
  4213. it('should render as much columns as the container width allows, if width is null', function () {
  4214. var wt = new Walkontable.Core({
  4215. table: $table[0],
  4216. data: getData,
  4217. totalRows: getTotalRows,
  4218. totalColumns: getTotalColumns,
  4219. columnHeaders: [function (col, TH) {
  4220. TH.innerHTML = col + 1;
  4221. }]
  4222. });
  4223. wt.draw();
  4224. expect($table.find('thead tr:first').children().length).toBe(2);
  4225. expect($table.find('tbody tr:first').children().length).toBe(2);
  4226. $wrapper.width(200);
  4227. wt.draw();
  4228. expect($table.find('thead tr:first').children().length).toBe(4);
  4229. expect($table.find('tbody tr:first').children().length).toBe(4);
  4230. });
  4231. it('should render as much columns as the container width allows, if width is null (with row header)', function () {
  4232. var wt = new Walkontable.Core({
  4233. table: $table[0],
  4234. data: getData,
  4235. totalRows: getTotalRows,
  4236. totalColumns: getTotalColumns,
  4237. rowHeaders: [function (row, TH) {
  4238. TH.innerHTML = row + 1;
  4239. }],
  4240. columnHeaders: [function (col, TH) {
  4241. TH.innerHTML = col + 1;
  4242. }]
  4243. });
  4244. wt.draw();
  4245. expect($table.find('thead tr:first').children().length).toBe(2);
  4246. expect($table.find('tbody tr:first').children().length).toBe(2);
  4247. $wrapper.width(200);
  4248. wt.draw();
  4249. expect($table.find('thead tr:first').children().length).toBe(4);
  4250. expect($table.find('tbody tr:first').children().length).toBe(4);
  4251. });
  4252. it('should use column width function to get column width', function () {
  4253. $wrapper.width(600);
  4254. var wt = new Walkontable.Core({
  4255. table: $table[0],
  4256. data: getData,
  4257. totalRows: getTotalRows,
  4258. totalColumns: getTotalColumns,
  4259. rowHeaders: [function (row, TH) {
  4260. TH.innerHTML = row + 1;
  4261. }],
  4262. columnHeaders: [function (col, TH) {
  4263. TH.innerHTML = col + 1;
  4264. }],
  4265. columnWidth: function columnWidth(column) {
  4266. return (column + 1) * 50;
  4267. }
  4268. });
  4269. wt.draw();
  4270. expect($table.find('tbody tr:first td:eq(0)').outerWidth()).toBe(50);
  4271. expect($table.find('tbody tr:first td:eq(1)').outerWidth()).toBe(100);
  4272. expect($table.find('tbody tr:first td:eq(2)').outerWidth()).toBe(150);
  4273. expect($table.find('tbody tr:first td:eq(3)').outerWidth()).toBe(200);
  4274. });
  4275. it('should use column width array to get column width', function () {
  4276. $wrapper.width(600);
  4277. var wt = new Walkontable.Core({
  4278. table: $table[0],
  4279. data: getData,
  4280. totalRows: getTotalRows,
  4281. totalColumns: getTotalColumns,
  4282. rowHeaders: [function (row, TH) {
  4283. TH.innerHTML = row + 1;
  4284. }],
  4285. columnHeaders: [function (col, TH) {
  4286. TH.innerHTML = col + 1;
  4287. }],
  4288. columnWidth: [50, 100, 150, 201]
  4289. });
  4290. wt.draw();
  4291. expect($table.find('tbody tr:first td:eq(0)').outerWidth()).toBe(50);
  4292. expect($table.find('tbody tr:first td:eq(1)').outerWidth()).toBe(100);
  4293. expect($table.find('tbody tr:first td:eq(2)').outerWidth()).toBe(150);
  4294. expect($table.find('tbody tr:first td:eq(3)').outerWidth()).toBe(201);
  4295. });
  4296. it('should use column width integer to get column width', function () {
  4297. $wrapper.width(600);
  4298. var wt = new Walkontable.Core({
  4299. table: $table[0],
  4300. data: getData,
  4301. totalRows: getTotalRows,
  4302. totalColumns: getTotalColumns,
  4303. rowHeaders: [function (row, TH) {
  4304. TH.innerHTML = row + 1;
  4305. }],
  4306. columnHeaders: [function (col, TH) {
  4307. TH.innerHTML = col + 1;
  4308. }],
  4309. columnWidth: 100
  4310. });
  4311. wt.draw();
  4312. expect($table.find('tbody tr:first td:eq(0)').outerWidth()).toBe(100);
  4313. expect($table.find('tbody tr:first td:eq(1)').outerWidth()).toBe(100);
  4314. expect($table.find('tbody tr:first td:eq(2)').outerWidth()).toBe(100);
  4315. expect($table.find('tbody tr:first td:eq(3)').outerWidth()).toBe(100);
  4316. });
  4317. it('should use column width also when there are no rows', function () {
  4318. this.data.length = 0;
  4319. $wrapper.width(600);
  4320. var wt = new Walkontable.Core({
  4321. table: $table[0],
  4322. data: getData,
  4323. totalRows: getTotalRows,
  4324. totalColumns: 4,
  4325. rowHeaders: [function (row, TH) {
  4326. TH.innerHTML = row + 1;
  4327. }],
  4328. columnHeaders: [function (col, TH) {
  4329. TH.innerHTML = col + 1;
  4330. }],
  4331. columnWidth: 100
  4332. });
  4333. wt.draw();
  4334. // start from eq(1) because eq(0) is corner header
  4335. expect($table.find('thead tr:first th:eq(1)').outerWidth()).toBe(100);
  4336. expect($table.find('thead tr:first th:eq(2)').outerWidth()).toBe(100);
  4337. expect($table.find('thead tr:first th:eq(3)').outerWidth()).toBe(100);
  4338. expect($table.find('thead tr:first th:eq(4)').outerWidth()).toBe(100);
  4339. });
  4340. it('should render a cell that is outside of the viewport horizontally', function () {
  4341. var wt = new Walkontable.Core({
  4342. table: $table[0],
  4343. data: getData,
  4344. totalRows: getTotalRows,
  4345. totalColumns: getTotalColumns
  4346. });
  4347. wt.draw();
  4348. $table.find('tbody td').html('');
  4349. wt.draw();
  4350. expect($table.find('tbody tr:first td').length).toBe(2);
  4351. });
  4352. it('should not render a cell when fastDraw == true', function () {
  4353. var count = 0,
  4354. wt = new Walkontable.Core({
  4355. table: $table[0],
  4356. data: getData,
  4357. totalRows: getTotalRows,
  4358. totalColumns: getTotalColumns,
  4359. cellRenderer: function cellRenderer(row, column, TD) {
  4360. count++;
  4361. return wt.wtSettings.defaults.cellRenderer(row, column, TD);
  4362. }
  4363. });
  4364. wt.draw();
  4365. var oldCount = count;
  4366. wt.draw(true);
  4367. expect(count).toBe(oldCount);
  4368. });
  4369. it('should not ignore fastDraw == true when grid was scrolled by amount of rows that doesn\'t exceed endRow', function () {
  4370. var count = 0,
  4371. wt = new Walkontable.Core({
  4372. table: $table[0],
  4373. data: getData,
  4374. totalRows: getTotalRows,
  4375. totalColumns: getTotalColumns,
  4376. cellRenderer: function cellRenderer(row, column, TD) {
  4377. count++;
  4378. return wt.wtSettings.defaults.cellRenderer(row, column, TD);
  4379. },
  4380. viewportRowCalculatorOverride: function viewportRowCalculatorOverride(calc) {
  4381. calc.endRow += 10;
  4382. }
  4383. });
  4384. wt.draw();
  4385. var oldCount = count;
  4386. wt.scrollVertical(8);
  4387. wt.draw(true);
  4388. expect(count).not.toBeGreaterThan(oldCount);
  4389. });
  4390. it('should ignore fastDraw == true when grid was scrolled by amount of rows that exceeds endRow', function () {
  4391. var count = 0,
  4392. wt = new Walkontable.Core({
  4393. table: $table[0],
  4394. data: getData,
  4395. totalRows: getTotalRows,
  4396. totalColumns: getTotalColumns,
  4397. cellRenderer: function cellRenderer(row, column, TD) {
  4398. count++;
  4399. return wt.wtSettings.defaults.cellRenderer(row, column, TD);
  4400. },
  4401. viewportRowCalculatorOverride: function viewportRowCalculatorOverride(calc) {
  4402. calc.endRow += 10;
  4403. }
  4404. });
  4405. wt.draw();
  4406. var oldCount = count;
  4407. wt.scrollVertical(10);
  4408. wt.draw(true);
  4409. expect(count).not.toBeGreaterThan(oldCount);
  4410. wt.scrollVertical(11);
  4411. wt.draw(true);
  4412. expect(count).toBeGreaterThan(oldCount);
  4413. });
  4414. it('should not ignore fastDraw == true when grid was scrolled by amount of columns that doesn\'t exceed endColumn', function () {
  4415. createDataArray(50, 50);
  4416. var count = 0,
  4417. wt = new Walkontable.Core({
  4418. table: $table[0],
  4419. data: getData,
  4420. totalRows: getTotalRows,
  4421. totalColumns: getTotalColumns,
  4422. cellRenderer: function cellRenderer(row, column, TD) {
  4423. count++;
  4424. return wt.wtSettings.defaults.cellRenderer(row, column, TD);
  4425. },
  4426. viewportColumnCalculatorOverride: function viewportColumnCalculatorOverride(calc) {
  4427. calc.endColumn += 10;
  4428. }
  4429. });
  4430. wt.draw();
  4431. var oldCount = count;
  4432. wt.scrollHorizontal(8);
  4433. wt.draw(true);
  4434. expect(count).not.toBeGreaterThan(oldCount);
  4435. });
  4436. it('should ignore fastDraw == true when grid was scrolled by amount of columns that exceeds endColumn', function () {
  4437. createDataArray(50, 50);
  4438. var count = 0,
  4439. wt = new Walkontable.Core({
  4440. table: $table[0],
  4441. data: getData,
  4442. totalRows: getTotalRows,
  4443. totalColumns: getTotalColumns,
  4444. cellRenderer: function cellRenderer(row, column, TD) {
  4445. count++;
  4446. return wt.wtSettings.defaults.cellRenderer(row, column, TD);
  4447. },
  4448. viewportColumnCalculatorOverride: function viewportColumnCalculatorOverride(calc) {
  4449. calc.endColumn += 10;
  4450. }
  4451. });
  4452. wt.draw();
  4453. var oldCount = count;
  4454. wt.scrollHorizontal(10);
  4455. wt.draw(true);
  4456. expect(count).not.toBeGreaterThan(oldCount);
  4457. wt.scrollHorizontal(11);
  4458. wt.draw(true);
  4459. expect(count).toBeGreaterThan(oldCount);
  4460. });
  4461. describe('cell header border', function () {
  4462. it('should be correct visible in fixedColumns and without row header', function () {
  4463. createDataArray(50, 50);
  4464. $wrapper.width(500).height(400);
  4465. var count = 0,
  4466. wt = new Walkontable.Core({
  4467. table: $table[0],
  4468. data: getData,
  4469. totalRows: getTotalRows,
  4470. totalColumns: getTotalColumns,
  4471. columnWidth: 70,
  4472. fixedColumnsLeft: 2,
  4473. columnHeaders: [function (col, TH) {}]
  4474. });
  4475. wt.draw();
  4476. expect($('.ht_clone_top_left_corner thead tr th').eq(0).css('border-left-width')).toBe('1px');
  4477. expect($('.ht_clone_top_left_corner thead tr th').eq(0).css('border-right-width')).toBe('1px');
  4478. expect($('.ht_clone_top_left_corner thead tr th').eq(1).css('border-left-width')).toBe('0px');
  4479. expect($('.ht_clone_top_left_corner thead tr th').eq(1).css('border-right-width')).toBe('1px');
  4480. });
  4481. });
  4482. describe('isLastRowFullyVisible', function () {
  4483. it('should be false because it is only partially visible', function () {
  4484. createDataArray(8, 4);
  4485. $wrapper.width(185).height(175);
  4486. var wt = new Walkontable.Core({
  4487. table: $table[0],
  4488. data: getData,
  4489. totalRows: getTotalRows,
  4490. totalColumns: getTotalColumns
  4491. });
  4492. wt.draw();
  4493. expect(wt.wtTable.isLastRowFullyVisible()).toEqual(false);
  4494. });
  4495. it('should be true because it is fully visible', function () {
  4496. createDataArray(8, 4);
  4497. $wrapper.width(185).height(185);
  4498. var wt = new Walkontable.Core({
  4499. table: $table[0],
  4500. data: getData,
  4501. totalRows: getTotalRows,
  4502. totalColumns: getTotalColumns
  4503. });
  4504. wt.draw();
  4505. wt.scrollVertical(7);
  4506. wt.draw();
  4507. expect(wt.wtTable.isLastRowFullyVisible()).toEqual(true);
  4508. });
  4509. });
  4510. xdescribe('isLastColumnFullyVisible', function () {
  4511. it('should be false because it is only partially visible', function () {
  4512. createDataArray(18, 4);
  4513. $wrapper.width(209).height(185);
  4514. var wt = new Walkontable.Core({
  4515. table: $table[0],
  4516. data: getData,
  4517. totalRows: getTotalRows,
  4518. totalColumns: getTotalColumns
  4519. });
  4520. wt.draw();
  4521. expect(wt.wtTable.isLastColumnFullyVisible()).toEqual(false); // few pixels are obstacled by scrollbar
  4522. });
  4523. it('should be true because it is fully visible', function () {
  4524. createDataArray(18, 4);
  4525. $wrapper.width(180).height(185);
  4526. var wt = new Walkontable.Core({
  4527. table: $table[0],
  4528. data: getData,
  4529. totalRows: getTotalRows,
  4530. totalColumns: getTotalColumns
  4531. });
  4532. wt.draw();
  4533. wt.scrollHorizontal(1);
  4534. expect(wt.wtTable.isLastColumnFullyVisible()).toEqual(true);
  4535. });
  4536. });
  4537. });
  4538. /***/ })
  4539. /******/ ]);
  4540. //# sourceMappingURL=specs.entry.js.map