resolve cyclical group association

This commit is contained in:
Alex Corey
2020-11-05 10:43:35 -05:00
parent 8ff2c5b576
commit 944c32da24
4 changed files with 20 additions and 6 deletions

View File

@@ -48,6 +48,12 @@ class Groups extends Base {
id: childId, id: childId,
}); });
} }
readPotentialGroups(id, params) {
return this.http.get(`${this.baseUrl}${id}/potential_children/`, {
params,
});
}
} }
export default Groups; export default Groups;

View File

@@ -48,7 +48,7 @@ function InventoryGroup({ i18n, setBreadcrumb, inventory }) {
{ {
name: ( name: (
<> <>
<CaretLeftIcon /> <CaretLeftIcon aria-label={i18n._(t`Back to Groups`)} />
{i18n._(t`Back to Groups`)} {i18n._(t`Back to Groups`)}
</> </>
), ),

View File

@@ -73,13 +73,14 @@ function InventoryRelatedGroupList({ i18n }) {
const fetchGroupsToAssociate = useCallback( const fetchGroupsToAssociate = useCallback(
params => { params => {
return InventoriesAPI.readGroups( return GroupsAPI.readPotentialGroups(
inventoryId, groupId,
mergeParams(params, { not__id: inventoryId, not__parents: inventoryId }) mergeParams(params, { not__id: groupId, not__parents: groupId })
); );
}, },
[inventoryId] [groupId]
); );
const associateGroup = useCallback( const associateGroup = useCallback(
async selectedGroups => { async selectedGroups => {
try { try {

View File

@@ -189,7 +189,7 @@ describe('<InventoryRelatedGroupList />', () => {
}); });
test('should associate existing group', async () => { test('should associate existing group', async () => {
InventoriesAPI.readGroups.mockResolvedValue({ GroupsAPI.readPotentialGroups.mockResolvedValue({
data: { count: mockGroups.length, results: mockGroups }, data: { count: mockGroups.length, results: mockGroups },
}); });
await act(async () => { await act(async () => {
@@ -204,6 +204,13 @@ describe('<InventoryRelatedGroupList />', () => {
.find('DropdownItem[aria-label="Add existing group"]') .find('DropdownItem[aria-label="Add existing group"]')
.prop('onClick')() .prop('onClick')()
); );
expect(GroupsAPI.readPotentialGroups).toBeCalledWith(2, {
not__id: 2,
not__parents: 2,
order_by: 'name',
page: 1,
page_size: 5,
});
wrapper.update(); wrapper.update();
act(() => act(() =>
wrapper.find('CheckboxListItem[name="foo"]').prop('onSelect')({ id: 1 }) wrapper.find('CheckboxListItem[name="foo"]').prop('onSelect')({ id: 1 })