diff --git a/packages/elements/src/components/Editor/index.tsx b/packages/elements/src/components/Editor/index.tsx index 8e56784bf4..114d06ee20 100644 --- a/packages/elements/src/components/Editor/index.tsx +++ b/packages/elements/src/components/Editor/index.tsx @@ -13,6 +13,7 @@ export interface EditorProps { contentClass?: string actions?: Array dataTest?: string + onBlur?: () => void } const defaultActions = [ @@ -42,6 +43,7 @@ export const Editor = ({ buttonClass = 'pell-button', contentClass = 'pell-content', dataTest = '', + onBlur, }: EditorProps) => { const containerEl = React.useRef(null) @@ -76,6 +78,11 @@ export const Editor = ({ }, [defaultContent]) return ( -
+
) } diff --git a/packages/elements/src/components/TextAreaEditor/__tests__/__snapshots__/index.tsx.snap b/packages/elements/src/components/TextAreaEditor/__tests__/__snapshots__/index.tsx.snap index 9490caf0ac..a2150fd400 100644 --- a/packages/elements/src/components/TextAreaEditor/__tests__/__snapshots__/index.tsx.snap +++ b/packages/elements/src/components/TextAreaEditor/__tests__/__snapshots__/index.tsx.snap @@ -1,58 +1,55 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`TextAreaEditor renderTextAreaEditor should match snapshot 1`] = ` -
-
-
- - -
-
-
-`; - -exports[`TextAreaEditor renderTextAreaEditor should match snapshot 2`] = ` -
-
-
- - -
-
-
-`; - exports[`TextAreaEditor should match a snapshot 1`] = ` - - - + + `; diff --git a/packages/elements/src/components/TextAreaEditor/__tests__/index.tsx b/packages/elements/src/components/TextAreaEditor/__tests__/index.tsx index 444955f883..0cdc64fd51 100644 --- a/packages/elements/src/components/TextAreaEditor/__tests__/index.tsx +++ b/packages/elements/src/components/TextAreaEditor/__tests__/index.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { shallow } from 'enzyme' -import { FieldProps, FieldInputProps, FieldMetaProps } from 'formik' -import { TextAreaEditor, TextAreaEditorProps, handleTextAreaOnChange, renderTextAreaEditor } from '../index' +import { FieldInputProps, Formik } from 'formik' +import { TextAreaEditor, TextAreaEditorProps, handleTextAreaOnChange, handleTextAreaOnBlur } from '../index' const props: TextAreaEditorProps = { id: 'username', @@ -12,7 +12,13 @@ const props: TextAreaEditorProps = { describe('TextAreaEditor', () => { it('should match a snapshot', () => { - expect(shallow()).toMatchSnapshot() + expect( + shallow( + + {() => } + , + ), + ).toMatchSnapshot() }) describe('onChange', () => { const mockField = { @@ -25,52 +31,14 @@ describe('TextAreaEditor', () => { fn('
') expect(mockField.onChange).toBeCalledWith({ target: { value: '
', name: '123' } }) }) - describe('renderTextAreaEditor', () => { - it('should match snapshot', () => { - const mockProps = { - labelText: 'mockLabel', - id: '123', - placeholder: 'mockPlaceholder', - } - const fn = renderTextAreaEditor(mockProps) - const mockField = { - name: '123', - value: '1', - } as FieldInputProps - const mockMeta = { - touched: true, - errors: '123', - value: '123', - initialValue: '123', - initialTouched: false, - initialError: '', - } as FieldMetaProps - const component = fn({ field: mockField, meta: mockMeta } as FieldProps) - const wrapper = shallow(
{component}
) - expect(wrapper).toMatchSnapshot() - }) - it('should match snapshot', () => { - const mockProps = { - labelText: 'mockLabel', - id: '123', - placeholder: 'mockPlaceholder', - } - const fn = renderTextAreaEditor(mockProps) - const mockField = { - name: '123', - } as FieldInputProps - const mockMeta = { - touched: false, - errors: '', - value: '123', - initialValue: '123', - initialTouched: false, - initialError: '', - } as FieldMetaProps - const component = fn({ field: mockField, meta: mockMeta } as FieldProps) - const wrapper = shallow(
{component}
) - expect(wrapper).toMatchSnapshot() + describe('handleTextAreaOnBlur', () => { + it('should call setTouched', () => { + const mockHelpers = { setTouched: jest.fn() } as any + const spy = jest.spyOn(mockHelpers, 'setTouched') + const fn = handleTextAreaOnBlur({ helpers: mockHelpers }) + fn() + expect(spy).toHaveBeenCalledWith(true) }) }) }) diff --git a/packages/elements/src/components/TextAreaEditor/index.tsx b/packages/elements/src/components/TextAreaEditor/index.tsx index fb624d1179..0f46522f79 100644 --- a/packages/elements/src/components/TextAreaEditor/index.tsx +++ b/packages/elements/src/components/TextAreaEditor/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Field, FieldInputProps, FieldProps } from 'formik' +import { FieldInputProps, FieldHelperProps, useField } from 'formik' import { checkError } from '../../utils/form' import { Editor, EditorProps } from '../Editor' @@ -15,38 +15,45 @@ export type HandleTextAreaOnChangeParams = { field: FieldInputProps } +export type HandleTextAreaOnBlurParams = { + helpers: FieldHelperProps +} + export const handleTextAreaOnChange = ({ field }: HandleTextAreaOnChangeParams) => (html: string) => { field.onChange({ target: { value: html, name: field.name } }) } -export const renderTextAreaEditor = ({ labelText, id, placeholder, ...restProps }) => ({ - field, - meta, -}: FieldProps) => { +export const handleTextAreaOnBlur = ({ helpers }: HandleTextAreaOnBlurParams) => () => { + helpers.setTouched(true) +} + +export const TextAreaEditor = ({ name, labelText, placeholder, id, ...restProps }: TextAreaEditorProps) => { + const [field, meta, helpers] = useField(name) + const hasError = checkError(meta) + return ( -
-
- - -
- {hasError && ( -
- {meta.error} + <> +
+
+ +
- )} -
+ {hasError && ( +
+ {meta.error} +
+ )} +
+ ) } - -export const TextAreaEditor = ({ name, labelText, placeholder, id, ...restProps }: TextAreaEditorProps) => ( - {renderTextAreaEditor({ labelText, id, placeholder, ...restProps })} -) diff --git a/packages/marketplace/src/tests/badges/badge-branches.svg b/packages/marketplace/src/tests/badges/badge-branches.svg index 69be6ec755..9713bda472 100644 --- a/packages/marketplace/src/tests/badges/badge-branches.svg +++ b/packages/marketplace/src/tests/badges/badge-branches.svg @@ -1 +1 @@ -Coverage:branchesCoverage:branches69.87%69.87% \ No newline at end of file +Coverage:branchesCoverage:branches69.9%69.9% diff --git a/packages/marketplace/src/tests/badges/badge-functions.svg b/packages/marketplace/src/tests/badges/badge-functions.svg index 929f772dd4..1b2ad6980c 100644 --- a/packages/marketplace/src/tests/badges/badge-functions.svg +++ b/packages/marketplace/src/tests/badges/badge-functions.svg @@ -1 +1 @@ -Coverage:functionsCoverage:functions74.75%74.75% \ No newline at end of file +Coverage:functionsCoverage:functions74.65%74.65% diff --git a/packages/web-components/src/scripts/start-search-widget.js b/packages/web-components/src/scripts/start-search-widget.js index 44d9c3f213..eccf197474 100644 --- a/packages/web-components/src/scripts/start-search-widget.js +++ b/packages/web-components/src/scripts/start-search-widget.js @@ -4,8 +4,9 @@ return (() => { try { const clearPublic = 'rimraf ./public/dist && rimraf ./public/themes' - // eslint-disable-next-line max-len - const moveHtml = 'mkdir -p ./public && cp ./src/search-widget/client/index.html ./public/ && cp ./src/property-detail/client/detail.html ./public/' + const moveHtml = + // eslint-disable-next-line max-len + 'mkdir -p ./public && cp ./src/search-widget/client/index.html ./public/ && cp ./src/property-detail/client/detail.html ./public/' // eslint-disable-next-line max-len const moveTheme = 'mkdir -p ./public/themes && cp ./src/common/styles/__themes__/themes.js ./public/themes' const clientScript =