|
| 1 | +import { GridRange } from '@deephaven/grid'; |
| 2 | +import IrisGridContextMenuHandler from './IrisGridContextMenuHandler'; |
| 3 | + |
| 4 | +describe('getLatestSelection', () => { |
| 5 | + it('should return the original selection if the clicked cell is within the original selection', () => { |
| 6 | + const originalSelection = [new GridRange(1, 1, 2, 2)]; |
| 7 | + const result = IrisGridContextMenuHandler.getLatestSelection( |
| 8 | + originalSelection, |
| 9 | + 1, |
| 10 | + 1 |
| 11 | + ); |
| 12 | + |
| 13 | + expect(result).toBe(originalSelection); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should return a new selection with the clicked cell if it is outside the original selection', () => { |
| 17 | + const originalSelection = [new GridRange(1, 1, 2, 2)]; |
| 18 | + const columnIndex = 3; |
| 19 | + const rowIndex = 3; |
| 20 | + |
| 21 | + const result = IrisGridContextMenuHandler.getLatestSelection( |
| 22 | + originalSelection, |
| 23 | + columnIndex, |
| 24 | + rowIndex |
| 25 | + ); |
| 26 | + |
| 27 | + expect(result).toEqual([GridRange.makeCell(columnIndex, rowIndex)]); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should return the original selection if columnIndex is null', () => { |
| 31 | + const originalSelection = [new GridRange(1, 1, 2, 2)]; |
| 32 | + |
| 33 | + const result = IrisGridContextMenuHandler.getLatestSelection( |
| 34 | + originalSelection, |
| 35 | + null, |
| 36 | + 1 |
| 37 | + ); |
| 38 | + |
| 39 | + expect(result).toBe(originalSelection); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return the original selection if rowIndex is null', () => { |
| 43 | + const originalSelection = [new GridRange(1, 1, 2, 2)]; |
| 44 | + |
| 45 | + const result = IrisGridContextMenuHandler.getLatestSelection( |
| 46 | + originalSelection, |
| 47 | + null, |
| 48 | + 1 |
| 49 | + ); |
| 50 | + |
| 51 | + expect(result).toBe(originalSelection); |
| 52 | + }); |
| 53 | +}); |
0 commit comments