From 619302cdbed98799b95914e21d1dedbb91961cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bryxi=CC=81?= Date: Fri, 13 Sep 2019 08:53:21 +0100 Subject: [PATCH] bugfix: allow zero for fillColumnIndex fix: #767 --- addon/-private/column-tree.js | 3 ++- .../components/headers/main-test.js | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/addon/-private/column-tree.js b/addon/-private/column-tree.js index a65917495..e6d4fe451 100644 --- a/addon/-private/column-tree.js +++ b/addon/-private/column-tree.js @@ -12,6 +12,7 @@ import { scheduler, Token } from 'ember-raf-scheduler'; import { getOrCreate } from './meta-cache'; import { objectAt, move, splice } from './utils/array'; import { mergeSort } from './utils/sort'; +import { isEmpty } from '@ember/utils'; import { getScale, getOuterClientRect, getInnerClientRect } from './utils/element'; import { MainIndicator, DropIndicator } from './utils/reorder-indicators'; import { notifyPropertyChange } from './utils/ember'; @@ -653,7 +654,7 @@ export default EmberObject.extend({ } else if (fillMode === FILL_MODE.LAST_COLUMN) { this.resizeColumn(columns.length - 1, delta); } else if (fillMode === FILL_MODE.NTH_COLUMN) { - assert("fillMode 'nth-column' must have a fillColumnIndex defined", fillColumnIndex); + assert("fillMode 'nth-column' must have a fillColumnIndex defined", !isEmpty(fillColumnIndex)); this.resizeColumn(fillColumnIndex, delta); } } diff --git a/tests/integration/components/headers/main-test.js b/tests/integration/components/headers/main-test.js index b52a8a9c8..d43c3a7e7 100644 --- a/tests/integration/components/headers/main-test.js +++ b/tests/integration/components/headers/main-test.js @@ -167,12 +167,34 @@ module('Integration | header | main', function() { ); }); + test('nth column mode for first column', async function(assert) { + let columnWidth = 30; + + await generateTable(this, { + fillMode: 'nth-column', + fillColumnIndex: 0, + widthConstraint: 'eq-container', + columnCount: 3, + columnOptions: { + width: columnWidth, + }, + }); + + let tableWidth = table.width; + let middleColumnWidth = table.headers.objectAt(0).width; + + assert.ok( + Math.abs(tableWidth - middleColumnWidth - 2 * columnWidth) <= 1, + 'nth column takes extra space in nth column resize mode.' + ); + }); + test('nth column mode', async function(assert) { let columnWidth = 30; await generateTable(this, { fillMode: 'nth-column', - fillColumnIndex: '1', + fillColumnIndex: 1, widthConstraint: 'eq-container', columnCount: 3, columnOptions: {