Skip to content

Commit

Permalink
Change error to warning toast (#123777)
Browse files Browse the repository at this point in the history
* Change error to warning toast

* Add test for addWarning

Co-authored-by: Kristof-Pierre Cummings <[email protected]>
  • Loading branch information
jamster10 and Kristof-Pierre Cummings authored Jan 27, 2022
1 parent 3e7611b commit 11537ea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ jest.mock('../../utils/route/use_route_spy', () => ({

const mockSearch = jest.fn();

const mockAddWarning = jest.fn();
jest.mock('../../lib/kibana', () => ({
useToasts: () => ({
addError: jest.fn(),
addSuccess: jest.fn(),
addWarning: jest.fn(),
addWarning: mockAddWarning,
}),
useKibana: () => ({
services: {
Expand Down Expand Up @@ -195,6 +196,38 @@ describe('Sourcerer Hooks', () => {
});
});
});

it('calls addWarning if defaultDataView has an error', async () => {
store = createStore(
{
...mockGlobalState,
sourcerer: {
...mockGlobalState.sourcerer,
signalIndexName: null,
defaultDataView: {
...mockGlobalState.sourcerer.defaultDataView,
error: true,
},
},
},
SUB_PLUGINS_REDUCER,
kibanaObservable,
storage
);
await act(async () => {
renderHook<string, void>(() => useInitSourcerer(), {
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
});

await waitFor(() => {
expect(mockAddWarning).toHaveBeenNthCalledWith(1, {
text: 'Users with write permission need to access the Elastic Security app to initialize the app source data.',
title: 'Write role required to generate data',
});
});
});
});

it('handles detections page', async () => {
await act(async () => {
mockUseUserInfo.mockImplementation(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ export const useInitSourcerer = (
(state) => getDataViewsSelector(state)
);

const { addError } = useAppToasts();
const { addError, addWarning } = useAppToasts();

useEffect(() => {
if (defaultDataView.error != null) {
addError(defaultDataView.error, {
addWarning({
title: i18n.translate('xpack.securitySolution.sourcerer.permissions.title', {
defaultMessage: 'Write role required to generate data',
}),
toastMessage: i18n.translate('xpack.securitySolution.sourcerer.permissions.toastMessage', {
text: i18n.translate('xpack.securitySolution.sourcerer.permissions.toastMessage', {
defaultMessage:
'Users with write permission need to access the Elastic Security app to initialize the app source data.',
}),
});
}
}, [addError, defaultDataView.error]);
}, [addWarning, defaultDataView.error]);

const getTimelineSelector = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []);
const activeTimeline = useDeepEqualSelector((state) =>
Expand Down

0 comments on commit 11537ea

Please sign in to comment.