123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- describe('NumericRenderer', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should render formatted number', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- handsontable({
- cells() {
- return {
- type: 'numeric',
- format: '$0,0.00'
- };
- },
- afterValidate: onAfterValidate
- });
- setDataAtCell(2, 2, '1000.234');
- setTimeout(() => {
- expect(getCell(2, 2).innerHTML).toEqual('$1,000.23');
- done();
- }, 200);
- });
- it('should render signed number', (done) => {
- var onAfterValidate = jasmine.createSpy('onAfterValidate');
- handsontable({
- cells() {
- return {
- type: 'numeric',
- format: '$0,0.00'
- };
- },
- afterValidate: onAfterValidate
- });
- setDataAtCell(2, 2, '-1000.234');
- setTimeout(() => {
- expect(getCell(2, 2).innerHTML).toEqual('-$1,000.23');
- done();
- }, 200);
- });
- it('should try to render string as numeral', (done) => {
- handsontable({
- cells() {
- return {
- type: 'numeric',
- format: '$0,0.00'
- };
- },
- });
- setDataAtCell(2, 2, '123 simple test');
- setTimeout(() => {
- expect(getCell(2, 2).innerHTML).toEqual('$123.00');
- done();
- }, 100);
- });
- it('should add class names `htNumeric` and `htRight` to the cell if it renders a number', () => {
- var DIV = document.createElement('DIV');
- var instance = new Handsontable(DIV, {});
- var TD = document.createElement('TD');
- TD.className = 'someClass';
- Handsontable.renderers.NumericRenderer(instance, TD, 0, 0, 0, 123, {});
- expect(TD.className).toEqual('someClass htRight htNumeric');
- instance.destroy();
- });
- it('should add class names `htNumeric` and `htRight` to the cell if it renders a numeric string', () => {
- var DIV = document.createElement('DIV');
- var instance = new Handsontable(DIV, {});
- var TD = document.createElement('TD');
- TD.className = 'someClass';
- Handsontable.renderers.NumericRenderer(instance, TD, 0, 0, 0, '123', {});
- expect(TD.className).toEqual('someClass htRight htNumeric');
- instance.destroy();
- });
- it('should not add class name `htNumeric` to the cell if it renders a text', () => {
- var DIV = document.createElement('DIV');
- var instance = new Handsontable(DIV, {});
- var TD = document.createElement('TD');
- TD.className = 'someClass';
- Handsontable.renderers.NumericRenderer(instance, TD, 0, 0, 0, 'abc', {});
- expect(TD.className).toEqual('someClass');
- instance.destroy();
- });
- it('should add class name `htDimmed` to a read only cell', () => {
- var DIV = document.createElement('DIV');
- var instance = new Handsontable(DIV, {});
- var TD = document.createElement('TD');
- Handsontable.renderers.NumericRenderer(instance, TD, 0, 0, 0, 123, {readOnly: true, readOnlyCellClassName: 'htDimmed'});
- expect(TD.className).toContain('htDimmed');
- instance.destroy();
- });
- describe('NumericRenderer with ContextMenu', () => {
- it('should change class name from default `htRight` to `htLeft` after set align in contextMenu', (done) => {
- handsontable({
- startRows: 1,
- startCols: 1,
- contextMenu: ['alignment'],
- cells() {
- return {
- type: 'numeric',
- format: '$0,0.00'
- };
- },
- height: 100
- });
- setDataAtCell(0, 0, '1000');
- 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(0);
- contextSubMenu.simulate('mousedown');
- contextSubMenu.simulate('mouseup');
- expect($('.handsontable.ht_master .htLeft:not(.htRight)').length).toBe(1);
- done();
- }, 500);
- });
- });
- });
|