Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kreafox committed Nov 24, 2023
1 parent 3599b0f commit 7f93774
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/components/manage/Blocks/Group/CounterComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/components/manage/Blocks/Group/utils.js
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 15 additions & 0 deletions src/components/manage/Blocks/Group/utils.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 7f93774

Please sign in to comment.