From 9d049c5f05827a8ae585a2eedb9ad64f07e55431 Mon Sep 17 00:00:00 2001 From: brendanjbond Date: Mon, 25 Mar 2024 18:54:38 +0000 Subject: [PATCH] more tests --- .../normalize/__tests__/normalize.test.ts | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/src/process/normalize/__tests__/normalize.test.ts b/src/process/normalize/__tests__/normalize.test.ts index 013a024d..746328b9 100644 --- a/src/process/normalize/__tests__/normalize.test.ts +++ b/src/process/normalize/__tests__/normalize.test.ts @@ -5,7 +5,7 @@ import { normalizeProcessSync } from '../'; import { generateProcessorContext } from '../../__tests__/fixtures/util'; it('Should normalize a time component with a valid time value that doees not match dataFormat', async () => { - const timeField: TimeComponent = { + const timeComp: TimeComponent = { type: 'time', key: 'time', label: 'Time', @@ -13,13 +13,13 @@ it('Should normalize a time component with a valid time value that doees not mat dataFormat: 'HH:mm:ss' }; const data = { time: '12:00' }; - const context = generateProcessorContext(timeField, data); + const context = generateProcessorContext(timeComp, data); normalizeProcessSync(context); expect(context.data).to.deep.equal({time: '12:00:00'}); }); it('Should normalize a select boxes component with an incorrect data model', () => { - const selectBoxesField: SelectBoxesComponent = { + const selectBoxesComp: SelectBoxesComponent = { type: 'selectboxes', key: 'selectBoxes', label: 'Select Boxes', @@ -33,7 +33,72 @@ it('Should normalize a select boxes component with an incorrect data model', () const data = { selectBoxes: '' }; - const context = generateProcessorContext(selectBoxesField, data); + const context = generateProcessorContext(selectBoxesComp, data); normalizeProcessSync(context); expect(context.data).to.deep.equal({selectBoxes: {}}); }); + +it('Should normalize an email component value', () => { + const emailComp = { + type: 'email', + key: 'email', + input: true, + label: 'Email' + }; + const data = { + email: 'BrendanBond@Gmail.com' + }; + const context = generateProcessorContext(emailComp, data); + normalizeProcessSync(context); + expect(context.data).to.deep.equal({email: 'brendanbond@gmail.com'}); +}); + +it('Should normalize a radio component with a string value', () => { + const radioComp = { + type: 'radio', + key: 'radio', + input: true, + label: 'Radio', + values: [ + { + label: 'Yes', + value: 'true', + }, + { + label: 'No', + value: 'false', + } + ] + }; + const data = { + radio: 'true' + }; + const context = generateProcessorContext(radioComp, data); + normalizeProcessSync(context); + expect(context.data).to.deep.equal({radio: true}); +}); + +it('Should normalize a radio component value with a number', () => { + const radioComp = { + type: 'radio', + key: 'radio', + input: true, + label: 'Radio', + values: [ + { + label: 'Yes', + value: '1', + }, + { + label: 'No', + value: '0', + } + ] + }; + const data = { + radio: '0' + }; + const context = generateProcessorContext(radioComp, data); + normalizeProcessSync(context); + expect(context.data).to.deep.equal({radio: 0}); +});