"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var test_1 = require("../../test");
var _1 = require(".");
var Grid_TEST_1 = require("../Grid/Grid.TEST");
describe('Cell', function () {
    describe('static', function () {
        it('converts row/column to key', function () {
            test_1.expect(_1.Cell.toKey({ row: 0, column: 0 })).to.eql('A1');
            test_1.expect(_1.Cell.toKey({ row: 4, column: 1 })).to.eql('B5');
        });
        it('isEmpty', function () {
            var test = function (input, expected) {
                test_1.expect(_1.Cell.isEmpty(input)).to.eql(expected);
            };
            test(undefined, true);
            test({ value: '' }, true);
            test({ value: undefined }, true);
            test({ value: undefined, props: {} }, true);
            test({ value: '', props: {} }, true);
            test({ value: ' ' }, false);
            test({ value: 0 }, false);
            test({ value: null }, false);
            test({ value: {} }, false);
            test({ value: { foo: 123 } }, false);
            test({ value: true }, false);
            test({ value: false }, false);
            test({ value: undefined, props: { value: 123 } }, false);
        });
        it('isEmptyValue', function () {
            var test = function (input, expected) {
                test_1.expect(_1.Cell.isEmptyValue(input)).to.eql(expected);
            };
            test(undefined, true);
            test('', true);
            test(' ', false);
            test(null, false);
            test(0, false);
            test(123, false);
            test({}, false);
            test([], false);
            test(true, false);
            test(false, false);
        });
    });
    describe('cell.value', function () {
        it('has default value (undefined)', function () {
            var grid = Grid_TEST_1.createGrid();
            var cell = grid.cell('A1');
            test_1.expect(cell.key).to.eql('A1');
            test_1.expect(cell.data.value).to.eql(undefined);
        });
    });
    describe('cell.props', function () {
        it('has default props (empty {})', function () {
            var grid = Grid_TEST_1.createGrid();
            var cell = grid.cell('A1');
            test_1.expect(cell.data.props).to.eql({});
        });
        it('Cell.props (default values)', function () {
            var grid = Grid_TEST_1.createGrid().changeCells({
                A2: {
                    value: 'A2',
                    props: {
                        style: { bold: true },
                        merge: { colspan: 3 },
                        view: { cell: { type: 'FOO', className: 'my-class' } },
                    },
                },
            });
            var A1 = grid.cell('A1');
            var A2 = grid.cell('A2');
            var res1 = _1.Cell.props(A1.data.props);
            var res2 = _1.Cell.props(A2.data.props);
            test_1.expect(A1.data.props).to.eql({});
            test_1.expect(res1.style).to.eql({});
            test_1.expect(res1.merge).to.eql({});
            test_1.expect(res1.view).to.eql({});
            test_1.expect(res2.style.bold).to.eql(true);
            test_1.expect(res2.merge.colspan).to.eql(3);
            test_1.expect(res2.view.cell && res2.view.cell.type).to.eql('FOO');
            test_1.expect(res2.view.cell && res2.view.cell.className).to.eql('my-class');
        });
    });
    describe('diff', function () {
        it('no difference', function () {
            var cell = { value: 1, props: { style: { bold: true } } };
            var res = _1.Cell.diff(cell, cell);
            test_1.expect(res.left).to.eql(cell);
            test_1.expect(res.right).to.eql(cell);
            test_1.expect(res.isDifferent).to.eql(false);
            test_1.expect(res.list.length).to.eql(0);
        });
        it('is different', function () {
            var left = { value: 1, props: { style: { bold: true } } };
            var right = { value: 2, props: { style: { bold: false } } };
            var res = _1.Cell.diff(left, right);
            test_1.expect(res.isDifferent).to.eql(true);
            test_1.expect(res.list.length).to.eql(2);
            test_1.expect((res.list[0].path || []).join('.')).to.eql('value');
            test_1.expect((res.list[1].path || []).join('.')).to.eql('props.style.bold');
        });
    });
    describe('rowspan/colspan', function () {
        it('default span values (1)', function () {
            var grid = Grid_TEST_1.createGrid();
            var cell = grid.cell('A1');
            test_1.expect(cell.rowspan).to.eql(1);
            test_1.expect(cell.colspan).to.eql(1);
        });
        it('updates col/row span values', function () {
            var values1 = {
                A1: { value: 'A1', props: { merge: { colspan: 2 } } },
                B2: { value: 'B2', props: { merge: { colspan: 3, rowspan: 5 } } },
            };
            var grid = Grid_TEST_1.createGrid().changeCells(values1);
            var cells = grid.data.cells;
            test_1.expect(cells.A1.props.merge.colspan).to.eql(2);
            test_1.expect(cells.B2.props.merge.colspan).to.eql(3);
            test_1.expect(cells.B2.props.merge.rowspan).to.eql(5);
        });
    });
});
