Skip to content

Commit

Permalink
fix: fix issue with warnings not appearing for first line of email text
Browse files Browse the repository at this point in the history
We needed to use childNodes instead of children in order to pick up both the child elements with
text and the DOM text nodes directly associated with the element.

re #117
  • Loading branch information
sbrudz committed Aug 25, 2021
1 parent b1d5f43 commit 2b93a40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions spec/JustNotSorrySpec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ describe('JustNotSorry', () => {
expect(wrapper.state('parentNode')).toBe(domNode.parentNode);
});

describe('when there are top-level and child nodes', () => {
it('catches the warnings for both', () => {
const elem = mount(
<div props={{ id: 'div-focus' }} contentEditable={'true'}>
test!!!
<div>Hello!!!</div>
</div>
);

const domNode = elem.getDOMNode();
instance.updateWarnings(domNode, [
buildWarning('\\b!{3,}\\B', 'warning message'),
]);

expect(wrapper.state('warnings').length).toBe(2);
expect(wrapper.state('parentNode')).toBe(domNode.parentNode);
});
});

it('does not add warnings for tooltip matches', () => {
const node = enterText('test justify test');
simulateEvent(node, 'focus');
Expand Down
4 changes: 2 additions & 2 deletions src/components/JustNotSorry.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class JustNotSorry extends Component {

updateWarnings(email, patterns) {
const newWarnings =
email.children.length > 0
? Array.from(email.children)
email.childNodes.length > 0
? Array.from(email.childNodes)
.filter((node) => node.textContent !== '')
.flatMap((text) => findRanges(text, patterns))
: findRanges(email, patterns);
Expand Down

0 comments on commit 2b93a40

Please sign in to comment.