| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- describe('WalkontableBorder', function () {
- var $table,
- $container,
- $wrapper,
- debug = false;
- beforeEach(function () {
- $container = $('<div></div>');
- $wrapper = $('<div></div>');
- $container.width(100).height(200);
- $table = $('<table></table>');
- $container.append($wrapper);
- $wrapper.append($table);
- $container.appendTo('body');
- createDataArray();
- });
- afterEach(function () {
- if (!debug) {
- $('.wtHolder').remove();
- }
- $container.remove();
- });
- it('should add/remove border to selection when cell is clicked', function () {
- var wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: 5,
- totalColumns: 5,
- selections: [new Walkontable.Selection({
- border: {
- width: 1,
- color: 'red'
- }
- })],
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- wt.selections.current.clear();
- wt.selections.current.add(coords);
- wt.draw();
- }
- });
- shimSelectionProperties(wt);
- wt.draw();
- var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
- var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
- var $top = $(wt.selections.current.getBorder(wt).top);
- var $right = $(wt.selections.current.getBorder(wt).right);
- var $bottom = $(wt.selections.current.getBorder(wt).bottom);
- var $left = $(wt.selections.current.getBorder(wt).left);
- $td1.simulate('mousedown');
- expect($top.css('height')).toBe('1px');
- expect($top.position().top).toBe(23);
- expect($top.position().left).toBe(0);
- expect($right.css('width')).toBe('1px');
- expect($right.position().top).toBe(23);
- expect($right.position().left).toBe(49);
- expect($bottom.css('height')).toBe('1px');
- expect($bottom.position().top).toBe(46);
- expect($bottom.position().left).toBe(0);
- expect($left.css('width')).toBe('1px');
- expect($left.position().top).toBe(23);
- expect($left.position().left).toBe(0);
- $td2.simulate('mousedown');
- expect($top.css('height')).toBe('1px');
- expect($top.position().top).toBe(46);
- expect($top.position().left).toBe(49);
- expect($right.css('width')).toBe('1px');
- expect($right.position().top).toBe(46);
- expect($right.position().left).toBe(99);
- expect($bottom.css('height')).toBe('1px');
- expect($bottom.position().top).toBe(69);
- expect($bottom.position().left).toBe(49);
- expect($left.css('width')).toBe('1px');
- expect($left.position().top).toBe(46);
- expect($left.position().left).toBe(49);
- });
- it('should add/remove corner to selection when cell is clicked', function () {
- var wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: 5,
- totalColumns: 5,
- selections: [new Walkontable.Selection({
- border: {
- width: 2,
- color: 'green',
- cornerVisible: function cornerVisible() {
- return true;
- }
- }
- }), new Walkontable.Selection({})],
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- wt.selections.current.clear();
- wt.selections.current.add(coords);
- wt.draw();
- }
- });
- shimSelectionProperties(wt);
- wt.draw();
- var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
- var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
- var $corner = $(wt.selections.current.getBorder(wt).corner);
- $td1.simulate('mousedown');
- expect($corner.css('width')).toBe('5px');
- expect($corner.css('height')).toBe('5px');
- expect($corner.position().top).toBe(42);
- expect($corner.position().left).toBe(45);
- $td2.simulate('mousedown');
- expect($corner.css('width')).toBe('5px');
- expect($corner.css('height')).toBe('5px');
- expect($corner.position().top).toBe(65);
- expect($corner.position().left).toBe(95);
- });
- 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 () {
- $container.css({
- overflow: 'hidden',
- width: '200px'
- });
- var wt = new Walkontable.Core({
- table: $table[0],
- data: getData,
- totalRows: 5,
- totalColumns: 4,
- selections: [new Walkontable.Selection({
- border: {
- width: 2,
- color: 'green',
- cornerVisible: function cornerVisible() {
- return true;
- }
- }
- }), new Walkontable.Selection({})],
- onCellMouseDown: function onCellMouseDown(event, coords, TD) {
- wt.selections.current.clear();
- wt.selections.current.add(coords);
- wt.draw();
- }
- });
- shimSelectionProperties(wt);
- wt.draw();
- var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
- var $td2 = $table.find('tbody tr:eq(3) td:eq(3)');
- var $td3 = $table.find('tbody tr:eq(2) td:eq(1)');
- var $corner = $(wt.selections.current.getBorder(wt).corner);
- $td1.simulate('mousedown');
- expect($corner.css('width')).toBe('5px');
- expect($corner.css('height')).toBe('5px');
- expect($corner.position().top).toBe(42);
- expect($corner.position().left).toBe(45);
- expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
- $td2.simulate('mousedown');
- expect($corner.css('width')).toBe('5px');
- expect($corner.css('height')).toBe('5px');
- expect($corner.position().top).toBe(88);
- expect($corner.position().left).toBe(193);
- expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
- $td3.simulate('mousedown');
- expect($corner.css('width')).toBe('5px');
- expect($corner.css('height')).toBe('5px');
- expect($corner.position().top).toBe(65);
- expect($corner.position().left).toBe(95);
- expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
- });
- });
|