Merge pull request #8624 from nixocio/ui_issue_8620

Hide instance group for Inventory Details if the data is not available

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-12-03 13:24:05 +00:00 committed by GitHub
commit 7faf9c6267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 18 deletions

View File

@ -80,19 +80,21 @@ function InventoryDetail({ inventory, i18n }) {
</Link>
}
/>
<Detail
fullWidth
label={i18n._(t`Instance Groups`)}
value={
<ChipGroup numChips={5} totalChips={instanceGroups.length}>
{instanceGroups.map(ig => (
<Chip key={ig.id} isReadOnly>
{ig.name}
</Chip>
))}
</ChipGroup>
}
/>
{instanceGroups && instanceGroups.length > 0 && (
<Detail
fullWidth
label={i18n._(t`Instance Groups`)}
value={
<ChipGroup numChips={5} totalChips={instanceGroups.length}>
{instanceGroups.map(ig => (
<Chip key={ig.id} isReadOnly>
{ig.name}
</Chip>
))}
</ChipGroup>
}
/>
)}
<VariablesDetail
label={i18n._(t`Variables`)}
value={inventory.variables}

View File

@ -63,11 +63,6 @@ const associatedInstanceGroups = [
name: 'Foo',
},
];
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
},
});
function expectDetailToMatch(wrapper, label, value) {
const detail = wrapper.find(`Detail[label="${label}"]`);
@ -77,6 +72,12 @@ function expectDetailToMatch(wrapper, label, value) {
describe('<InventoryDetail />', () => {
test('should render details', async () => {
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
},
});
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
@ -105,6 +106,12 @@ describe('<InventoryDetail />', () => {
});
test('should load instance groups', async () => {
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
},
});
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
@ -119,4 +126,24 @@ describe('<InventoryDetail />', () => {
expect(chip.prop('isReadOnly')).toEqual(true);
expect(chip.prop('children')).toEqual('Foo');
});
test('should not load instance groups', async () => {
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: [],
},
});
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<InventoryDetail inventory={mockInventory} />
);
});
wrapper.update();
expect(InventoriesAPI.readInstanceGroups).toHaveBeenCalledWith(
mockInventory.id
);
expect(wrapper.find(`Detail[label="Instance Groups"]`)).toHaveLength(0);
});
});