Skip to content

Commit

Permalink
fix init loading on viewer when no exception lists exist
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Jul 29, 2020
1 parent c7cd80f commit 116ab1a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,30 +221,42 @@ describe('useExceptionList', () => {

await act(async () => {
const onSuccessMock = jest.fn();
const { waitForNextUpdate } = renderHook<UseExceptionListProps, ReturnExceptionListAndItems>(
() =>
useExceptionList({
filterOptions: [],
http: mockKibanaHttpService,
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
],
matchFilters: false,
onError: onErrorMock,
onSuccess: onSuccessMock,
pagination: {
page: 1,
perPage: 20,
total: 0,
},
showDetectionsListsOnly: true,
showEndpointListsOnly: false,
})
const { result, waitForNextUpdate } = renderHook<
UseExceptionListProps,
ReturnExceptionListAndItems
>(() =>
useExceptionList({
filterOptions: [],
http: mockKibanaHttpService,
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
],
matchFilters: false,
onError: onErrorMock,
onSuccess: onSuccessMock,
pagination: {
page: 1,
perPage: 20,
total: 0,
},
showDetectionsListsOnly: false,
showEndpointListsOnly: true,
})
);
await waitForNextUpdate();
await waitForNextUpdate();

expect(spyOnfetchExceptionListsItemsByListIds).not.toHaveBeenCalledWith();
expect(spyOnfetchExceptionListsItemsByListIds).not.toHaveBeenCalled();
expect(result.current).toEqual([
false,
[],
{
page: 1,
perPage: 20,
total: 0,
},
result.current[3],
]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export const useExceptionList = ({
}
setLoading(false);
}
} else {
if (isSubscribed) {
setLoading(false);
}
}
} catch (error) {
if (isSubscribed) {
Expand Down

0 comments on commit 116ab1a

Please sign in to comment.