Skip to content

Commit

Permalink
refactor: move internal radio field constant over to shared as SSOT
Browse files Browse the repository at this point in the history
  • Loading branch information
justynoh committed Mar 18, 2024
1 parent 86e5e93 commit f270eea
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions frontend/src/templates/Field/Radio/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { CLIENT_RADIO_OTHERS_INPUT_VALUE as RADIO_OTHERS_INPUT_VALUE } from '~shared/constants'

export const RADIO_OTHERS_INPUT_KEY = 'othersInput'
// TODO: Keep this in sync with the shared value.
export const RADIO_OTHERS_INPUT_VALUE = '!!FORMSG_INTERNAL_RADIO_OTHERS_VALUE!!'
3 changes: 3 additions & 0 deletions shared/constants/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export const PAYMENT_PRODUCT_FIELD_ID = 'payment_products'
export const PAYMENT_VARIABLE_INPUT_AMOUNT_FIELD_ID =
'payment_variable_input_amount_field_id'

export const CLIENT_RADIO_OTHERS_INPUT_VALUE =
'!!FORMSG_INTERNAL_RADIO_OTHERS_VALUE!!'

// The current encrypt version to assign to the encrypted submission.
// This is needed if we ever break backwards compatibility with
// end-to-end encryption
Expand Down
6 changes: 3 additions & 3 deletions shared/utils/__tests__/logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
LogicFieldClientRadioResponseInput,
LogicFieldResponse,
LogicFieldServerResponse,
RADIO_OTHERS_INPUT_VALUE,
} from '../logic'

import {
Expand All @@ -22,6 +21,7 @@ import {
ShortTextFieldBase,
ShowFieldLogicDto,
} from '../../types'
import { CLIENT_RADIO_OTHERS_INPUT_VALUE } from '../../constants'

describe('Logic validation', () => {
/** Mock a field's bare essentials */
Expand Down Expand Up @@ -1100,7 +1100,7 @@ describe('Logic validation', () => {
getVisibleFieldIds(
[
fillInRadioButton({
value: RADIO_OTHERS_INPUT_VALUE,
value: CLIENT_RADIO_OTHERS_INPUT_VALUE,
othersInput: 'test',
}) as unknown as LogicFieldResponse,
textLogicFieldServerResponse,
Expand Down Expand Up @@ -1312,7 +1312,7 @@ describe('Logic validation', () => {
getLogicUnitPreventingSubmit(
[
fillInRadioButton({
value: RADIO_OTHERS_INPUT_VALUE,
value: CLIENT_RADIO_OTHERS_INPUT_VALUE,
othersInput: 'test',
}) as unknown as LogicFieldResponse,
textLogicFieldServerResponse,
Expand Down
7 changes: 2 additions & 5 deletions shared/utils/logic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CLIENT_RADIO_OTHERS_INPUT_VALUE } from '../constants'
import {
BasicField,
FormDto,
Expand All @@ -11,10 +12,6 @@ import {
LogicableField,
} from '../types'

// TODO: Keep this in sync with the frontend value.
// Exported for testing
export const RADIO_OTHERS_INPUT_VALUE = '!!FORMSG_INTERNAL_RADIO_OTHERS_VALUE!!'

const LOGIC_CONDITIONS: LogicCondition[] = [
[
BasicField.Dropdown,
Expand Down Expand Up @@ -413,7 +410,7 @@ const isConditionFulfilled = (
} else {
// (4) Client-side handling
if (
currentValue.value === RADIO_OTHERS_INPUT_VALUE &&
currentValue.value === CLIENT_RADIO_OTHERS_INPUT_VALUE &&
!!currentValue.othersInput
) {
return true
Expand Down

0 comments on commit f270eea

Please sign in to comment.