Wrap phrase for translation and update test

This commit is contained in:
Marliana Lara 2019-10-09 22:24:40 -04:00
parent 7fc4e8d20a
commit 4b83bda306
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
2 changed files with 24 additions and 7 deletions

View File

@ -63,9 +63,9 @@ function ProjectDetail({ project, i18n }) {
let createdBy = '';
if (created) {
if (summary_fields.created_by && summary_fields.created_by.username) {
createdBy = `${formatDateString(created)} ${i18n._(t`by`)} ${
summary_fields.created_by.username
}`;
createdBy = i18n._(
t`${formatDateString(created)} by ${summary_fields.created_by.username}`
);
} else {
createdBy = formatDateString(created);
}
@ -74,9 +74,11 @@ function ProjectDetail({ project, i18n }) {
let modifiedBy = '';
if (modified) {
if (summary_fields.modified_by && summary_fields.modified_by.username) {
modifiedBy = `${formatDateString(modified)} ${i18n._(t`by`)} ${
summary_fields.modified_by.username
}`;
modifiedBy = i18n._(
t`${formatDateString(modified)} by ${
summary_fields.modified_by.username
}`
);
} else {
modifiedBy = formatDateString(modified);
}

View File

@ -61,7 +61,22 @@ describe('<ProjectDetail />', () => {
});
test('should render Details', () => {
const wrapper = mountWithContexts(<ProjectDetail project={mockProject} />);
const wrapper = mountWithContexts(<ProjectDetail project={mockProject} />, {
context: {
linguiPublisher: {
i18n: {
_: key => {
if (key.values) {
Object.entries(key.values).forEach(([k, v]) => {
key.id = key.id.replace(new RegExp(`\\{${k}\\}`), v);
});
}
return key.id;
},
},
},
},
});
function assertDetail(label, value) {
expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label);
expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value);