Skip to content

Commit 270da75

Browse files
authored
Add unit test to make sure issue 1297 will not be introduced again (#1535)
* Add unit test to make sure issue 1297 will not be introduced again in the future * Disable 'Unchanged files with check annotations' section in PR * Revert last commit * Revert change made by mistake * Add jsdoc comment * Fix type error
1 parent 29178e5 commit 270da75

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AbsoluteCellRange.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ export interface SimpleCellRange {
2626
end: SimpleCellAddress,
2727
}
2828

29-
export function isSimpleCellRange(obj: any): obj is SimpleCellRange {
30-
if (obj && (typeof obj === 'object' || typeof obj === 'function')) {
29+
/**
30+
* Type guard that checks if an object is a valid SimpleCellRange.
31+
* @param {unknown} val - Value to check
32+
* @returns {boolean} True if and only if the object is a valid SimpleCellRange
33+
*/
34+
export function isSimpleCellRange(val: unknown): val is SimpleCellRange {
35+
if (val && (typeof val === 'object' || typeof val === 'function')) {
36+
const obj = val as Record<string, unknown>
3137
return 'start' in obj && isSimpleCellAddress(obj.start) && 'end' in obj && isSimpleCellAddress(obj.end)
3238
} else {
3339
return false

test/unit/cruds/change-cell-content.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,20 @@ describe('changing cell content', () => {
582582
expect(engine.getCellValueDetailedType({ sheet: 0, col: 0, row: 1 })).toEqual(CellValueDetailedType.NUMBER_CURRENCY)
583583
expect(engine.getCellValueDetailedType({ sheet: 0, col: 0, row: 2 })).toEqual(CellValueDetailedType.NUMBER_PERCENT)
584584
})
585+
586+
it('should work in scenario from issue https://github.com/handsontable/hyperformula/issues/1297', () => {
587+
const engine = HyperFormula.buildFromArray([
588+
[1, 2, '=SUM(A1:B1)'],
589+
['=SUM(1:1)', 0, 0],
590+
['=SUM(1:2)', 0, 0],
591+
])
592+
593+
engine.setCellContents(adr('C1'), [['=SUM(A1:B1)']])
594+
engine.setCellContents(adr('A3'), [['=SUM(A1:C2)']])
595+
engine.setCellContents(adr('B1'), [[null]])
596+
597+
expect(engine.getCellValue(adr('A3'))).toEqual(4)
598+
})
585599
})
586600

587601
describe('change multiple cells contents', () => {

0 commit comments

Comments
 (0)