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
2 changed files with 47 additions and 18 deletions

View File

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

View File

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