import {render, screen} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';
import {tct} from 'sentry/locale';
describe('locale.gettextComponentTemplate', () => {
it('should not wrap translated text in span', () => {
// spaces are removed because pretter keeps trying to remove them in the snapshot
expect(
tct('hello[one]two[three:3]', {
one: ' one',
three:
,
})
).toMatchInlineSnapshot(`
hello
one
two
3
`);
});
it('should render two component templates inside the same parent', () => {
render(
{tct('1st: [one]', {
one: 'one',
})}
{tct('2nd: [two]', {
two: 'two',
})}
);
expect(
screen.getByText(textWithMarkupMatcher('1st: one2nd: two'))
).toBeInTheDocument();
});
it('should render multiple groups with the same name', () => {
const RenderChildren = ({children}: {children?: React.ReactNode}) => children;
render(
{tct('[render:one] [render:two] [render:three]', {
render: ,
})}
);
expect(screen.getByText(textWithMarkupMatcher('one two three'))).toBeInTheDocument();
});
it('should render multiple groups with the same name in an HTML tag', () => {
const {container} = render(
{tct('[render:one] [render:two] [render:three]', {
render: ,
})}
);
expect(screen.getByText(textWithMarkupMatcher('one two three'))).toBeInTheDocument();
expect(container.innerHTML).toEqual('one two three
');
});
it('should render nested goups', () => {
const {container} = render(
{tct('[bold:text with [link:another] group]', {
bold:
,
link:
,
})}
);
expect(
screen.getByText(textWithMarkupMatcher('text with another group'))
).toBeInTheDocument();
expect(container.innerHTML).toEqual(
''
);
});
});