| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- describe('Core.setCellMeta', () => {
- const id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should set correct meta className for cell', () => {
- const className = 'htCenter htMiddle';
- handsontable({
- afterCellMetaReset() {
- this.setCellMeta(0, 0, 'className', className);
- }
- });
- let cellMeta = getCellMeta(0, 0);
- expect(cellMeta.className).not.toBeUndefined();
- expect(cellMeta.className).toEqual(className);
- });
- it('should set correct meta className for non existed cell', () => {
- const className = 'htCenter htMiddle';
- handsontable({
- data: Handsontable.helper.createSpreadsheetData(5, 5),
- afterCellMetaReset() {
- this.setCellMeta(100, 100, 'className', className);
- }
- });
- let cellMeta = getCellMeta(100, 100);
- expect(cellMeta.className).not.toBeUndefined();
- expect(cellMeta.className).toEqual(className);
- });
- it('should set correct meta classNames for cells using cell in configuration', function() {
- const classNames = [
- 'htCenter htTop',
- 'htRight htBottom'
- ];
- handsontable({
- cell: [
- {row: 0, col: 0, className: classNames[0] },
- {row: 1, col: 1, className: classNames[1] }
- ]
- });
- expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual(classNames[0]);
- expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual(classNames[1]);
- });
- it('should change cell meta data with updateSettings when the cell option is defined', function() {
- const classNames = [
- 'htCenter htTop',
- 'htRight htBottom'
- ];
- handsontable({
- cell: [
- {row: 0, col: 0, className: classNames[0] },
- {row: 1, col: 1, className: classNames[1] }
- ]
- });
- expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual(classNames[0]);
- expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual(classNames[1]);
- updateSettings({
- cell: []
- });
- expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual('');
- expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual('');
- updateSettings({
- cell: [
- {row: 0, col: 0, className: classNames[1] },
- {row: 1, col: 1, className: classNames[0] }
- ]
- });
- expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual(classNames[1]);
- expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual(classNames[0]);
- });
- it('should call afterSetCellMeta plugin hook', () => {
- const className = 'htCenter htMiddle';
- let res = {};
- handsontable({
- afterCellMetaReset() {
- this.setCellMeta(0, 1, 'className', className);
- },
- afterSetCellMeta(row, col, key, val) {
- res.row = row;
- res.col = col;
- res.key = key;
- res.val = val;
- }
- });
- expect(res.row).toEqual(0);
- expect(res.col).toEqual(1);
- expect(res.key).toEqual('className');
- expect(res.val).toEqual(className);
- });
- });
|