Skip to content

Commit 7e218f8

Browse files
author
Konstantinos Bairaktaris
committed
Tests and a minor fix
1 parent 541c00c commit 7e218f8

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

packages/cli/test/api/extract.hashedkeys.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,34 @@ describe('extractPhrases with hashed keys', () => {
154154
string: '<b>HTML inline text</b>',
155155
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
156156
},
157+
'57b0d93fc0e1c3af68a41214147efd97': {
158+
string: 'Text 5',
159+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
160+
},
161+
'404d0c0fef510bc89da7bc58ef160ccc': {
162+
string: 'Text <1> 6 </1>',
163+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
164+
},
165+
'4f5fe2d7356c474bd2f4c03176c6bc45': {
166+
string: 'Text <1> <2> 7 </2> </1>',
167+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
168+
},
169+
'1ecaf4c087b894bf86987fc2972ddba7': {
170+
string: 'Text 8',
171+
meta: { context: ['foo'], tags: [], occurrences: ['react.jsx'] },
172+
},
173+
f9818c4a4b3772c365b8522ff29cb785: {
174+
string: 'Text <1/> 9',
175+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
176+
},
177+
'37678ce8d9c3a694ce19b947c64b9787': {
178+
string: 'Text {msg}',
179+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
180+
},
181+
'5c6622f57e93ed83011b45833a12b0aa': {
182+
string: 'Text 10',
183+
meta: { context: [], tags: ['tag1', 'tag2'], occurrences: ['react.jsx'] },
184+
},
157185
});
158186
});
159187

packages/cli/test/api/extract.sourcekeys.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,34 @@ describe('extractPhrases with source keys', () => {
147147
string: '<b>HTML inline text</b>',
148148
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
149149
},
150+
'Text 5': {
151+
string: 'Text 5',
152+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
153+
},
154+
'Text <1> 6 </1>': {
155+
string: 'Text <1> 6 </1>',
156+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
157+
},
158+
'Text <1> <2> 7 </2> </1>': {
159+
string: 'Text <1> <2> 7 </2> </1>',
160+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
161+
},
162+
'Text 8::foo': {
163+
string: 'Text 8',
164+
meta: { context: ['foo'], tags: [], occurrences: ['react.jsx'] },
165+
},
166+
'Text <1/> 9': {
167+
string: 'Text <1/> 9',
168+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
169+
},
170+
'Text {msg}': {
171+
string: 'Text {msg}',
172+
meta: { context: [], tags: [], occurrences: ['react.jsx'] },
173+
},
174+
'Text 10': {
175+
string: 'Text 10',
176+
meta: { context: [], tags: ['tag1', 'tag2'], occurrences: ['react.jsx'] },
177+
},
150178
});
151179
});
152180

packages/cli/test/fixtures/react.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ function foo() {
3030
<T _str={str3} />
3131
{msg}
3232
{msg2}
33+
<T>Text 5</T>
34+
<T>Text <b>6</b></T>
35+
<T>Text <b><i>7</i></b></T>
36+
<T _context={context}>Text 8</T>
37+
<T>Text <br /> 9</T>
38+
<T msg={msg}>Text {'{msg}'}</T>
39+
<T _tags="tag1,tag2">Text 10</T>
3340
</div>
3441
);
3542
}

packages/react/src/utils/toStr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function toElement(translation, propsContainer) {
109109
if (rightSlash) {
110110
// Single tag, copy props and don't include children in the React element
111111
result.push(React.createElement(type, { ...props, key: lastKey }));
112-
lastEnd += openingTag.length;
112+
lastEnd += matchIndex + openingTag.length;
113113
} else {
114114
// Opening tag, find the closing tag which is guaranteed to be there and
115115
// to be unique

packages/react/tests/T.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,28 @@ describe('T', () => {
4444
render(<T _str="hello {w}" w={<b>world</b>} />);
4545
expect(screen.getByText('world')).toBeTruthy();
4646
});
47+
48+
it('renders body', () => {
49+
render(<T>hello <b>safe text</b></T>);
50+
expect(screen.queryByText('hello')).toBeInTheDocument();
51+
expect(screen.queryByText('safe text')).toBeInTheDocument();
52+
});
53+
54+
it('renders body with single tags', () => {
55+
render(<T>hello <br /> <b>safe text</b></T>);
56+
expect(screen.queryByText('hello')).toBeInTheDocument();
57+
expect(screen.queryByText('safe text')).toBeInTheDocument();
58+
});
59+
60+
it('renders nestedbody', () => {
61+
render(<T>hello <b>safe <T>text</T></b></T>);
62+
expect(screen.queryByText('hello')).toBeInTheDocument();
63+
expect(screen.queryByText('safe text')).toBeInTheDocument();
64+
});
65+
66+
it('renders body with params', () => {
67+
render(<T username="Bill">hello <b>mister {'{username}'}</b></T>);
68+
expect(screen.queryByText('hello')).toBeInTheDocument();
69+
expect(screen.queryByText('mister Bill')).toBeInTheDocument();
70+
});
4771
});

0 commit comments

Comments
 (0)