1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953 |
- describe('AutocompleteEditor', () => {
- var id = 'testContainer';
- var choices = ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white', 'purple', 'lime', 'olive', 'cyan'];
- var hot;
- beforeEach(function() {
- this.$container = $(`<div id="${id}" style="width: 300px; height: 200px; overflow: auto"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (hot) {
- hot = null;
- }
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- describe('open editor', () => {
- it('should display editor (after hitting ENTER)', () => {
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- expect(editor.is(':visible')).toBe(false);
- keyDownUp('enter');
- expect(editor.is(':visible')).toBe(true);
- });
- it('should display editor (after hitting F2)', () => {
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- expect(editor.is(':visible')).toBe(false);
- keyDownUp('f2');
- expect(editor.is(':visible')).toBe(true);
- });
- it('should display editor (after doubleclicking)', () => {
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- expect(editor.is(':visible')).toBe(false);
- mouseDoubleClick($(getCell(0, 0)));
- expect(editor.is(':visible')).toBe(true);
- });
- // see https://github.com/handsontable/handsontable/issues/3380
- it('should not throw error while selecting the next cell by hitting enter key', () => {
- var spy = jasmine.createSpyObj('error', ['test']);
- var prevError = window.onerror;
- window.onerror = function(messageOrEvent, source, lineno, colno, error) {
- spy.test();
- };
- handsontable({
- columns: [{
- editor: 'autocomplete',
- source: choices
- }]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- keyDownUp('enter');
- keyDownUp('enter');
- expect(spy.test.calls.count()).toBe(0);
- window.onerror = prevError;
- });
- });
- describe('choices', () => {
- it('should display given choices (array)', (done) => {
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- keyDownUp('enter');
- setTimeout(() => {
- expect(editor.find('tbody td:eq(0)').text()).toEqual(choices[0]);
- expect(editor.find('tbody td:eq(1)').text()).toEqual(choices[1]);
- expect(editor.find('tbody td:eq(2)').text()).toEqual(choices[2]);
- expect(editor.find('tbody td:eq(3)').text()).toEqual(choices[3]);
- expect(editor.find('tbody td:eq(4)').text()).toEqual(choices[4]);
- done();
- }, 100);
- });
- it('should call source function with context set as cellProperties', (done) => {
- var source = jasmine.createSpy('source');
- var context;
- source.and.callFake(function(query, process) {
- process(choices);
- context = this;
- });
- var hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source
- }
- ]
- });
- selectCell(0, 0);
- source.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(context.instance).toBe(hot);
- expect(context.row).toBe(0);
- expect(context.col).toBe(0);
- done();
- }, 200);
- });
- it('should display given choices (sync function)', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- syncSources.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(editor.find('tbody td:eq(0)').text()).toEqual(choices[0]);
- expect(editor.find('tbody td:eq(1)').text()).toEqual(choices[1]);
- expect(editor.find('tbody td:eq(2)').text()).toEqual(choices[2]);
- expect(editor.find('tbody td:eq(3)').text()).toEqual(choices[3]);
- expect(editor.find('tbody td:eq(4)').text()).toEqual(choices[4]);
- done();
- }, 200);
- });
- it('should display given choices (async function)', (done) => {
- var asyncSources = jasmine.createSpy('asyncSources');
- asyncSources.and.callFake((process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source(query, process) {
- setTimeout(() => {
- asyncSources(process);
- }, 0);
- }
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- keyDownUp('enter');
- setTimeout(() => {
- expect(asyncSources.calls.count()).toEqual(1);
- expect(editor.find('tbody td:eq(0)').text()).toEqual(choices[0]);
- expect(editor.find('tbody td:eq(1)').text()).toEqual(choices[1]);
- expect(editor.find('tbody td:eq(2)').text()).toEqual(choices[2]);
- expect(editor.find('tbody td:eq(3)').text()).toEqual(choices[3]);
- expect(editor.find('tbody td:eq(4)').text()).toEqual(choices[4]);
- done();
- }, 200);
- });
- it('should NOT update choices list, after cursor leaves and enters the list (#1330)', (done) => {
- spyOn(Handsontable.editors.AutocompleteEditor.prototype, 'updateChoicesList').and.callThrough();
- var updateChoicesList = Handsontable.editors.AutocompleteEditor.prototype.updateChoicesList;
- var hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = hot.getActiveEditor();
- keyDownUp('enter');
- setTimeout(() => {
- updateChoicesList.calls.reset();
- $(editor.htContainer).find('.htCore tr:eq(0) td:eq(0)').mouseenter();
- $(editor.htContainer).find('.htCore tr:eq(0) td:eq(0)').mouseleave();
- $(editor.htContainer).find('.htCore tr:eq(0) td:eq(0)').mouseenter();
- }, 200);
- setTimeout(() => {
- expect(updateChoicesList).not.toHaveBeenCalled();
- done();
- }, 300);
- });
- it('should update choices list exactly once after a key is pressed (#1330)', (done) => {
- spyOn(Handsontable.editors.AutocompleteEditor.prototype, 'updateChoicesList').and.callThrough();
- var updateChoicesList = Handsontable.editors.AutocompleteEditor.prototype.updateChoicesList;
- var hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = hot.getActiveEditor();
- updateChoicesList.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- updateChoicesList.calls.reset();
- editor.TEXTAREA.value = 'red';
- $(editor.TEXTAREA).simulate('keydown', {
- keyCode: 'd'.charCodeAt(0)
- });
- }, 200);
- setTimeout(() => {
- expect(updateChoicesList.calls.count()).toEqual(1);
- done();
- }, 100);
- });
- it('should not initialize the dropdown with unneeded scrollbars (scrollbar causing a scrollbar issue)', (done) => {
- spyOn(Handsontable.editors.AutocompleteEditor.prototype, 'updateChoicesList').and.callThrough();
- var updateChoicesList = Handsontable.editors.AutocompleteEditor.prototype.updateChoicesList;
- var hot = handsontable({
- data: [
- [
- 'blue'
- ],
- [],
- [],
- []
- ],
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editor = hot.getActiveEditor();
- updateChoicesList.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(editor.htContainer.scrollWidth).toEqual(editor.htContainer.clientWidth);
- done();
- }, 200);
- });
- it('autocomplete list should have textarea dimensions', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- colWidths: [200],
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.handsontableInputHolder');
- syncSources.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- // -2 for transparent borders
- expect(editor.find('.autocompleteEditor .htCore td').width()).toEqual(editor.find('.handsontableInput').width() - 2);
- expect(editor.find('.autocompleteEditor .htCore td').width()).toBeGreaterThan(187);
- done();
- }, 200);
- });
- it('autocomplete list should have the suggestion table dimensions, when trimDropdown option is set to false', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(['long text', 'even longer text', 'extremely long text in the suggestion list', 'short text', 'text', 'another', 'yellow', 'black']);
- });
- var hot = handsontable({
- colWidths: [200],
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ],
- trimDropdown: false,
- });
- selectCell(0, 0);
- var editor = $('.handsontableInputHolder');
- syncSources.calls.reset();
- keyDownUp('enter');
- setTimeout(() => {
- expect(editor.find('.autocompleteEditor .htCore td').eq(0).width()).toBeGreaterThan(editor.find('.handsontableInput').width());
- done();
- }, 200);
- });
- it('autocomplete textarea should have cell dimensions (after render)', (done) => {
- var data = [
- ['a', 'b'],
- ['c', 'd']
- ];
- hot = handsontable({
- data,
- minRows: 4,
- minCols: 4,
- minSpareRows: 4,
- minSpareCols: 4,
- cells() {
- return {
- type: Handsontable.AutocompleteCell
- };
- }
- });
- selectCell(1, 1);
- keyDownUp('enter');
- data[1][1] = 'dddddddddddddddddddd';
- render();
- setTimeout(() => {
- var $td = spec().$container.find('.htCore tbody tr:eq(1) td:eq(1)');
- expect(autocompleteEditor().width()).toEqual($td.width());
- done();
- }, 10);
- });
- it('should invoke beginEditing only once after dobleclicking on a cell (#1011)', () => {
- var hot = handsontable({
- columns: [
- {},
- {},
- {
- type: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 2);
- spyOn(hot.getActiveEditor(), 'beginEditing');
- expect(hot.getActiveEditor().beginEditing.calls.count()).toBe(0);
- mouseDoubleClick(getCell(0, 2));
- expect(hot.getActiveEditor().beginEditing.calls.count()).toBe(1);
- mouseDoubleClick(getCell(1, 2));
- expect(hot.getActiveEditor().beginEditing.calls.count()).toBe(2);
- mouseDoubleClick(getCell(2, 2));
- expect(hot.getActiveEditor().beginEditing.calls.count()).toBe(3);
- });
- it('should not display all the choices from a long source list and not leave any unused space in the dropdown (YouTrack: #HOT-32)', (done) => {
- var hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: [
- 'Acura', 'Audi', 'BMW', 'Buick', 'Cadillac', 'Chevrolet', 'Chrysler', 'Citroen', 'Dodge', 'Eagle', 'Ferrari',
- 'Ford', 'General Motors', 'GMC', 'Honda', 'Hummer', 'Hyundai', 'Infiniti', 'Isuzu', 'Jaguar', 'Jeep', 'Kia',
- 'Lamborghini', 'Land Rover', 'Lexus', 'Lincoln', 'Lotus', 'Mazda', 'Mercedes-Benz', 'Mercury', 'Mitsubishi',
- 'Nissan', 'Oldsmobile', 'Peugeot', 'Pontiac', 'Porsche', 'Regal', 'Renault', 'Saab', 'Saturn', 'Seat', 'Skoda',
- 'Subaru', 'Suzuki', 'Toyota', 'Volkswagen', 'Volvo']
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- var $autocomplete = autocomplete();
- var $autocompleteHolder = $autocomplete.find('.ht_master .wtHolder').first();
- setTimeout(() => {
- expect($autocomplete.find('td').first().text()).toEqual('Acura');
- $autocompleteHolder.scrollTop($autocompleteHolder[0].scrollHeight);
- }, 100);
- setTimeout(() => {
- expect($autocomplete.find('td').last().text()).toEqual('Volvo');
- done();
- }, 200);
- });
- it('should display the choices, regardless if they\'re declared as string or numeric', (done) => {
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: ['1', '2', 3, '4', 5, 6]
- }
- ]
- });
- selectCell(0, 0);
- var editor = $('.autocompleteEditor');
- keyDownUp('enter');
- setTimeout(() => {
- expect(editor.find('tbody td:eq(0)').text()).toEqual('1');
- expect(editor.find('tbody td:eq(1)').text()).toEqual('2');
- expect(editor.find('tbody td:eq(2)').text()).toEqual('3');
- expect(editor.find('tbody td:eq(3)').text()).toEqual('4');
- expect(editor.find('tbody td:eq(4)').text()).toEqual('5');
- expect(editor.find('tbody td:eq(5)').text()).toEqual('6');
- done();
- }, 100);
- });
- it('should display the choices, regardless if they\'re declared as string or numeric, when data is present', (done) => {
- handsontable({
- data: Handsontable.helper.createSpreadsheetData(10, 1),
- columns: [
- {
- editor: 'autocomplete',
- source: ['1', '2', 3, '4', 5, 6]
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('backspace');
- var editor = $('.autocompleteEditor');
- keyDownUp('enter');
- setTimeout(() => {
- expect(editor.find('tbody td:eq(0)').text()).toEqual('1');
- expect(editor.find('tbody td:eq(1)').text()).toEqual('2');
- expect(editor.find('tbody td:eq(2)').text()).toEqual('3');
- expect(editor.find('tbody td:eq(3)').text()).toEqual('4');
- expect(editor.find('tbody td:eq(4)').text()).toEqual('5');
- expect(editor.find('tbody td:eq(5)').text()).toEqual('6');
- done();
- }, 100);
- });
- it('should display the dropdown above the editor, when there is not enough space below the cell AND there is more space above the cell', (done) => {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(30, 30),
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}
- ],
- width: 400,
- height: 400
- });
- setDataAtCell(29, 0, '');
- selectCell(29, 0);
- mouseDoubleClick($(getCell(29, 0)));
- setTimeout(() => {
- var autocompleteEditor = $('.autocompleteEditor');
- expect(autocompleteEditor.css('position')).toEqual('absolute');
- expect(autocompleteEditor.css('top')).toEqual(`${(-1) * autocompleteEditor.height()}px`);
- done();
- }, 200);
- });
- it('should flip the dropdown upwards when there is no more room left below the cell after filtering the choice list', (done) => {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(30, 30),
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}
- ],
- width: 400,
- height: 400
- });
- setDataAtCell(26, 0, 'b');
- selectCell(26, 0);
- hot.view.wt.wtTable.holder.scrollTop = 999;
- mouseDoubleClick($(getCell(26, 0)));
- var autocompleteEditor = $('.autocompleteEditor');
- setTimeout(() => {
- expect(autocompleteEditor.css('position')).toEqual('relative');
- autocompleteEditor.siblings('textarea').first().val('');
- keyDownUp('backspace');
- }, 20);
- setTimeout(() => {
- expect(autocompleteEditor.css('position')).toEqual('absolute');
- expect(autocompleteEditor.css('top')).toEqual(`${(-1) * autocompleteEditor.height()}px`);
- done();
- }, 100);
- });
- });
- describe('closing editor', () => {
- it('should destroy editor when value change with mouse click on suggestion', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().find('tbody td:eq(3)').simulate('mousedown');
- expect(getDataAtCell(0, 0)).toEqual('green');
- done();
- }, 200);
- });
- it('should not change value type from `numeric` to `string` after mouse click suggestion - ' +
- 'test no. 1 #4143', (done) => {
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: [1, 2, 3, 4, 5, 11, 14]
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().find('tbody td:eq(0)').simulate('mousedown');
- expect(typeof getDataAtCell(0, 0)).toEqual('number');
- done();
- }, 200);
- });
- it('should not change value type from `numeric` to `string` after mouse click on suggestion - ' +
- 'test no. 2 #4143', (done) => {
- const syncSources = jasmine.createSpy('syncSources');
- const source = [1, 2, 3, 4, 5, 11, 14];
- syncSources.and.callFake((query, process) => {
- process(source);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().find('tbody td:eq(0)').simulate('mousedown');
- expect(typeof getDataAtCell(0, 0)).toEqual('number');
- done();
- }, 200);
- });
- it('should call `afterChange` hook with proper value types - test no. 1 #4143', (done) => {
- let changesInside;
- let sourceInside;
- const afterChange = (changes, source) => {
- if (source !== 'loadData') {
- changesInside = changes;
- sourceInside = source;
- }
- };
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: [1, 2, 3, 4, 5, 11, 14]
- }
- ],
- afterChange
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().find('tbody td:eq(1)').simulate('mousedown');
- expect(changesInside[0]).toEqual([0, 0, null, 2]);
- done();
- }, 200);
- });
- it('should call `afterChange` hook with proper value types - test no. 2 #4143', (done) => {
- let changesInside;
- let sourceInside;
- const afterChange = (changes, source) => {
- if (source !== 'loadData') {
- changesInside = changes;
- sourceInside = source;
- }
- };
- const syncSources = jasmine.createSpy('syncSources');
- const source = [1, 2, 3, 4, 5, 11, 14];
- syncSources.and.callFake((query, process) => {
- process(source);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ],
- afterChange
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().find('tbody td:eq(1)').simulate('mousedown');
- expect(changesInside[0]).toEqual([0, 0, null, 2]);
- done();
- }, 200);
- });
- it('should not change value type from `numeric` to `string` when written down value from set of suggestions #4143', (done) => {
- const syncSources = jasmine.createSpy('syncSources');
- const source = [1, 2, 3, 4, 5, 11, 14];
- syncSources.and.callFake((query, process) => {
- process(source);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- keyDownUp('backspace');
- document.activeElement.value = '1';
- $(document.activeElement).simulate('keyup');
- setTimeout(() => {
- keyDownUp('enter');
- expect(getDataAtCell(0, 0)).toEqual(1);
- done();
- }, 200);
- });
- it('should destroy editor when value change with Enter on suggestion', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- keyDownUp('enter');
- expect(getDataAtCell(0, 0)).toEqual('green');
- done();
- }, 200);
- });
- it('should destroy editor when pressed Enter then Esc', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- expect(autocompleteEditor().is(':visible')).toBe(true);
- keyDownUp('esc');
- expect(autocompleteEditor().is(':visible')).toBe(false);
- done();
- }, 200);
- });
- it('should destroy editor when mouse double clicked then Esc', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- mouseDoubleClick(getCell(0, 0));
- setTimeout(() => {
- expect(autocompleteEditor().is(':visible')).toBe(true);
- keyDownUp('esc');
- expect(autocompleteEditor().is(':visible')).toBe(false);
- done();
- }, 200);
- });
- it('cancel editing (Esc) should restore the previous value', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- setDataAtCell(0, 0, 'black');
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().siblings('.handsontableInput').val('ye');
- keyDownUp(69); // e
- keyDownUp('esc');
- expect(getDataAtCell(0, 0)).toEqual('black');
- done();
- }, 200);
- });
- it('should destroy editor when clicked outside the table', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- mouseDoubleClick(getCell(0, 0));
- setTimeout(() => {
- expect(autocompleteEditor().is(':visible')).toBe(true);
- $('body').simulate('mousedown');
- expect(autocompleteEditor().is(':visible')).toBe(false);
- done();
- }, 200);
- });
- it('should show fillHandle element again after close editor', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.plan = function(query, process) {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- };
- var hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // Trigger quick edit mode
- keyDownUp('enter');
- setTimeout(() => {
- expect($('#testContainer.handsontable > .handsontable .wtBorder.current.corner:visible').length).toEqual(1);
- done();
- }, 200);
- });
- });
- describe('non strict mode', () => {
- it('should allow any value in non strict mode (close editor with ENTER)', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- var editor = $('.handsontableInput');
- editor.val('foo');
- keyDownUp('enter');
- expect(getDataAtCell(0, 0)).toEqual('foo');
- done();
- }, 200);
- });
- it('should allow any value in non strict mode (close editor by clicking on table)', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- var editor = $('.handsontableInput');
- editor.val('foo');
- spec().$container.find('tbody tr:eq(1) td:eq(0)').simulate('mousedown');
- expect(getDataAtCell(0, 0)).toEqual('foo');
- done();
- }, 200);
- });
- it('should save the value from textarea after hitting ENTER', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['blue'],
- ['black']
- ]);
- var selected = innerHot.getSelected();
- expect(selected).toBeUndefined();
- keyDownUp('enter');
- expect(getDataAtCell(0, 0)).toEqual('b');
- done();
- }, 400);
- });
- });
- describe('strict mode', () => {
- it('strict mode should NOT use value if it DOES NOT match the list (sync reponse is empty)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var onAfterChange = jasmine.createSpy('onAfterChange');
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process([]); // hardcoded empty result
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- allowInvalid: false,
- strict: true
- },
- {}
- ],
- afterValidate: onAfterValidate,
- afterChange: onAfterChange
- });
- setDataAtCell(0, 0, 'unexistent');
- setTimeout(() => {
- expect(getData()).toEqual([
- ['one', 'two'],
- ['three', 'four']
- ]);
- expect(syncSources.calls.count()).toEqual(1);
- expect(onAfterValidate.calls.count()).toEqual(1);
- expect(onAfterChange.calls.count()).toEqual(1); // 1 for loadData (it is not called after failed edit)
- done();
- }, 200);
- });
- it('strict mode should use value if it DOES match the list (sync reponse is not empty)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var onAfterChange = jasmine.createSpy('onAfterChange');
- var syncSources = jasmine.createSpy('asyncSources');
- syncSources.and.callFake((query, process) => {
- process(choices); // hardcoded empty result
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- allowInvalid: false,
- strict: true
- },
- {}
- ],
- afterValidate: onAfterValidate,
- afterChange: onAfterChange
- });
- setDataAtCell(0, 0, 'yellow');
- setTimeout(() => {
- expect(getData()).toEqual([
- ['yellow', 'two'],
- ['three', 'four']
- ]);
- expect(syncSources.calls.count()).toEqual(1);
- expect(onAfterValidate.calls.count()).toEqual(1);
- expect(onAfterChange.calls.count()).toEqual(2); // 1 for loadData and 1 for setDataAtCell
- done();
- }, 200);
- });
- it('strict mode should NOT use value if it DOES NOT match the list (async reponse is empty)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var onAfterChange = jasmine.createSpy('onAfterChange');
- var asyncSources = jasmine.createSpy('asyncSources');
- asyncSources.and.callFake((query, process) => {
- setTimeout(() => {
- process([]); // hardcoded empty result
- });
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: asyncSources,
- allowInvalid: false,
- strict: true
- },
- {}
- ],
- afterValidate: onAfterValidate,
- afterChange: onAfterChange
- });
- setDataAtCell(0, 0, 'unexistent');
- setTimeout(() => {
- expect(getData()).toEqual([
- ['one', 'two'],
- ['three', 'four']
- ]);
- expect(asyncSources.calls.count()).toEqual(1);
- expect(onAfterValidate.calls.count()).toEqual(1);
- expect(onAfterChange.calls.count()).toEqual(1); // 1 for loadData (it is not called after failed edit)
- done();
- }, 200);
- });
- it('strict mode should use value if it DOES match the list (async reponse is not empty)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var onAfterChange = jasmine.createSpy('onAfterChange');
- var asyncSources = jasmine.createSpy('asyncSources');
- asyncSources.and.callFake((query, process) => {
- setTimeout(() => {
- process(choices); // hardcoded empty result
- });
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: asyncSources,
- allowInvalid: false,
- strict: true
- },
- {}
- ],
- afterValidate: onAfterValidate,
- afterChange: onAfterChange
- });
- setDataAtCell(0, 0, 'yellow');
- setTimeout(() => {
- expect(getData()).toEqual([
- ['yellow', 'two'],
- ['three', 'four']
- ]);
- expect(asyncSources.calls.count()).toEqual(1);
- expect(onAfterValidate.calls.count()).toEqual(1);
- expect(onAfterChange.calls.count()).toEqual(2); // 1 for loadData and 1 for setDataAtCell
- done();
- }, 200);
- });
- it('strict mode mark value as invalid if it DOES NOT match the list (sync reponse is empty)', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var onAfterChange = jasmine.createSpy('onAfterChange');
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process([]); // hardcoded empty result
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- allowInvalid: true,
- strict: true
- },
- {}
- ],
- afterValidate: onAfterValidate,
- afterChange: onAfterChange
- });
- expect(getCellMeta(0, 0).valid).not.toBe(false);
- expect($(getCell(0, 0)).hasClass('htInvalid')).toBe(false);
- setDataAtCell(0, 0, 'unexistent');
- setTimeout(() => {
- expect(getData()).toEqual([
- ['unexistent', 'two'],
- ['three', 'four']
- ]);
- expect(getCellMeta(0, 0).valid).toBe(false);
- expect($(getCell(0, 0)).hasClass('htInvalid')).toBe(true);
- done();
- }, 200);
- });
- it('should select the best matching option after hitting ENTER', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- strict: true
- }
- ],
- afterValidate: onAfterValidate
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['blue'],
- ['black']
- ]);
- var selected = innerHot.getSelected();
- var selectedData = innerHot.getDataAtCell(selected[0], selected[1]);
- expect(selectedData).toEqual('blue');
- onAfterValidate.calls.reset();
- keyDownUp('enter');
- }, 400);
- setTimeout(() => {
- expect(getDataAtCell(0, 0)).toEqual('blue');
- done();
- }, 600);
- });
- it('should select the best matching option after hitting TAB', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- strict: true
- }
- ],
- afterValidate: onAfterValidate
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['blue'],
- ['black']
- ]);
- var selected = innerHot.getSelected();
- var selectedData = innerHot.getDataAtCell(selected[0], selected[1]);
- expect(selectedData).toEqual('blue');
- onAfterValidate.calls.reset();
- keyDownUp('tab');
- }, 400);
- setTimeout(() => {
- expect(getDataAtCell(0, 0)).toEqual('blue');
- done();
- }, 600);
- });
- it('should mark list item corresponding to current cell value as selected', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(['red', 'dark-yellow', 'yellow', 'light-yellow', 'black']);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- strict: true
- }
- ],
- data: [
- ['yellow'],
- ['red'],
- ['blue']
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- expect(autocomplete().find('.current').text()).toEqual(getDataAtCell(0, 0));
- done();
- }, 200);
- });
- });
- describe('filtering', () => {
- it('typing in textarea should filter the lookup list', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('e');
- keyDownUp(69); // e
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['red'],
- ['yellow'],
- ['green'],
- ['blue'],
- ['lime'],
- ['white'],
- ['olive'],
- ['orange'],
- ['purple']
- ]);
- syncSources.calls.reset();
- editorInput.val('ed');
- keyDownUp(68); // d
- }, 400);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['red']
- ]);
- done();
- }, 600);
- });
- it('default filtering should be case insensitive', (done) => {
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- editorInput.val('e');
- keyDownUp(69); // e
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['red'],
- ['yellow'],
- ['green'],
- ['blue'],
- ['lime'],
- ['white'],
- ['olive'],
- ['orange'],
- ['purple']
- ]);
- editorInput.val('e');
- keyDownUp(69); // E (same as 'e')
- }, 50);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['red'],
- ['yellow'],
- ['green'],
- ['blue'],
- ['lime'],
- ['white'],
- ['olive'],
- ['orange'],
- ['purple']
- ]);
- done();
- }, 100);
- });
- it('default filtering should be case sensitive when filteringCaseSensitive is false', (done) => {
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices,
- filteringCaseSensitive: true
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- editorInput.val('e');
- keyDownUp(69); // e
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['red'],
- ['yellow'],
- ['green'],
- ['blue'],
- ['lime'],
- ['white'],
- ['olive'],
- ['orange'],
- ['purple']
- ]);
- editorInput.val('E');
- keyDownUp(69); // E (same as 'e')
- }, 50);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([]);
- expect(innerHot.getSourceData()).toEqual([]);
- done();
- }, 200);
- });
- it('typing in textarea should NOT filter the lookup list when filtering is disabled', (done) => {
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices,
- filter: false
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- editorInput.val('e');
- keyDownUp('e'.charCodeAt(0)); // e
- }, 20);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual(Handsontable.helper.pivot([choices]));
- editorInput.val('ed');
- keyDownUp('d'.charCodeAt(0)); // d
- }, 40);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual(Handsontable.helper.pivot([choices]));
- done();
- }, 60);
- });
- it('typing in textarea should highlight the matching phrase', (done) => {
- var choices = ['Male', 'Female'];
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.search(new RegExp(query, 'i')) != -1));
- });
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- filter: false
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('Male');
- keyDownUp(69); // e
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- var autocompleteList = $(innerHot.rootElement);
- expect(autocompleteList.find('td:eq(0)').html()).toMatch(/<(strong|STRONG)>Male<\/(strong|STRONG)>/); // IE8 makes the tag names UPPERCASE
- expect(autocompleteList.find('td:eq(1)').html()).toMatch(/Fe<(strong|STRONG)>male<\/(strong|STRONG)>/);
- done();
- }, 400);
- });
- it('text in textarea should not be interpreted as regexp', (done) => {
- spyOn(Handsontable.editors.AutocompleteEditor.prototype, 'queryChoices').and.callThrough();
- var queryChoices = Handsontable.editors.AutocompleteEditor.prototype.queryChoices;
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- queryChoices.calls.reset();
- editorInput.val('yellow|red');
- keyDownUp('d'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData().length).toEqual(0);
- done();
- }, 400);
- });
- it('text in textarea should not be interpreted as regexp when highlighting the matching phrase', (done) => {
- var choices = ['Male', 'Female'];
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.search(new RegExp(query, 'i')) != -1));
- });
- hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- filter: false
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('M|F');
- keyDownUp('F'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- var autocompleteList = $(innerHot.rootElement);
- expect(autocompleteList.find('td:eq(0)').html()).toEqual('Male');
- expect(autocompleteList.find('td:eq(1)').html()).toEqual('Female');
- done();
- }, 400);
- });
- it('should allow any value if filter === false and allowInvalid === true', (done) => {
- spyOn(Handsontable.editors.AutocompleteEditor.prototype, 'queryChoices').and.callThrough();
- var queryChoices = Handsontable.editors.AutocompleteEditor.prototype.queryChoices;
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices,
- filter: false,
- strict: true,
- allowInvalid: true
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- queryChoices.calls.reset();
- editorInput.val('foobar');
- keyDownUp(82); // r
- }, 200);
- setTimeout(() => {
- keyDownUp(Handsontable.helper.KEY_CODES.ENTER);
- expect(getDataAtCell(0, 0)).toEqual('foobar');
- done();
- }, 400);
- });
- it('typing in textarea should highlight best choice, if strict === true', (done) => {
- var choices = ['Male', 'Female'];
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.search(new RegExp(query, 'i')) != -1));
- });
- var hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- filter: false,
- strict: true
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- syncSources.calls.reset();
- editorInput.val('e');
- keyDownUp(69); // e
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getSelected()).toEqual([1, 0, 1, 0]);
- done();
- }, 400);
- });
- });
- it('should restore the old value when hovered over a autocomplete menu item and then clicked outside of the table', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ]
- });
- selectCell(0, 0);
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- autocomplete().find('tbody td:eq(1)').simulate('mouseenter');
- autocomplete().find('tbody td:eq(1)').simulate('mouseleave');
- spec().$container.simulate('mousedown');
- expect(getDataAtCell(0, 0)).toBeNull();
- done();
- }, 200);
- });
- it('should be able to use empty value ("")', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(['', 'BMW', 'Bentley']);
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources,
- filter: false
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- expect(getDataAtCell(0, 0)).toEqual('one');
- autocomplete().find('tbody td:eq(0)').simulate('mousedown');
- expect(getDataAtCell(0, 0)).toEqual('');
- done();
- }, 200);
- });
- describe('allow html mode', () => {
- it('should allow inject html items (async mode)', (done) => {
- hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source(query, cb) {
- cb(['<b>foo <span>zip</span></b>', '<i>bar</i>', '<strong>baz</strong>']);
- },
- allowHtml: true,
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['<i>bar</i>'],
- ['<strong>baz</strong>'],
- ]);
- editorInput.val('bar');
- keyDownUp('a'.charCodeAt(0));
- keyDownUp('r'.charCodeAt(0));
- }, 400);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['<i>bar</i>']
- ]);
- keyDownUp('arrow_down');
- keyDownUp('enter');
- }, 600);
- setTimeout(() => {
- expect(getCell(0, 0).querySelector('i').textContent).toBe('bar');
- done();
- }, 700);
- });
- it('should allow inject html items (sync mode)', (done) => {
- hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: ['<b>foo <span>zip</span></b>', '<i>bar</i>', '<strong>baz</strong>'],
- allowHtml: true,
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['<i>bar</i>'],
- ['<strong>baz</strong>'],
- ]);
- editorInput.val('bar');
- keyDownUp('a'.charCodeAt(0));
- keyDownUp('r'.charCodeAt(0));
- }, 400);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['<i>bar</i>']
- ]);
- keyDownUp('arrow_down');
- keyDownUp('enter');
- }, 600);
- setTimeout(() => {
- expect(getCell(0, 0).querySelector('i').textContent).toBe('bar');
- done();
- }, 700);
- });
- });
- describe('disallow html mode', () => {
- it('should be disabled by default', () => {
- hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source(query, cb) {
- cb(['<b>foo <span>zip</span></b>', '<i>bar</i>', '<strong>baz</strong>']);
- },
- allowHtml: false,
- }
- ]
- });
- expect(hot.getCellMeta(0, 0).allowHtml).toBeFalsy();
- });
- it('should strip html from strings provided in source (async mode)', (done) => {
- hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source(query, cb) {
- cb(['<b>foo <span>zip</span></b>', '<i>bar</i>', '<strong>baz</strong>']);
- },
- allowHtml: false,
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['bar'],
- ['baz'],
- ]);
- editorInput.val('bar');
- keyDownUp('a'.charCodeAt(0));
- keyDownUp('r'.charCodeAt(0));
- }, 400);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['bar']
- ]);
- keyDownUp('arrow_down');
- keyDownUp('enter');
- }, 600);
- setTimeout(() => {
- expect(getCell(0, 0).querySelector('i')).toBeNull();
- expect(getCell(0, 0).textContent).toMatch('bar');
- done();
- }, 700);
- });
- it('should strip html from strings provided in source (sync mode)', (done) => {
- hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: ['<b>foo <span>zip</span></b>', '<i>bar</i>', '<strong>baz</strong>'],
- allowHtml: false,
- }
- ]
- });
- selectCell(0, 0);
- var editorInput = $('.handsontableInput');
- expect(getDataAtCell(0, 0)).toBeNull();
- keyDownUp('enter');
- setTimeout(() => {
- editorInput.val('b');
- keyDownUp('b'.charCodeAt(0));
- }, 200);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['bar'],
- ['baz'],
- ]);
- editorInput.val('bar');
- keyDownUp('a'.charCodeAt(0));
- keyDownUp('r'.charCodeAt(0));
- }, 400);
- setTimeout(() => {
- var ac = hot.getActiveEditor();
- var innerHot = ac.htEditor;
- expect(innerHot.getData()).toEqual([
- ['bar']
- ]);
- keyDownUp('arrow_down');
- keyDownUp('enter');
- }, 600);
- setTimeout(() => {
- expect(getCell(0, 0).querySelector('i')).toBeNull();
- expect(getCell(0, 0).textContent).toMatch('bar');
- done();
- }, 700);
- });
- });
- describe('Autocomplete helper functions:', () => {
- describe('sortByRelevance', () => {
- it('should sort the provided array, so items more relevant to the provided value are listed first', () => {
- var choices = [
- 'Wayne', // 0
- 'Draven', // 1
- 'Banner', // 2
- 'Stark', // 3
- 'Parker', // 4
- 'Kent', // 5
- 'Gordon', // 6
- 'Kyle', // 7
- 'Simmons'// 8
- ];
- let value = 'a';
- var sorted = Handsontable.editors.AutocompleteEditor.sortByRelevance(value, choices);
- expect(sorted).toEqual([0, 2, 4, 3, 1]);
- value = 'o';
- sorted = Handsontable.editors.AutocompleteEditor.sortByRelevance(value, choices);
- expect(sorted).toEqual([6, 8]);
- value = 'er';
- sorted = Handsontable.editors.AutocompleteEditor.sortByRelevance(value, choices);
- expect(sorted).toEqual([2, 4]);
- });
- });
- });
- it('should not modify the suggestion lists\' order, when the sortByRelevance option is set to false', (done) => {
- var choices = [
- 'Wayne', 'Draven', 'Banner', 'Stark', 'Parker', 'Kent', 'Gordon', 'Kyle', 'Simmons'
- ];
- var hot = handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: choices,
- sortByRelevance: false
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- var $editorInput = $('.handsontableInput');
- $editorInput.val('a');
- keyDownUp('a'.charCodeAt(0));
- Handsontable.dom.setCaretPosition($editorInput[0], 1);
- setTimeout(() => {
- var dropdownList = $('.autocompleteEditor tbody').first();
- var listLength = dropdownList.find('tr').size();
- expect(listLength).toBe(9);
- for (var i = 1; i <= listLength; i++) {
- expect(dropdownList.find(`tr:nth-child(${i}) td`).text()).toEqual(choices[i - 1]);
- }
- done();
- }, 30);
- });
- it('should fire one afterChange event when value is changed', (done) => {
- var onAfterChange = jasmine.createSpy('onAfterChange');
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {
- editor: 'autocomplete',
- source: syncSources
- }
- ],
- afterChange: onAfterChange
- });
- selectCell(0, 0);
- keyDownUp('enter');
- setTimeout(() => {
- onAfterChange.calls.reset();
- autocomplete().find('tbody td:eq(1)').simulate('mousedown');
- expect(getDataAtCell(0, 0)).toEqual('red');
- expect(onAfterChange.calls.count()).toEqual(1);
- expect(onAfterChange).toHaveBeenCalledWith([[0, 0, null, 'red']], 'edit', undefined, undefined, undefined, undefined);
- done();
- }, 200);
- });
- it('should not affect other cell values after clicking on autocomplete cell (#1021)', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices);
- });
- handsontable({
- columns: [
- {},
- {},
- {
- editor: 'autocomplete',
- source: syncSources
- },
- {}
- ],
- data: [
- [null, null, 'yellow', null],
- [null, null, 'red', null],
- [null, null, 'blue', null]
- ]
- });
- expect($(getCell(0, 2)).text()).toMatch('yellow');
- mouseDoubleClick(getCell(0, 2));
- expect($(getCell(1, 2)).text()).toMatch('red');
- mouseDoubleClick(getCell(1, 2));
- expect($(getCell(2, 2)).text()).toMatch('blue');
- mouseDoubleClick(getCell(2, 2));
- setTimeout(() => {
- expect(getDataAtCol(2)).toEqual(['yellow', 'red', 'blue']);
- done();
- }, 200);
- });
- it('should handle editor if cell data is a function', (done) => {
- spyOn(Handsontable.editors.AutocompleteEditor.prototype, 'updateChoicesList').and.callThrough();
- var updateChoicesList = Handsontable.editors.AutocompleteEditor.prototype.updateChoicesList;
- var afterValidateCallback = jasmine.createSpy('afterValidateCallbak');
- var hot = handsontable({
- data: [
- new Model({
- id: 1,
- name: 'Ted Right',
- address: ''
- }),
- new Model({
- id: 2,
- name: 'Frank Honest',
- address: ''
- }),
- new Model({
- id: 3,
- name: 'Joan Well',
- address: ''
- })],
- dataSchema: Model,
- colHeaders: ['ID', 'Name', 'Address'],
- columns: [
- {
- data: createAccessorForProperty('id'),
- type: 'autocomplete',
- source: ['1', '2', '3'],
- filter: false,
- strict: true
- },
- {
- data: createAccessorForProperty('name')
- },
- {
- data: createAccessorForProperty('address')
- }
- ],
- minSpareRows: 1,
- afterValidate: afterValidateCallback
- });
- selectCell(0, 0);
- expect(hot.getActiveEditor().isOpened()).toBe(false);
- keyDownUp('enter');
- setTimeout(() => {
- expect(hot.getActiveEditor().isOpened()).toBe(true);
- afterValidateCallback.calls.reset();
- $(hot.getActiveEditor().htContainer).find('tr:eq(1) td:eq(0)').simulate('mousedown');
- }, 200);
- setTimeout(() => {
- expect(getDataAtCell(0, 0)).toEqual('2');
- done();
- }, 400);
- });
- it('should not call the `source` has been selected', () => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process([]); // hardcoded empty result
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- allowInvalid: false,
- strict: true
- },
- {}
- ],
- cells(row, col) {
- var cellProperties = {};
- if (row === 0 && col === 0) {
- cellProperties.readOnly = true;
- }
- return cellProperties;
- }
- });
- expect(getCellMeta(0, 0).readOnly).toBe(true);
- expect(syncSources).not.toHaveBeenCalled();
- selectCell(0, 0);
- expect(syncSources).not.toHaveBeenCalled();
- expect(getCellMeta(1, 0).readOnly).toBeFalsy();
- selectCell(1, 0);
- expect(syncSources).not.toHaveBeenCalled();
- });
- it('should not call the `source` method if cell is read only and the arrow has been clicked', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process([]); // hardcoded empty result
- });
- handsontable({
- data: [
- ['one', 'two'],
- ['three', 'four']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- allowInvalid: false,
- strict: true
- },
- {}
- ],
- cells(row, col) {
- var cellProperties = {};
- if (row === 0 && col === 0) {
- cellProperties.readOnly = true;
- }
- return cellProperties;
- }
- });
- expect(getCellMeta(0, 0).readOnly).toBe(true);
- expect(syncSources).not.toHaveBeenCalled();
- selectCell(0, 0);
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
- setTimeout(() => {
- expect(syncSources).not.toHaveBeenCalled();
- syncSources.calls.reset();
- expect(getCellMeta(1, 0).readOnly).toBeFalsy();
- selectCell(1, 0);
- $(getCell(1, 0)).find('.htAutocompleteArrow').simulate('mousedown');
- }, 100);
- setTimeout(() => {
- expect(syncSources).toHaveBeenCalled();
- expect(syncSources.calls.count()).toEqual(1);
- done();
- }, 200);
- });
- it('should add a scrollbar to the autocomplete dropdown, only if number of displayed choices exceeds 10', function(done) {
- var hot = handsontable({
- data: [
- ['', 'two', 'three'],
- ['four', 'five', 'six']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: choices,
- allowInvalid: false,
- strict: false
- },
- {},
- {}
- ]
- });
- this.$container.css({
- height: 600
- });
- expect(choices.length).toBeGreaterThan(10);
- selectCell(0, 0);
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
- var dropdown = hot.getActiveEditor().htContainer;
- var dropdownHolder = hot.getActiveEditor().htEditor.view.wt.wtTable.holder;
- setTimeout(() => {
- expect(dropdownHolder.scrollHeight).toBeGreaterThan(dropdownHolder.clientHeight);
- keyDownUp('esc');
- hot.getSettings().columns[0].source = hot.getSettings().columns[0].source.slice(0).splice(3);
- hot.updateSettings({});
- selectCell(0, 0);
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
- }, 30);
- setTimeout(() => {
- expect(dropdownHolder.scrollHeight > dropdownHolder.clientHeight).toBe(false);
- done();
- }, 60);
- });
- it('should not close editor on scrolling', (done) => {
- var hot = handsontable({
- data: [
- ['', 'two', 'three'],
- ['four', 'five', 'six']
- ],
- columns: [
- {
- type: 'autocomplete',
- source: choices,
- allowInvalid: false,
- strict: false
- },
- {},
- {}
- ]
- });
- expect(choices.length).toBeGreaterThan(10);
- selectCell(0, 0);
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mouseup');
- var dropdown = hot.getActiveEditor().htContainer;
- hot.view.wt.wtOverlays.topOverlay.scrollTo(1);
- setTimeout(() => {
- expect($(dropdown).is(':visible')).toBe(true);
- selectCell(0, 0);
- }, 30);
- setTimeout(() => {
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
- $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mouseup');
- hot.view.wt.wtOverlays.topOverlay.scrollTo(3);
- }, 80);
- setTimeout(() => {
- expect($(dropdown).is(':visible')).toBe(true);
- done();
- }, 120);
- });
- it('should keep textarea caret position, after moving the selection to the suggestion list (pressing down arrow)', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- Handsontable.dom.setCaretPosition($editorInput[0], 1);
- setTimeout(() => {
- keyDownUp('arrow_down');
- expect(Handsontable.dom.getCaretPosition($editorInput[0])).toEqual(1);
- keyDownUp('arrow_down');
- expect(Handsontable.dom.getCaretPosition($editorInput[0])).toEqual(1);
- done();
- }, 200);
- });
- it('should keep textarea selection, after moving the selection to the suggestion list (pressing down arrow)', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- }
- ]
- });
- selectCell(0, 0);
- keyDownUp('enter');
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- Handsontable.dom.setCaretPosition($editorInput[0], 1, 2);
- setTimeout(() => {
- keyDownUp('arrow_down');
- expect(Handsontable.dom.getCaretPosition($editorInput[0])).toEqual(1);
- expect(Handsontable.dom.getSelectionEndPosition($editorInput[0])).toEqual(2);
- keyDownUp('arrow_down');
- expect(Handsontable.dom.getCaretPosition($editorInput[0])).toEqual(1);
- expect(Handsontable.dom.getSelectionEndPosition($editorInput[0])).toEqual(2);
- done();
- }, 200);
- });
- it('should jump to the sibling cell, after pressing up key in quick edit mode', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // trigger quick edit mode
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- setTimeout(() => {
- keyDownUp('arrow_up');
- expect(getSelected()).toEqual([0, 0, 0, 0]);
- done();
- }, 200);
- });
- it('should jump to the next cell, after pressing right key in quick edit mode', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.plan = function(query, process) {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- };
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // trigger quick edit mode
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- setTimeout(() => {
- keyDownUp('arrow_right');
- expect(getSelected()).toEqual([1, 1, 1, 1]);
- done();
- }, 200);
- });
- it('should jump to the next cell, after pressing left key in quick edit mode', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {},
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- }
- ]
- });
- selectCell(1, 1);
- keyDownUp('x'); // trigger quick edit mode
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- // put caret on the end of the text to ensure that editor will be closed after hit left arrow key
- Handsontable.dom.setCaretPosition($editorInput[0], 2, 2);
- setTimeout(() => {
- keyDownUp('arrow_left');
- expect(getSelected()).toEqual([1, 0, 1, 0]);
- done();
- }, 200);
- });
- it('should jump to the next cell, after pressing down key in quick edit mode', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // trigger quick edit mode
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- setTimeout(() => {
- keyDownUp('arrow_down');
- expect(getSelected()).toEqual([1, 0, 1, 0]);
- done();
- }, 200);
- });
- it('should jump to the next cell, after pressing down key in quick edit mode when no matching option list found', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // trigger quick edit mode
- var $editorInput = $('.handsontableInput');
- $editorInput.val('anananan');
- keyDownUp(65); // a
- keyDownUp(78); // n
- keyDownUp(65); // a
- keyDownUp(78); // n
- keyDownUp(65); // a
- keyDownUp(78); // n
- keyDownUp(65); // a
- keyDownUp(78); // n
- setTimeout(() => {
- keyDownUp('arrow_down');
- expect(getSelected()).toEqual([2, 0, 2, 0]);
- done();
- }, 200);
- });
- it('should not jump to the next cell, after pressing down key in quick edit mode when options list was opened', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // trigger quick edit mode
- var $editorInput = $('.handsontableInput');
- $editorInput.val('an');
- keyDownUp(65); // a
- keyDownUp(78); // n
- setTimeout(() => {
- keyDownUp('arrow_down');
- expect(getSelected()).toEqual([1, 0, 1, 0]);
- done();
- }, 200);
- });
- it('should select option in opened editor after pressing down key in quick edit mode', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- var hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // Trigger quick edit mode
- setTimeout(() => {
- keyDownUp('arrow_down');
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([0, 0, 0, 0]);
- keyDownUp('arrow_down');
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([1, 0, 1, 0]);
- keyDownUp('arrow_down');
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([2, 0, 2, 0]);
- done();
- }, 200);
- });
- it('should select option in opened editor after pressing up key in quick edit mode', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- var hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // Trigger quick edit mode
- setTimeout(() => {
- hot.getActiveEditor().htEditor.selectCell(2, 0);
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([2, 0, 2, 0]);
- keyDownUp('arrow_up');
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([1, 0, 1, 0]);
- keyDownUp('arrow_up');
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([0, 0, 0, 0]);
- keyDownUp('arrow_up');
- expect(hot.getActiveEditor().htEditor.getSelected()).toEqual([0, 0, 0, 0]);
- done();
- }, 200);
- });
- it('should not close editor in quick edit mode after pressing down key when last option is selected', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- var hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // Trigger quick edit mode
- setTimeout(() => {
- hot.getActiveEditor().htEditor.selectCell(7, 0);
- hot.listen();
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- keyDownUp('arrow_down');
- expect(hot.getActiveEditor().isOpened()).toBe(true);
- done();
- }, 200);
- });
- it('should close editor in quick edit mode after pressing up key when no option is selected', (done) => {
- var syncSources = jasmine.createSpy('syncSources');
- syncSources.and.callFake((query, process) => {
- process(choices.filter((choice) => choice.indexOf(query) != -1));
- });
- var hot = handsontable({
- columns: [
- {
- type: 'autocomplete',
- source: syncSources,
- strict: false
- },
- {}
- ]
- });
- selectCell(1, 0);
- keyDownUp('x'); // Trigger quick edit mode
- setTimeout(() => {
- hot.getActiveEditor().htEditor.selectCell(1, 0);
- hot.listen();
- keyDownUp('arrow_up');
- keyDownUp('arrow_up');
- keyDownUp('arrow_up');
- expect(getSelected()).toEqual([0, 0, 0, 0]);
- done();
- }, 200);
- });
- });
|