-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/meta/assessment/originalDataPoint/odps/test/calc.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Numbers } from 'utils/numbers' | ||
|
||
import { calcTotalSubSubFieldArea } from 'meta/assessment/originalDataPoint/odps/calc' | ||
|
||
import { odp1, odp2, odp3 } from './mockODP' | ||
|
||
const testsCalcTotalSubSubFieldArea = [ | ||
{ | ||
name: 'calcTotalSubSubFieldArea - 1: all parent values 0, return 0', | ||
odp: odp1, | ||
expected: Numbers.toBigNumber('0'), | ||
}, | ||
{ | ||
name: 'calcTotalSubSubFieldArea - 2: parent value exist, child value empty, return null', | ||
odp: odp2, | ||
expected: null, | ||
}, | ||
{ | ||
name: 'calcTotalSubSubFieldArea - 3: parent values exist, child value empty, child value filled, return value', | ||
odp: odp3, | ||
expected: Numbers.BigNumber('375'), | ||
}, | ||
] | ||
|
||
describe('ODPs.calc', () => { | ||
testsCalcTotalSubSubFieldArea.forEach((_test) => { | ||
test(_test.name, () => { | ||
const result = calcTotalSubSubFieldArea({ | ||
originalDataPoint: _test.odp, | ||
field: 'forestPercent', | ||
subField: 'forestNaturalPercent', | ||
subSubField: 'forestNaturalForestOfWhichPrimaryForestPercent', | ||
}) | ||
expect(result).toEqual(_test.expected) | ||
}) | ||
}) | ||
|
||
// TODO: test calcTotalArea | ||
// TODO: test calcTotalFieldArea | ||
// TODO: test calcTotalSubFieldArea | ||
// TODO: test calcTotalSubSubFieldArea | ||
// TODO: test calcTotalLandArea | ||
}) |
199 changes: 199 additions & 0 deletions
199
src/meta/assessment/originalDataPoint/odps/test/mockODP.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import { OriginalDataPoint } from 'meta/assessment/originalDataPoint/originalDataPoint' | ||
|
||
export const odp1 = { | ||
id: 1400, | ||
countryIso: 'X01', | ||
year: 2011, | ||
dataSourceAdditionalComments: 'Add comments here', | ||
dataSourceMethods: ['nationalForestInventory'], | ||
dataSourceReferences: '', | ||
description: '', | ||
nationalClasses: [ | ||
{ | ||
area: '1500.00', | ||
name: 'Open forest', | ||
uuid: '02b381ca-2c39-49f7-9fef-80a3463f8f6b', | ||
definition: 'Add definition here', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '0.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: null, | ||
forestNaturalForestOfWhichPrimaryForestPercent: '0', | ||
}, | ||
{ | ||
area: '900.00', | ||
name: 'Closed forest', | ||
uuid: '3986836e-eac8-4287-a625-11df18a60d01', | ||
definition: '', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '0.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: '5.00', | ||
forestNaturalForestOfWhichPrimaryForestPercent: '0', | ||
}, | ||
{ | ||
area: '550.00', | ||
name: 'Plantations', | ||
uuid: '42b9b108-c655-40f3-a865-934346dfa859', | ||
definition: '', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '0.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: null, | ||
forestNaturalForestOfWhichPrimaryForestPercent: '0', | ||
}, | ||
{ | ||
area: '300.00', | ||
name: 'Woodland', | ||
uuid: '578bb1d6-961a-48c1-b489-877641f3c17f', | ||
definition: '', | ||
forestPercent: '0.00', | ||
otherWoodedLandPercent: '100.00', | ||
}, | ||
{ | ||
name: '', | ||
definition: '', | ||
uuid: '6c611c99-9eab-4369-a56b-16c671e491da', | ||
placeHolder: true, | ||
}, | ||
], | ||
idLegacy: null, | ||
} as OriginalDataPoint | ||
|
||
export const odp2 = { | ||
id: 1400, | ||
countryIso: 'X01', | ||
year: 2011, | ||
dataSourceAdditionalComments: 'Add comments here', | ||
dataSourceMethods: ['nationalForestInventory'], | ||
dataSourceReferences: '', | ||
description: '', | ||
nationalClasses: [ | ||
{ | ||
area: '1500.00', | ||
name: 'Open forest', | ||
uuid: '02b381ca-2c39-49f7-9fef-80a3463f8f6b', | ||
definition: 'Add definition here', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '50.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '50.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: null, | ||
forestNaturalForestOfWhichPrimaryForestPercent: null, | ||
}, | ||
{ | ||
area: '900.00', | ||
name: 'Closed forest', | ||
uuid: '3986836e-eac8-4287-a625-11df18a60d01', | ||
definition: '', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '0.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: '5.00', | ||
forestNaturalForestOfWhichPrimaryForestPercent: '0', | ||
}, | ||
{ | ||
area: '550.00', | ||
name: 'Plantations', | ||
uuid: '42b9b108-c655-40f3-a865-934346dfa859', | ||
definition: '', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '0.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: null, | ||
forestNaturalForestOfWhichPrimaryForestPercent: '0', | ||
}, | ||
{ | ||
area: '300.00', | ||
name: 'Woodland', | ||
uuid: '578bb1d6-961a-48c1-b489-877641f3c17f', | ||
definition: '', | ||
forestPercent: '0.00', | ||
otherWoodedLandPercent: '100.00', | ||
}, | ||
{ | ||
name: '', | ||
definition: '', | ||
uuid: '6c611c99-9eab-4369-a56b-16c671e491da', | ||
placeHolder: true, | ||
}, | ||
], | ||
idLegacy: null, | ||
} as OriginalDataPoint | ||
|
||
export const odp3 = { | ||
id: 1400, | ||
countryIso: 'X01', | ||
year: 2011, | ||
dataSourceAdditionalComments: 'Add comments here', | ||
dataSourceMethods: ['nationalForestInventory'], | ||
dataSourceReferences: '', | ||
description: '', | ||
nationalClasses: [ | ||
{ | ||
area: '1500.00', | ||
name: 'Open forest', | ||
uuid: '02b381ca-2c39-49f7-9fef-80a3463f8f6b', | ||
definition: 'Add definition here', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '50.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '50.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: null, | ||
forestNaturalForestOfWhichPrimaryForestPercent: '50.00', | ||
}, | ||
{ | ||
area: '900.00', | ||
name: 'Closed forest', | ||
uuid: '3986836e-eac8-4287-a625-11df18a60d01', | ||
definition: '', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '50.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: '5.00', | ||
forestNaturalForestOfWhichPrimaryForestPercent: null, | ||
}, | ||
{ | ||
area: '550.00', | ||
name: 'Plantations', | ||
uuid: '42b9b108-c655-40f3-a865-934346dfa859', | ||
definition: '', | ||
forestPercent: '100.00', | ||
forestNaturalPercent: '0.00', | ||
otherWoodedLandPercent: '0', | ||
forestPlantationPercent: '100.00', | ||
otherPlantedForestPercent: '0.00', | ||
forestPlantationIntroducedPercent: null, | ||
forestNaturalForestOfWhichPrimaryForestPercent: '0', | ||
}, | ||
{ | ||
area: '300.00', | ||
name: 'Woodland', | ||
uuid: '578bb1d6-961a-48c1-b489-877641f3c17f', | ||
definition: '', | ||
forestPercent: '0.00', | ||
otherWoodedLandPercent: '100.00', | ||
}, | ||
{ | ||
name: '', | ||
definition: '', | ||
uuid: '6c611c99-9eab-4369-a56b-16c671e491da', | ||
placeHolder: true, | ||
}, | ||
], | ||
idLegacy: null, | ||
} as OriginalDataPoint |