Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"test": "npm-run-all lint test:unit test:browser test:compatibility",
"test:unit": "cross-env NODE_ICU_DATA=node_modules/full-icu jest",
"test:watch": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch",
"test:tdd": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch offset",
"test:tdd": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch named-expressions",
"test:coverage": "npm run test:unit -- --coverage",
"test:logMemory": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --runInBand --logHeapUsage",
"test:unit.ci": "cross-env NODE_ICU_DATA=node_modules/full-icu node --expose-gc ./node_modules/jest/bin/jest --forceExit",
Expand Down
52 changes: 52 additions & 0 deletions test/unit/named-expressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,34 @@ describe('Named expressions - named ranges', () => {

expect(changes).toContainEqual(new ExportedNamedExpressionChange('fooo', [[1, 3], [2, 4]]))
})

it('should update automatically when row is added to the referenced range', () => {
const engine = HyperFormula.buildFromArray([
[1, 2],
[3, 4],
])

engine.addNamedExpression('range', '=Sheet1!$A$1:$B$2')
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$B$2')

engine.addRows(0, [1, 1])
expect(engine.getSheetValues(0)).toEqual([[1, 2], [], [3, 4]])
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$B$3')
})

it('should update automatically when column is added to the referenced range', () => {
const engine = HyperFormula.buildFromArray([
[1, 2],
[3, 4],
])

engine.addNamedExpression('range', '=Sheet1!$A$1:$B$2')
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$B$2')

engine.addColumns(0, [1, 1])
expect(engine.getSheetValues(0)).toEqual([[1, null, 2], [3, null, 4]])
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$C$2')
})
})

describe('when created on initialization', () => {
Expand All @@ -1651,6 +1679,30 @@ describe('Named expressions - named ranges', () => {
expect(engine.getCellValue(adr('B1'))).toEqual(4)
expect(engine.getCellValue(adr('C1'))).toEqual(4)
})

it('should update automatically when row is added to the referenced range', () => {
const engine = HyperFormula.buildFromArray([
[1, 2],
[3, 4],
], {}, [{ name: 'range', expression: '=Sheet1!$A$1:$B$2' }])
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$B$2')

engine.addRows(0, [1, 1])
expect(engine.getSheetValues(0)).toEqual([[1, 2], [], [3, 4]])
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$B$3')
})

it('should update automatically when column is added to the referenced range', () => {
const engine = HyperFormula.buildFromArray([
[1, 2],
[3, 4],
], {}, [{ name: 'range', expression: '=Sheet1!$A$1:$B$2' }])
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$B$2')

engine.addColumns(0, [1, 1])
expect(engine.getSheetValues(0)).toEqual([[1, null, 2], [3, null, 4]])
expect(engine.getNamedExpressionFormula('range')).toEqual('=Sheet1!$A$1:$C$2')
})
})
})

Expand Down
Loading