123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- describe('CheckboxRenderer', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}" style="width: 300px; height: 200px;"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should render values as checkboxes', () => {
- handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- expect($(getRenderedValue(0, 0)).is(':checkbox')).toBe(true);
- expect($(getRenderedValue(1, 0)).is(':checkbox')).toBe(true);
- expect($(getRenderedValue(2, 0)).is(':checkbox')).toBe(true);
- });
- it('should render check checkboxes for cell which value is true', () => {
- handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox' }
- ]
- });
- expect($(getRenderedContent(0, 0)).prop('checked')).toBe(true);
- expect($(getRenderedContent(1, 0)).prop('checked')).toBe(false);
- expect($(getRenderedContent(2, 0)).prop('checked')).toBe(true);
- });
- it('should use templates to check appropriate checkboxes', () => {
- handsontable({
- data: [['yes'], ['no'], ['yes']],
- columns: [
- {
- type: 'checkbox',
- checkedTemplate: 'yes',
- uncheckedTemplate: 'no'
- }
- ]
- });
- expect($(getRenderedContent(0, 0)).prop('checked')).toBe(true);
- expect($(getRenderedContent(1, 0)).prop('checked')).toBe(false);
- expect($(getRenderedContent(2, 0)).prop('checked')).toBe(true);
- });
- it('should select cell after checkbox click', function() {
- var hot = handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- hot.selectCell(0, 0);
- this.$container.find(':checkbox').eq(2).simulate('mousedown');
- expect(hot.getSelected()).toEqual([2, 0, 2, 0]);
- });
- it('should select cell after label click', function() {
- var hot = handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox', label: {position: 'before', value: 'Sure? '}}
- ]
- });
- hot.selectCell(0, 0);
- this.$container.find('td label').eq(2).simulate('mousedown');
- expect(hot.getSelected()).toEqual([2, 0, 2, 0]);
- });
- it('should reverse selection in checkboxes', function() {
- handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox' }
- ]
- });
- this.$container.find(':checkbox').eq(0).simulate('click');
- this.$container.find(':checkbox').eq(1).simulate('click');
- this.$container.find(':checkbox').eq(2).simulate('click');
- expect(getData()).toEqual([[false], [true], [false]]);
- });
- it('shouldn\'t uncheck checkboxes', function() {
- handsontable({
- data: [[true], [true], [true]],
- columns: [
- {type: 'checkbox', readOnly: true}
- ]
- });
- this.$container.find(':checkbox').trigger('click');
- expect(getData()).toEqual([[true], [true], [true]]);
- });
- it('should check single box after hitting space', function() {
- handsontable({
- data: [[true], [true], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [true], [true]]);
- selectCell(0, 0);
- // this.$container.find(':checkbox').eq(0).simulate('click');
- // this.$container.simulate('keydown',{
- // keyCode: 32
- // });
- keyDown('space');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[false], [true], [true]]);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, true, false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should not check single box after hitting space, if cell is readOnly', function() {
- handsontable({
- data: [[true], [true], [true]],
- columns: [
- {type: 'checkbox', readOnly: true}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [true], [true]]);
- selectCell(0, 0);
- keyDown('space');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [true], [true]]);
- expect(afterChangeCallback).not.toHaveBeenCalled();
- });
- it('should not check single box after hitting space, if last column is readOnly (#3562)', function() {
- handsontable({
- data: [[true, true], [false, false], [true, true]],
- columns: [
- {type: 'checkbox'},
- {type: 'checkbox', readOnly: true}
- ]
- });
- selectCell(0, 0);
- keyDown('space');
- selectCell(0, 1);
- keyDown('space');
- selectCell(1, 0);
- keyDown('space');
- selectCell(1, 1);
- keyDown('space');
- var checkboxes = this.$container.find(':checkbox');
- // column 0
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(checkboxes.eq(4).prop('checked')).toBe(true);
- // column 1
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(3).prop('checked')).toBe(false);
- expect(checkboxes.eq(5).prop('checked')).toBe(true);
- expect(getData()).toEqual([[false, true], [true, false], [true, true]]);
- });
- it('should change checkboxes values properly when data contains null or/and undefined', () => {
- handsontable({
- data: [[null], [undefined]],
- colHeaders: true,
- columns: [
- {
- type: 'checkbox'
- }
- ]
- });
- selectCell(0, 0, 1, 0);
- keyDown('space');
- expect(getDataAtCol(0)).toEqual([true, true]);
- selectCell(0, 0, 1, 0);
- keyDown('space');
- expect(getDataAtCol(0)).toEqual([false, false]);
- });
- it('should change checkboxes values for cells below the viewport (hot initialized by startRows) #4037', () => {
- handsontable({
- startRows: 200,
- colHeaders: true,
- columns: [
- {
- type: 'checkbox'
- }
- ]
- });
- selectCell(0, 0, 199, 0);
- keyDown('space');
- expect(getDataAtCell(199, 0)).toEqual(true);
- });
- it('should reverse checkboxes state after hitting space, when multiple cells are selected', function() {
- var hot = handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [false], [true]]);
- selectCell(0, 0, 2, 0);
- keyDown('space');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(false);
- expect(getData()).toEqual([[false], [true], [false]]);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, true, false], [1, 0, false, true], [2, 0, true, false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should reverse checkboxes state after hitting space, when multiple cells are selected and selStart > selEnd', function() {
- handsontable({
- data: [[true], [false], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [false], [true]]);
- selectCell(2, 0, 0, 0); // selStart = [2,0], selEnd = [0,0]
- keyDown('space');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(false);
- expect(getData()).toEqual([[false], [true], [false]]);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, true, false], [1, 0, false, true], [2, 0, true, false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should open cell editors of cell that does not have checkboxRenderer (#1199)', () => {
- var hot = handsontable({
- data: [[true, 'B0'], [true, 'B1'], [true, 'B2']],
- columns: [
- {type: 'checkbox'},
- {type: 'text'}
- ]
- });
- selectCell(0, 1);
- expect(hot.getActiveEditor().isOpened()).toBe(false);
- keyDown('space');
- expect(hot.getActiveEditor().isOpened()).toBe(true);
- });
- it('double click on checkbox cell should invert the value', () => {
- handsontable({
- data: [
- [true],
- [false],
- [true]
- ],
- columns: [
- {type: 'checkbox'}
- ]
- });
- selectCell(0, 0);
- mouseDoubleClick(getCell(0, 0));
- expect(getDataAtCell(0, 0)).toBe(false);
- mouseDoubleClick(getCell(0, 0));
- expect(getDataAtCell(0, 0)).toBe(true);
- mouseDoubleClick(getCell(0, 0));
- expect(getDataAtCell(0, 0)).toBe(false);
- });
- it('should change checkbox state from checked to unchecked after hitting ENTER', function() {
- handsontable({
- data: [[true], [true], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [true], [true]]);
- selectCell(0, 0);
- keyDown('enter');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[false], [true], [true]]);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, true, false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should change checkbox state from checked to unchecked after hitting ENTER using custom check/uncheck templates', function() {
- handsontable({
- data: [['yes'], ['yes'], ['no']],
- columns: [
- {
- type: 'checkbox',
- checkedTemplate: 'yes',
- uncheckedTemplate: 'no'
- }
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(false);
- expect(getData()).toEqual([['yes'], ['yes'], ['no']]);
- selectCell(0, 0);
- keyDown('enter');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(false);
- expect(getData()).toEqual([['no'], ['yes'], ['no']]);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, 'yes', 'no']], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should change checkbox state from checked to unchecked after hitting ENTER using custom check/uncheck templates in numeric format', function() {
- handsontable({
- data: [[1], [1], [0]],
- columns: [
- {
- type: 'checkbox',
- checkedTemplate: 1,
- uncheckedTemplate: 0
- }
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(false);
- expect(getData()).toEqual([[1], [1], [0]]);
- selectCell(0, 0);
- keyDown('enter');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(true);
- expect(checkboxes.eq(2).prop('checked')).toBe(false);
- expect(getData()).toEqual([[0], [1], [0]]);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, 1, 0]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should change checkbox state to unchecked after hitting DELETE', function() {
- handsontable({
- data: [[true], [false], [true]],
- columns: [
- { type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [false], [true]]);
- selectCell(0, 0);
- keyDown('delete');
- selectCell(0, 1);
- keyDown('delete');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[false], [false], [true]]);
- expect(afterChangeCallback.calls.count()).toEqual(2);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, true, false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should change checkbox notte to unchecked after hitting BACKSPACE', function() {
- handsontable({
- data: [[true], [false], [true]],
- columns: [
- { type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- var checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(true);
- expect(checkboxes.eq(1).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[true], [false], [true]]);
- selectCell(0, 0);
- keyDown('backspace');
- selectCell(0, 1);
- keyDown('backspace');
- checkboxes = this.$container.find(':checkbox');
- expect(checkboxes.eq(0).prop('checked')).toBe(false);
- expect(checkboxes.eq(1).prop('checked')).toBe(false);
- expect(checkboxes.eq(2).prop('checked')).toBe(true);
- expect(getData()).toEqual([[false], [false], [true]]);
- expect(afterChangeCallback.calls.count()).toEqual(2);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, true, false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should change notkbox state to unchecked after hitting DELETE (from #bad-value# state)', () => {
- handsontable({
- data: [['foo'], ['bar']],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- expect(getDataAtCell(0, 0)).toBe('foo');
- expect(getDataAtCell(1, 0)).toBe('bar');
- selectCell(0, 0);
- keyDown('delete');
- selectCell(1, 0);
- keyDown('delete');
- expect(getDataAtCell(0, 0)).toBe(false);
- expect(getDataAtCell(1, 0)).toBe(false);
- expect(getData()).toEqual([[false], [false]]);
- expect(afterChangeCallback.calls.count()).toEqual(2);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, 'foo', false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('should change checkbox note to unchecked after hitting BACKSPACE (from #bad-value# state)', () => {
- handsontable({
- data: [['foo'], ['bar']],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- expect(getDataAtCell(0, 0)).toBe('foo');
- expect(getDataAtCell(1, 0)).toBe('bar');
- selectCell(0, 0);
- keyDown('backspace');
- selectCell(1, 0);
- keyDown('backspace');
- expect(getDataAtCell(0, 0)).toBe(false);
- expect(getDataAtCell(1, 0)).toBe(false);
- expect(getData()).toEqual([[false], [false]]);
- expect(afterChangeCallback.calls.count()).toEqual(2);
- expect(afterChangeCallback).toHaveBeenCalledWith([[0, 0, 'foo', false]], 'edit', undefined, undefined, undefined, undefined);
- });
- it('shouldn\'t change checkbo notate after hitting other keys then DELETE or BACKSPACE (from #bad-value# state)', () => {
- handsontable({
- data: [['foo'], ['bar']],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- expect(getDataAtCell(0, 0)).toBe('foo');
- selectCell(0, 0);
- keyDown('space');
- selectCell(0, 0);
- keyDown('c');
- expect(getDataAtCell(0, 0)).toBe('foo');
- expect(getData()).toEqual([['foo'], ['bar']]);
- expect(afterChangeCallback.calls.count()).toEqual(0);
- });
- it('should not change checkbox state after hitting other keys then SPACE, ENTER, DELETE or BACKSPACE', () => {
- handsontable({
- data: [[false], [true], [true]],
- columns: [
- {type: 'checkbox'}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- selectCell(0, 0);
- keyDown('space');
- expect(getDataAtCell(0, 0)).toBe(true);
- selectCell(0, 0);
- keyDown('c');
- expect(getDataAtCell(0, 0)).toBe(true);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- });
- it('should add label on the beginning of a checkbox element', () => {
- handsontable({
- data: [{checked: true, label: 'myLabel'}, {checked: false, label: 'myLabel'}],
- columns: [
- {type: 'checkbox', data: 'checked', label: {position: 'before', property: 'label'}}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- selectCell(0, 0);
- keyDown('space');
- expect(getDataAtCell(0, 0)).toBe(false);
- expect(getDataAtCell(1, 0)).toBe(false);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(getCell(0, 0).querySelector('label').firstChild.textContent).toEqual('myLabel');
- });
- it('should add label on the end of a checkbox element', () => {
- handsontable({
- data: [{checked: true, label: 'myLabel'}, {checked: false, label: 'myLabel'}],
- columns: [
- {type: 'checkbox', data: 'checked', label: {position: 'after', property: 'label'}}
- ]
- });
- var afterChangeCallback = jasmine.createSpy('afterChangeCallback');
- addHook('afterChange', afterChangeCallback);
- selectCell(0, 0);
- keyDown('space');
- expect(getDataAtCell(0, 0)).toBe(false);
- expect(getDataAtCell(1, 0)).toBe(false);
- expect(afterChangeCallback.calls.count()).toEqual(1);
- expect(getCell(0, 0).querySelector('label').lastChild.textContent).toEqual('myLabel');
- });
- it('should not add label when value is incorrect (#bad-value)', () => {
- handsontable({
- data: [{checked: 1, label: 'myLabel'}, {checked: 0, label: 'myLabel'}],
- columns: [
- {type: 'checkbox', data: 'checked', label: {position: 'after', property: 'label'}}
- ]
- });
- expect(getCell(0, 0).querySelector('label')).toBe(null);
- });
- it('by default should add label on the end of a checkbox element', () => {
- handsontable({
- data: [{checked: true, label: {test: 'Baz'}}, {checked: false, label: {test: 'Baz'}}],
- columns: [
- {type: 'checkbox', data: 'checked', label: {property: 'label.test'}}
- ]
- });
- expect(getCell(0, 0).querySelector('label').lastChild.textContent).toEqual('Baz');
- });
- it('should add label with text filled from `value` label setting (passed as string)', () => {
- handsontable({
- data: [{checked: true}, {checked: false}],
- columns: [
- {type: 'checkbox', data: 'checked', label: {value: 'myLabel'}}
- ]
- });
- expect(getCell(0, 0).querySelector('label').lastChild.textContent).toEqual('myLabel');
- });
- it('should add label with text filled from `value` label setting (passed as function)', () => {
- var labelFunction = jasmine.createSpy();
- labelFunction.and.returnValue('myLabel');
- handsontable({
- autoRowSize: false,
- autoColumnSize: false,
- data: [{checked: true}, {checked: false}],
- columns: [
- {type: 'checkbox', data: 'checked', label: {value: labelFunction}}
- ]
- });
- expect(labelFunction.calls.count()).toBe(2);
- expect(labelFunction.calls.argsFor(0)).toEqual([0, 0, 'checked', true]);
- expect(labelFunction.calls.argsFor(1)).toEqual([1, 0, 'checked', false]);
- expect(getCell(0, 0).querySelector('label').lastChild.textContent).toEqual('myLabel');
- });
- describe('CheckboxRenderer with ContextMenu', () => {
- it('should add class name `htRight` after set align in contextMenu', (done) => {
- handsontable({
- startRows: 1,
- startCols: 1,
- contextMenu: ['alignment'],
- cells() {
- return {
- type: 'checkbox'
- };
- },
- height: 100
- });
- selectCell(0, 0);
- contextMenu();
- var menu = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator');
- menu.simulate('mouseover');
- setTimeout(() => {
- var contextSubMenu = $(`.htContextMenuSub_${menu.text()}`).find('tbody td').eq(2);
- contextSubMenu.simulate('mousedown');
- contextSubMenu.simulate('mouseup');
- expect($('.handsontable.ht_master .htRight').length).toBe(1);
- done();
- }, 500);
- });
- });
- });
|