Skip to content

Commit

Permalink
test: simplified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Aug 18, 2023
1 parent e81f2e6 commit 25b7291
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions src/modules/pivotTable/__tests__/addToTotalIfNumber.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,84 @@
import { addToTotalIfNumber } from '../addToTotalIfNumber.js'

const field = 'test'
const tests = [
{
testName: 'negative value',
value: -1,
totalObj: {},
field,
total: undefined,
expected: -1,
},
{
testName: 'zero value',
value: 0,
totalObj: {},
field,
total: undefined,
expected: 0,
},
{
testName: 'positive value',
value: 1,
totalObj: {},
field,
total: undefined,
expected: 1,
},
{
testName: 'null value',
value: null,
totalObj: {},
field,
total: undefined,
expected: undefined,
},
{
testName: 'undefined value',
value: undefined,
totalObj: {},
field,
total: undefined,
expected: undefined,
},
{
testName: 'string value',
value: 'string',
totalObj: {},
field,
total: undefined,
expected: undefined,
},
{
testName: 'negative value with existing total',
value: -1,
totalObj: { [field]: 100 },
field,
total: 100,
expected: 99,
},
{
testName: 'zero value with existing total',
value: 0,
totalObj: { [field]: 100 },
field,
total: 100,
expected: 100,
},
{
testName: 'positive value with existing total',
value: 1,
totalObj: { [field]: 100 },
field,
total: 100,
expected: 101,
},
{
testName: 'null value with existing total',
value: null,
totalObj: { [field]: 100 },
field,
total: 100,
expected: 100,
},
{
testName: 'undefined value with existing total',
value: undefined,
totalObj: { [field]: 100 },
field,
total: 100,
expected: 100,
},
{
testName: 'string value with existing total',
value: 'string',
totalObj: { [field]: 100 },
field,
total: 100,
expected: 100,
},
]

describe('addToTotalIfNumber', () => {
tests.forEach((t) => {
it(t.testName, () => {
expect(addToTotalIfNumber(t.value, t.totalObj[t.field])).toEqual(
t.expected
)
expect(addToTotalIfNumber(t.value, t.total)).toEqual(t.expected)
})
})
})

0 comments on commit 25b7291

Please sign in to comment.