|
| 1 | +import { GanttExportHelper } from 'ui/gantt/ui.gantt.export_helper'; |
| 2 | +import gridCoreUtils from '__internal/grids/grid_core/m_utils'; |
| 3 | + |
| 4 | +const moduleConfig = { |
| 5 | + beforeEach: function() { |
| 6 | + this.calledColumns = []; |
| 7 | + this.getDisplayValueStub = sinon.stub(gridCoreUtils, 'getDisplayValue').callsFake((column, rawValue) => { |
| 8 | + this.calledColumns.push(column && column.dataField); |
| 9 | + return rawValue; |
| 10 | + }); |
| 11 | + }, |
| 12 | + afterEach: function() { |
| 13 | + this.getDisplayValueStub.restore(); |
| 14 | + } |
| 15 | +}; |
| 16 | + |
| 17 | +QUnit.module('GanttExportHelper', moduleConfig); |
| 18 | + |
| 19 | +QUnit.test('getGridDisplayText uses only visible columns (T1307282)', function(assert) { |
| 20 | + const visibleColumns = [ |
| 21 | + { dataField: 'id', dataType: 'number' }, |
| 22 | + { dataField: 'title', dataType: 'string' } |
| 23 | + ]; |
| 24 | + |
| 25 | + const hiddenColumn = { |
| 26 | + dataField: 'secret', |
| 27 | + dataType: 'string', |
| 28 | + }; |
| 29 | + |
| 30 | + const treeListStub = { |
| 31 | + getController: function() { |
| 32 | + return { |
| 33 | + getVisibleColumns: function() { |
| 34 | + return visibleColumns; |
| 35 | + }, |
| 36 | + getColumns: function() { |
| 37 | + return [...visibleColumns, hiddenColumn]; |
| 38 | + } |
| 39 | + }; |
| 40 | + } |
| 41 | + }; |
| 42 | + |
| 43 | + const helper = new GanttExportHelper({ _treeList: treeListStub }); |
| 44 | + const data = { id: 1, title: 'Task A', secret: 'hidden' }; |
| 45 | + |
| 46 | + assert.strictEqual(helper._getGridDisplayText(0, data), '1', 'First visible column value returned'); |
| 47 | + assert.strictEqual(helper._getGridDisplayText(1, data), 'Task A', 'Second visible column value returned'); |
| 48 | + |
| 49 | + assert.strictEqual(helper._getGridDisplayText(2, data), undefined, 'Out-of-range visible column index returns undefined'); |
| 50 | + |
| 51 | + assert.deepEqual(this.calledColumns, ['id', 'title', undefined], 'Only visible columns (and undefined for out-of-range) were queried'); |
| 52 | + assert.notOk(this.calledColumns.includes('secret'), 'Hidden column was not accessed'); |
| 53 | +}); |
0 commit comments