Translate contents of Hosts Automated field as a single string (#12480)

* Translate contents of Hosts Automated field as a single string

* Adds unit test case for hiding Hosts automated detail when no value is present
This commit is contained in:
Michael Abashian
2022-07-12 15:24:33 -04:00
committed by GitHub
parent bd93ac7edd
commit 8031b3d402
2 changed files with 37 additions and 13 deletions

View File

@@ -35,6 +35,13 @@ function SubscriptionDetail() {
}, },
]; ];
const { automated_instances: automatedInstancesCount, automated_since } =
license_info;
const automatedInstancesSinceDateTime = automated_since
? formatDateString(new Date(automated_since * 1000).toISOString())
: null;
return ( return (
<> <>
<RoutedTabs tabsArray={tabsArray} /> <RoutedTabs tabsArray={tabsArray} />
@@ -127,19 +134,23 @@ function SubscriptionDetail() {
label={t`Hosts imported`} label={t`Hosts imported`}
value={license_info.current_instances} value={license_info.current_instances}
/> />
<Detail {typeof automatedInstancesCount !== 'undefined' &&
dataCy="subscription-hosts-automated" automatedInstancesCount !== null && (
label={t`Hosts automated`} <Detail
value={ dataCy="subscription-hosts-automated"
<> label={t`Hosts automated`}
{license_info.automated_instances} <Trans>since</Trans>{' '} value={
{license_info.automated_since && automated_since ? (
formatDateString( <Trans>
new Date(license_info.automated_since * 1000).toISOString() {automatedInstancesCount} since{' '}
)} {automatedInstancesSinceDateTime}
</> </Trans>
} ) : (
/> automatedInstancesCount
)
}
/>
)}
<Detail <Detail
dataCy="subscription-hosts-remaining" dataCy="subscription-hosts-remaining"
label={t`Hosts remaining`} label={t`Hosts remaining`}

View File

@@ -82,4 +82,17 @@ describe('<SubscriptionDetail />', () => {
expect(wrapper.find('Button[aria-label="edit"]').length).toBe(1); expect(wrapper.find('Button[aria-label="edit"]').length).toBe(1);
}); });
test('should not render Hosts Automated Detail if license_info.automated_instances is undefined', () => {
wrapper = mountWithContexts(<SubscriptionDetail />, {
context: {
config: {
...config,
license_info: { ...config.license_info, automated_instances: null },
},
},
});
expect(wrapper.find(`Detail[label="Hosts automated"]`).length).toBe(0);
});
}); });