123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- 'use strict';
- describe('WalkontableEvent', function () {
- var $table,
- debug = false;
- beforeEach(function () {
- $table = $('<table></table>'); // create a table that is not attached to document
- $table.appendTo('body');
- createDataArray();
- });
- afterEach(function () {
- if (!debug) {
- $('.wtHolder').remove();
- }
- });
- it('should call `onCellMouseDown` callback', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- }
- });
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- $td.simulate('mousedown');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- it('should call `onCellMouseOver` callback', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onCellMouseOver: function onCellMouseOver(event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- }
- });
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- $td.simulate('mouseover');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- it('should call `onCellMouseOver` callback with correctly passed TD element when cell contains another table', function () {
- var fn = jasmine.createSpy();
- var wt = new Walkontable.Core({
- table: $table[0],
- data: [['<table style="width: 50px;"><tr><td class="test">TEST</td></tr></table>']],
- totalRows: 1,
- totalColumns: 1,
- onCellMouseOver: fn,
- cellRenderer: function cellRenderer(row, column, TD) {
- TD.innerHTML = wt.wtSettings.getSetting('data', row, column);
- }
- });
- wt.draw();
- var outerTD = $table.find('tbody td:not(td.test)');
- var innerTD = $table.find('tbody td.test');
- innerTD.simulate('mouseover');
- expect(fn.calls.argsFor(0)[2]).toBe(outerTD[0]);
- });
- it('should call `onCellMouseOut` callback', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onCellMouseOut: function onCellMouseOut(event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- }
- });
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- $td.simulate('mouseover');
- $td.simulate('mouseout');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- it('should call `onCellMouseOut` callback with correctly passed TD element when cell contains another table', function () {
- var fn = jasmine.createSpy();
- var wt = new Walkontable.Core({
- table: $table[0],
- data: [['<table style="width: 50px;"><tr><td class="test">TEST</td></tr></table>']],
- totalRows: 1,
- totalColumns: 1,
- onCellMouseOut: fn,
- cellRenderer: function cellRenderer(row, column, TD) {
- TD.innerHTML = wt.wtSettings.getSetting('data', row, column);
- }
- });
- wt.draw();
- var outerTD = $table.find('tbody td:not(td.test)');
- var innerTD = $table.find('tbody td.test');
- innerTD.simulate('mouseover');
- innerTD.simulate('mouseout');
- expect(fn.calls.argsFor(0)[2]).toBe(outerTD[0]);
- });
- it('should call `onCellDblClick` callback', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onCellDblClick: function onCellDblClick(event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- }
- });
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- $td.simulate('mousedown');
- $td.simulate('mouseup');
- $td.simulate('mousedown');
- $td.simulate('mouseup');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- it('should call `onCellDblClick` callback, even when it is set only after first click', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns
- });
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- $td.simulate('mousedown');
- $td.simulate('mouseup');
- $td.simulate('mousedown');
- wt.update('onCellDblClick', function (event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- });
- $td.simulate('mouseup');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- it('should call `onCellMouseDown` callback when clicked on TH', function () {
- var called = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- columnHeaders: [function (col, TH) {
- TH.innerHTML = col + 1;
- }],
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- called = true;
- }
- });
- wt.draw();
- var $th = $table.find('th:first');
- $th.simulate('mousedown');
- expect(called).toEqual(true);
- });
- it('should not call `onCellMouseDown` callback when clicked on the focusable element (column headers)', function () {
- var opt = ['Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'].map(function (opt) {
- return '<option value="' + opt + '">' + opt + '</option>';
- }).join('');
- var called = false;
- var wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- columnHeaders: [function (col, TH) {
- TH.innerHTML = '#' + col + '<select>' + opt + '</select>';
- }],
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- called = true;
- }
- });
- wt.draw();
- var select = $table.find('th:first select');
- select.focus();
- select.simulate('mousedown');
- expect(called).toBe(false);
- });
- it('should not call `onCellMouseDown` callback when clicked on the focusable element (cell renderer)', function () {
- var opt = ['Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'].map(function (opt) {
- return '<option value="' + opt + '">' + opt + '</option>';
- }).join('');
- var called = false;
- var wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- cellRenderer: function cellRenderer(row, column, TD) {
- TD.innerHTML = '<select>' + opt + '</select>';
- },
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- called = true;
- }
- });
- wt.draw();
- var select = $table.find('td:first select');
- select.focus();
- select.simulate('mousedown');
- expect(called).toBe(false);
- });
- it('should call `onCellMouseOver` callback when clicked on TH', function () {
- var called = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- columnHeaders: [function (col, TH) {
- TH.innerHTML = col + 1;
- }],
- onCellMouseOver: function onCellMouseOver(event, coords, TD) {
- called = coords;
- }
- });
- wt.draw();
- var $th = $table.find('th:first');
- $th.simulate('mouseover');
- expect(called.row).toEqual(-1);
- expect(called.col).toEqual(0);
- });
- it('should call `onCellDblClick` callback when clicked on TH', function () {
- var called = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- columnHeaders: [function (col, TH) {
- TH.innerHTML = col + 1;
- }],
- onCellDblClick: function onCellDblClick(event, coords, TD) {
- called = true;
- }
- });
- wt.draw();
- var $th = $table.find('th:first');
- $th.simulate('mousedown');
- $th.simulate('mouseup');
- $th.simulate('mousedown');
- $th.simulate('mouseup');
- expect(called).toEqual(true);
- });
- it('should not call `onCellDblClick` callback when right-clicked', function () {
- var called = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onCellDblClick: function onCellDblClick(event, coords, TD) {
- called = true;
- }
- });
- wt.draw();
- var $td = $table.find('tbody tr:first td:first');
- var options = {
- button: 2
- };
- $td.simulate('mousedown', options);
- $td.simulate('mouseup', options);
- $td.simulate('mousedown', options);
- $td.simulate('mouseup', options);
- expect(called).toEqual(false);
- });
- it('should not call `onCellDblClick` when first mouse up came from mouse drag', function () {
- var called = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onCellDblClick: function onCellDblClick(event, coords, TD) {
- called = true;
- }
- });
- wt.draw();
- var $td = $table.find('tbody tr:first td:first');
- var $td2 = $table.find('tbody tr:first td:eq(1)');
- $td2.simulate('mousedown');
- $td.simulate('mouseup');
- $td.simulate('mousedown');
- $td.simulate('mouseup');
- expect(called).toEqual(false);
- });
- it('border click should call `onCellMouseDown` callback', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- selections: [new Walkontable.Selection({
- className: 'current',
- border: {
- width: 1,
- color: 'red',
- style: 'solid'
- }
- })],
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- }
- });
- shimSelectionProperties(wt);
- wt.selections.current.add(new Walkontable.CellCoords(1, 1));
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- var $border = $table.parents('.wtHolder').find('.wtBorder:first');
- $border.simulate('mousedown');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- it('border click should call `onCellDblClick` callback', function () {
- var myCoords = null,
- myTD = null,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- selections: [new Walkontable.Selection({
- className: 'current',
- border: {
- width: 1,
- color: 'red',
- style: 'solid'
- }
- })],
- onCellDblClick: function onCellDblClick(event, coords, TD) {
- myCoords = coords;
- myTD = TD;
- }
- });
- shimSelectionProperties(wt);
- wt.selections.current.add(new Walkontable.CellCoords(1, 1));
- wt.draw();
- var $td = $table.find('tbody tr:eq(1) td:eq(1)');
- var $border = $table.parents('.wtHolder').find('.wtBorder:first');
- $border.simulate('mousedown');
- $border.simulate('mouseup');
- $border.simulate('mousedown');
- $border.simulate('mouseup');
- expect(myCoords).toEqual(new Walkontable.CellCoords(1, 1));
- expect(myTD).toEqual($td[0]);
- });
- // corner
- it('should call `onCellCornerMouseDown` callback', function () {
- var clicked = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- selections: [new Walkontable.Selection({
- className: 'current',
- border: {
- width: 1,
- color: 'red',
- style: 'solid'
- }
- })],
- onCellCornerMouseDown: function onCellCornerMouseDown(event) {
- clicked = true;
- }
- });
- shimSelectionProperties(wt);
- wt.selections.current.add(new Walkontable.CellCoords(10, 2));
- wt.draw();
- var $td = $table.parents('.wtHolder').find('.current.corner');
- $td.simulate('mousedown');
- expect(clicked).toEqual(true);
- });
- it('should call `onCellCornerDblClick` callback, even when it is set only after first click', function () {
- var clicked = false,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- selections: [new Walkontable.Selection({
- className: 'current',
- border: {
- width: 1,
- color: 'red',
- style: 'solid'
- }
- })]
- });
- shimSelectionProperties(wt);
- wt.selections.current.add(new Walkontable.CellCoords(10, 2));
- wt.draw();
- var $td = $table.parents('.wtHolder').find('.current.corner');
- $td.simulate('mousedown');
- $td.simulate('mouseup');
- $td.simulate('mousedown');
- wt.update('onCellCornerDblClick', function (event) {
- clicked = true;
- });
- $td.simulate('mouseup');
- expect(clicked).toEqual(true);
- });
- it('should call `onDraw` callback after render', function () {
- var count = 0,
- wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: getTotalRows,
- totalColumns: getTotalColumns,
- onDraw: function onDraw() {
- count++;
- }
- });
- wt.draw();
- expect(count).toEqual(1);
- });
- });
|