Skip to content

Commit

Permalink
Tests and a minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kbairak committed Jul 25, 2024
1 parent d562c36 commit da7e0c3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/cli/test/api/extract.hashedkeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,34 @@ describe('extractPhrases with hashed keys', () => {
string: '<b>HTML inline text</b>',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'57b0d93fc0e1c3af68a41214147efd97': {
string: 'Text 5',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'404d0c0fef510bc89da7bc58ef160ccc': {
string: 'Text <1> 6 </1>',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'4f5fe2d7356c474bd2f4c03176c6bc45': {
string: 'Text <1> <2> 7 </2> </1>',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'1ecaf4c087b894bf86987fc2972ddba7': {
string: 'Text 8',
meta: { context: ['foo'], tags: [], occurrences: ['react.jsx'] },
},
f9818c4a4b3772c365b8522ff29cb785: {
string: 'Text <1/> 9',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'37678ce8d9c3a694ce19b947c64b9787': {
string: 'Text {msg}',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'5c6622f57e93ed83011b45833a12b0aa': {
string: 'Text 10',
meta: { context: [], tags: ['tag1', 'tag2'], occurrences: ['react.jsx'] },
},
});
});

Expand Down
28 changes: 28 additions & 0 deletions packages/cli/test/api/extract.sourcekeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ describe('extractPhrases with source keys', () => {
string: '<b>HTML inline text</b>',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'Text 5': {
string: 'Text 5',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'Text <1> 6 </1>': {
string: 'Text <1> 6 </1>',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'Text <1> <2> 7 </2> </1>': {
string: 'Text <1> <2> 7 </2> </1>',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'Text 8::foo': {
string: 'Text 8',
meta: { context: ['foo'], tags: [], occurrences: ['react.jsx'] },
},
'Text <1/> 9': {
string: 'Text <1/> 9',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'Text {msg}': {
string: 'Text {msg}',
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
},
'Text 10': {
string: 'Text 10',
meta: { context: [], tags: ['tag1', 'tag2'], occurrences: ['react.jsx'] },
},
});
});

Expand Down
7 changes: 7 additions & 0 deletions packages/cli/test/fixtures/react.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ function foo() {
<T _str={str3} />
{msg}
{msg2}
<T>Text 5</T>
<T>Text <b>6</b></T>
<T>Text <b><i>7</i></b></T>
<T _context={context}>Text 8</T>
<T>Text <br /> 9</T>
<T msg={msg}>Text {'{msg}'}</T>
<T _tags="tag1,tag2">Text 10</T>
</div>
);
}
2 changes: 1 addition & 1 deletion packages/react/src/utils/toStr.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function toElement(translation, propsContainer) {
if (rightSlash) {
// Single tag, copy props and don't include children in the React element
result.push(React.createElement(type, { ...props, key: lastKey }));
lastEnd += openingTag.length;
lastEnd += matchIndex + openingTag.length;
} else {
// Opening tag, find the closing tag which is guaranteed to be there and
// to be unique
Expand Down
24 changes: 24 additions & 0 deletions packages/react/tests/T.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,28 @@ describe('T', () => {
render(<T _str="hello {w}" w={<b>world</b>} />);
expect(screen.getByText('world')).toBeTruthy();
});

it('renders body', () => {
render(<T>hello <b>safe text</b></T>);
expect(screen.queryByText('hello')).toBeInTheDocument();
expect(screen.queryByText('safe text')).toBeInTheDocument();
});

it('renders body with single tags', () => {
render(<T>hello <br /> <b>safe text</b></T>);
expect(screen.queryByText('hello')).toBeInTheDocument();
expect(screen.queryByText('safe text')).toBeInTheDocument();
});

it('renders nestedbody', () => {
render(<T>hello <b>safe <T>text</T></b></T>);
expect(screen.queryByText('hello')).toBeInTheDocument();
expect(screen.queryByText('safe text')).toBeInTheDocument();
});

it('renders body with params', () => {
render(<T username="Bill">hello <b>mister {'{username}'}</b></T>);
expect(screen.queryByText('hello')).toBeInTheDocument();
expect(screen.queryByText('mister Bill')).toBeInTheDocument();
});
});

0 comments on commit da7e0c3

Please sign in to comment.