diff --git a/src/components/manage/Blocks/Group/CounterComponent.jsx b/src/components/manage/Blocks/Group/CounterComponent.jsx index d6c37c3..bca416d 100644 --- a/src/components/manage/Blocks/Group/CounterComponent.jsx +++ b/src/components/manage/Blocks/Group/CounterComponent.jsx @@ -7,15 +7,7 @@ import { visitBlocks } from '@plone/volto/helpers/Blocks/Blocks'; import { serializeNodesToText } from '@plone/volto-slate/editor/render'; import delightedSVG from '@plone/volto/icons/delighted.svg'; import dissatisfiedSVG from '@plone/volto/icons/dissatisfied.svg'; - -const countCharsWithoutSpaces = (paragraph) => { - const regex = /[^\s\\]/g; - return (paragraph.match(regex) || []).length; -}; - -const countCharsWithSpaces = (paragraph) => { - return paragraph?.length || 0; -}; +import { countCharsWithoutSpaces, countCharsWithSpaces } from './utils'; const countTextInEachBlock = (countTextIn, ignoreSpaces, groupCharCount) => ([ id, diff --git a/src/components/manage/Blocks/Group/utils.js b/src/components/manage/Blocks/Group/utils.js new file mode 100644 index 0000000..fc1dcfd --- /dev/null +++ b/src/components/manage/Blocks/Group/utils.js @@ -0,0 +1,8 @@ +export function countCharsWithoutSpaces(paragraph) { + const regex = /[^\s\\]/g; + return (paragraph.match(regex) || []).length; +} + +export function countCharsWithSpaces(paragraph) { + return paragraph?.length || 0; +} diff --git a/src/components/manage/Blocks/Group/utils.test.js b/src/components/manage/Blocks/Group/utils.test.js new file mode 100644 index 0000000..4cf02d7 --- /dev/null +++ b/src/components/manage/Blocks/Group/utils.test.js @@ -0,0 +1,15 @@ +import { countCharsWithoutSpaces, countCharsWithSpaces } from './utils'; + +describe('countCharsWithoutSpaces', () => { + it('should return number of charts without spaces', () => { + const paragraph = 'Lorem ipsum dolor sit'; + expect(countCharsWithoutSpaces(paragraph)).toBe(18); + }); +}); + +describe('countCharsWithSpaces', () => { + it('should return number of charts with spaces', () => { + const paragraph = 'Lorem ipsum dolor sit'; + expect(countCharsWithSpaces(paragraph)).toBe(21); + }); +});