123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- describe('ContextMenu', function () {
- var id = 'testContainer';
- beforeEach(function () {
- this.$container = $('<div id="' + id + '"></div>').appendTo('body');
- });
- afterEach(function () {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- describe('alignment', function () {
- it('should align text left', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(0);
- button.simulate('mousedown'); // Text left
- expect(getCellMeta(0, 0).className).toEqual('htLeft');
- expect(getCell(0, 0).className).toContain('htLeft');
- done();
- }, 350);
- });
- it('should align text center', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(1);
- button.simulate('mousedown'); // Text center
- expect(getCellMeta(0, 0).className).toEqual('htCenter');
- expect(getCell(0, 0).className).toContain('htCenter');
- done();
- }, 350);
- });
- it('should align text right', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(2);
- button.simulate('mousedown'); // Text right
- expect(getCellMeta(0, 0).className).toEqual('htRight');
- expect(getCell(0, 0).className).toContain('htRight');
- done();
- }, 350);
- });
- it('should justify text', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(3);
- button.simulate('mousedown'); // Text justify
- deselectCell();
- expect(getCellMeta(0, 0).className).toEqual('htJustify');
- expect(getCell(0, 0).className).toContain('htJustify');
- done();
- }, 350); // menu opens after 300ms
- });
- it('should vertical align text top', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(4);
- button.simulate('mousedown'); // Text top
- deselectCell();
- expect(getCellMeta(0, 0).className).toEqual('htTop');
- expect(getCell(0, 0).className).toContain('htTop');
- done();
- }, 350); // menu opens after 300ms
- });
- it('should vertical align text middle', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(5);
- button.simulate('mousedown'); // Text middle
- deselectCell();
- expect(getCellMeta(0, 0).className).toEqual('htMiddle');
- expect(getCell(0, 0).className).toContain('htMiddle');
- done();
- }, 350); // menu opens after 300ms
- });
- it('should vertical align text bottom', function (done) {
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(4, 4),
- contextMenu: true,
- height: 100
- });
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(6);
- button.simulate('mousedown'); // Text bottom
- deselectCell();
- expect(getCellMeta(0, 0).className).toEqual('htBottom');
- expect(getCell(0, 0).className).toContain('htBottom');
- done();
- }, 350); // menu opens after 300ms
- });
- it('should trigger `afterSetCellMeta` callback after changing alignment by context menu', function (done) {
- var afterSetCellMetaCallback = jasmine.createSpy('afterSetCellMetaCallback');
- var hot = handsontable({
- data: Handsontable.helper.createSpreadsheetData(5, 5),
- rowHeaders: true,
- colHeaders: true,
- contextMenu: true,
- afterSetCellMeta: afterSetCellMetaCallback
- });
- selectCell(2, 3);
- contextMenu();
- var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
- item.simulate('mouseover');
- setTimeout(function () {
- var contextSubMenu = $('.htContextMenuSub_' + item.text());
- var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(2);
- button.simulate('mousedown'); // Text bottom
- deselectCell();
- expect(afterSetCellMetaCallback).toHaveBeenCalledWith(2, 3, 'className', 'htRight', undefined, undefined);
- done();
- }, 350); // menu opens after 300ms
- });
- });
- });
|