Skip to content

Commit

Permalink
test(@dpc-sdp/ripple-tide-webform): ✅ fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingallday committed Jun 26, 2024
1 parent fbffa9a commit 349ac75
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { expect, describe, it } from '@jest/globals'
import { getConditionals } from './webform-conditional-logic'

const logger = {
warn: (message: string, props: { label: string }) => {
console.warn(props.label, message)
}
}

describe('getConditionals', () => {
describe('states', () => {
it('required', () => {
Expand All @@ -18,7 +24,7 @@ describe('getConditionals', () => {
required: '$isChecked($get(input_a).value, "true")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('disabled', () => {
Expand All @@ -36,7 +42,7 @@ describe('getConditionals', () => {
disabled: '$isChecked($get(input_a).value, "true")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('enabled', () => {
Expand All @@ -54,7 +60,7 @@ describe('getConditionals', () => {
disabled: '$negate($isChecked($get(input_a).value, "true"))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('visible', () => {
Expand All @@ -72,7 +78,7 @@ describe('getConditionals', () => {
if: '$isChecked($get(input_a).value, "true")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('invisible', () => {
Expand All @@ -90,7 +96,7 @@ describe('getConditionals', () => {
if: '$negate($isChecked($get(input_a).value, "true"))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})
})

Expand All @@ -110,7 +116,7 @@ describe('getConditionals', () => {
required: '$negate($isFilled($get(input_a).value))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('filled', () => {
Expand All @@ -128,7 +134,7 @@ describe('getConditionals', () => {
required: '$isFilled($get(input_a).value)'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('checked', () => {
Expand All @@ -146,7 +152,7 @@ describe('getConditionals', () => {
required: '$isChecked($get(input_a).value, "true")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('unchecked', () => {
Expand All @@ -164,7 +170,7 @@ describe('getConditionals', () => {
required: '$negate($isChecked($get(input_a).value, "true"))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('value', () => {
Expand All @@ -182,7 +188,7 @@ describe('getConditionals', () => {
required: '$isEqual($get(input_a).value, "abc")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('!value', () => {
Expand All @@ -200,7 +206,7 @@ describe('getConditionals', () => {
required: '$negate($isEqual($get(input_a).value, abc))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('pattern', () => {
Expand All @@ -218,7 +224,7 @@ describe('getConditionals', () => {
required: '$isPatternMatch($get(input_a).value, "abc")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('!pattern', () => {
Expand All @@ -236,7 +242,7 @@ describe('getConditionals', () => {
required: '$negate($isPatternMatch($get(input_a).value, "abc"))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('less', () => {
Expand All @@ -254,7 +260,7 @@ describe('getConditionals', () => {
required: '$difference($get(input_a).value, 10) < 0'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('greater', () => {
Expand All @@ -272,7 +278,7 @@ describe('getConditionals', () => {
required: '$difference($get(input_a).value, 10) > 0'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})
})

Expand All @@ -296,7 +302,7 @@ describe('getConditionals', () => {
'$isChecked($get(input_a).value, "true") && $isEqual($get(input_b).value, "abc")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('OR', () => {
Expand All @@ -323,7 +329,7 @@ describe('getConditionals', () => {
'$isChecked($get(input_a).value, "true") || $isEqual($get(input_b).value, "abc")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('XOR', () => {
Expand All @@ -350,7 +356,7 @@ describe('getConditionals', () => {
'$xor($isChecked($get(input_a).value, "true"), $isEqual($get(input_b).value, "abc"))'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})
})

Expand All @@ -370,7 +376,7 @@ describe('getConditionals', () => {
required: '$isChecked($get(input_a).value, "option_one")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})

it('value', () => {
Expand All @@ -388,7 +394,7 @@ describe('getConditionals', () => {
required: '$isEqual($get(input_a).value, "option_one")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})
})

Expand All @@ -408,6 +414,6 @@ describe('getConditionals', () => {
required: '$isChecked($get(test_id_input_a).value, "true")'
}

expect(getConditionals(input)).toEqual(expected)
expect(getConditionals(input, logger)).toEqual(expected)
})
})

0 comments on commit 349ac75

Please sign in to comment.