mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 10:23:14 -04:00
[Enterprise Search] Added a test helper #117948
This commit is contained in:
parent
6f5faf93f0
commit
bde802fed6
36 changed files with 185 additions and 579 deletions
|
@ -5,12 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockKibanaValues, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockKibanaValues,
|
|
||||||
mockHttpValues,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
} from '../../../__mocks__/kea_logic';
|
|
||||||
|
|
||||||
jest.mock('../engine', () => ({
|
jest.mock('../engine', () => ({
|
||||||
EngineLogic: { values: { engineName: 'test-engine' } },
|
EngineLogic: { values: { engineName: 'test-engine' } },
|
||||||
|
@ -18,6 +13,8 @@ jest.mock('../engine', () => ({
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { DEFAULT_START_DATE, DEFAULT_END_DATE } from './constants';
|
import { DEFAULT_START_DATE, DEFAULT_END_DATE } from './constants';
|
||||||
|
|
||||||
import { AnalyticsLogic } from './';
|
import { AnalyticsLogic } from './';
|
||||||
|
@ -26,7 +23,6 @@ describe('AnalyticsLogic', () => {
|
||||||
const { mount } = new LogicMounter(AnalyticsLogic);
|
const { mount } = new LogicMounter(AnalyticsLogic);
|
||||||
const { history } = mockKibanaValues;
|
const { history } = mockKibanaValues;
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
dataLoading: true,
|
dataLoading: true,
|
||||||
|
@ -197,14 +193,9 @@ describe('AnalyticsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
AnalyticsLogic.actions.loadAnalyticsData();
|
AnalyticsLogic.actions.loadAnalyticsData();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -259,14 +250,9 @@ describe('AnalyticsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
AnalyticsLogic.actions.loadQueryData('some-query');
|
AnalyticsLogic.actions.loadQueryData('some-query');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,12 +17,14 @@ import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { DEFAULT_META } from '../../../shared/constants';
|
import { DEFAULT_META } from '../../../shared/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { ApiLogsLogic } from './';
|
import { ApiLogsLogic } from './';
|
||||||
|
|
||||||
describe('ApiLogsLogic', () => {
|
describe('ApiLogsLogic', () => {
|
||||||
const { mount, unmount } = new LogicMounter(ApiLogsLogic);
|
const { mount, unmount } = new LogicMounter(ApiLogsLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors, flashErrorToast } = mockFlashMessageHelpers;
|
const { flashErrorToast } = mockFlashMessageHelpers;
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
dataLoading: true,
|
dataLoading: true,
|
||||||
|
@ -176,14 +178,9 @@ describe('ApiLogsLogic', () => {
|
||||||
expect(ApiLogsLogic.actions.updateView).toHaveBeenCalledWith(MOCK_API_RESPONSE);
|
expect(ApiLogsLogic.actions.updateView).toHaveBeenCalledWith(MOCK_API_RESPONSE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles API errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
ApiLogsLogic.actions.fetchApiLogs();
|
ApiLogsLogic.actions.fetchApiLogs();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ import { Meta } from '../../../../../common/types';
|
||||||
|
|
||||||
import { DEFAULT_META } from '../../../shared/constants';
|
import { DEFAULT_META } from '../../../shared/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers/error_handling';
|
||||||
|
|
||||||
import { CrawlerDomainsLogic, CrawlerDomainsValues } from './crawler_domains_logic';
|
import { CrawlerDomainsLogic, CrawlerDomainsValues } from './crawler_domains_logic';
|
||||||
import { CrawlerDataFromServer, CrawlerDomain, CrawlerDomainFromServer } from './types';
|
import { CrawlerDataFromServer, CrawlerDomain, CrawlerDomainFromServer } from './types';
|
||||||
import { crawlerDataServerToClient } from './utils';
|
import { crawlerDataServerToClient } from './utils';
|
||||||
|
@ -193,13 +195,8 @@ describe('CrawlerDomainsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls flashApiErrors when there is an error', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
http.delete.mockReturnValue(Promise.reject('error'));
|
|
||||||
|
|
||||||
CrawlerDomainsLogic.actions.deleteDomain({ id: '1234' } as CrawlerDomain);
|
CrawlerDomainsLogic.actions.deleteDomain({ id: '1234' } as CrawlerDomain);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,8 @@ import '../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { CrawlerDomainsLogic } from './crawler_domains_logic';
|
import { CrawlerDomainsLogic } from './crawler_domains_logic';
|
||||||
import { CrawlerLogic, CrawlerValues } from './crawler_logic';
|
import { CrawlerLogic, CrawlerValues } from './crawler_logic';
|
||||||
import {
|
import {
|
||||||
|
@ -280,15 +282,8 @@ describe('CrawlerLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('on failure', () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
it('flashes an error message', async () => {
|
|
||||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
CrawlerLogic.actions.startCrawl();
|
CrawlerLogic.actions.startCrawl();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -308,16 +303,8 @@ describe('CrawlerLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('on failure', () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
it('flashes an error message', async () => {
|
|
||||||
jest.spyOn(CrawlerLogic.actions, 'fetchCrawlerData');
|
|
||||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
CrawlerLogic.actions.stopCrawl();
|
CrawlerLogic.actions.stopCrawl();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ jest.mock('./crawler_logic', () => ({
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { CrawlerLogic } from './crawler_logic';
|
import { CrawlerLogic } from './crawler_logic';
|
||||||
import { CrawlerSingleDomainLogic, CrawlerSingleDomainValues } from './crawler_single_domain_logic';
|
import { CrawlerSingleDomainLogic, CrawlerSingleDomainValues } from './crawler_single_domain_logic';
|
||||||
import { CrawlerDomain, CrawlerPolicies, CrawlerRules } from './types';
|
import { CrawlerDomain, CrawlerPolicies, CrawlerRules } from './types';
|
||||||
|
@ -35,7 +37,7 @@ const DEFAULT_VALUES: CrawlerSingleDomainValues = {
|
||||||
describe('CrawlerSingleDomainLogic', () => {
|
describe('CrawlerSingleDomainLogic', () => {
|
||||||
const { mount } = new LogicMounter(CrawlerSingleDomainLogic);
|
const { mount } = new LogicMounter(CrawlerSingleDomainLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
const { flashSuccessToast } = mockFlashMessageHelpers;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
@ -176,13 +178,8 @@ describe('CrawlerSingleDomainLogic', () => {
|
||||||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/crawler');
|
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/crawler');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls flashApiErrors when there is an error', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
http.delete.mockReturnValue(Promise.reject('error'));
|
|
||||||
|
|
||||||
CrawlerSingleDomainLogic.actions.deleteDomain({ id: '1234' } as CrawlerDomain);
|
CrawlerSingleDomainLogic.actions.deleteDomain({ id: '1234' } as CrawlerDomain);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -218,13 +215,8 @@ describe('CrawlerSingleDomainLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays any errors to the user', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
CrawlerSingleDomainLogic.actions.fetchDomainData('507f1f77bcf86cd799439011');
|
CrawlerSingleDomainLogic.actions.fetchDomainData('507f1f77bcf86cd799439011');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -272,16 +264,11 @@ describe('CrawlerSingleDomainLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays any errors to the user', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
CrawlerSingleDomainLogic.actions.submitDeduplicationUpdate(
|
CrawlerSingleDomainLogic.actions.submitDeduplicationUpdate(
|
||||||
{ id: '507f1f77bcf86cd799439011' } as CrawlerDomain,
|
{ id: '507f1f77bcf86cd799439011' } as CrawlerDomain,
|
||||||
{ fields: ['title'], enabled: true }
|
{ fields: ['title'], enabled: true }
|
||||||
);
|
);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,6 +20,7 @@ jest.mock('../../app_logic', () => ({
|
||||||
selectors: { myRole: jest.fn(() => ({})) },
|
selectors: { myRole: jest.fn(() => ({})) },
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
import { AppLogic } from '../../app_logic';
|
import { AppLogic } from '../../app_logic';
|
||||||
|
|
||||||
import { EngineTypes } from '../engine/types';
|
import { EngineTypes } from '../engine/types';
|
||||||
|
@ -31,7 +32,7 @@ import { CredentialsLogic } from './credentials_logic';
|
||||||
describe('CredentialsLogic', () => {
|
describe('CredentialsLogic', () => {
|
||||||
const { mount } = new LogicMounter(CredentialsLogic);
|
const { mount } = new LogicMounter(CredentialsLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { clearFlashMessages, flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;
|
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
activeApiToken: {
|
activeApiToken: {
|
||||||
|
@ -1059,14 +1060,9 @@ describe('CredentialsLogic', () => {
|
||||||
expect(CredentialsLogic.actions.setCredentialsData).toHaveBeenCalledWith(meta, results);
|
expect(CredentialsLogic.actions.setCredentialsData).toHaveBeenCalledWith(meta, results);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
mount();
|
mount();
|
||||||
http.get.mockReturnValue(Promise.reject('An error occured'));
|
|
||||||
|
|
||||||
CredentialsLogic.actions.fetchCredentials();
|
CredentialsLogic.actions.fetchCredentials();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1086,14 +1082,9 @@ describe('CredentialsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
mount();
|
mount();
|
||||||
http.get.mockReturnValue(Promise.reject('An error occured'));
|
|
||||||
|
|
||||||
CredentialsLogic.actions.fetchDetails();
|
CredentialsLogic.actions.fetchDetails();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1113,14 +1104,9 @@ describe('CredentialsLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalled();
|
expect(flashSuccessToast).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
mount();
|
mount();
|
||||||
http.delete.mockReturnValue(Promise.reject('An error occured'));
|
|
||||||
|
|
||||||
CredentialsLogic.actions.deleteApiKey(tokenName);
|
CredentialsLogic.actions.deleteApiKey(tokenName);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1172,14 +1158,9 @@ describe('CredentialsLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalled();
|
expect(flashSuccessToast).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
mount();
|
mount();
|
||||||
http.post.mockReturnValue(Promise.reject('An error occured'));
|
|
||||||
|
|
||||||
CredentialsLogic.actions.onApiTokenChange();
|
CredentialsLogic.actions.onApiTokenChange();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('token type data', () => {
|
describe('token type data', () => {
|
||||||
|
|
|
@ -5,17 +5,15 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockHttpValues } from '../../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
mockHttpValues,
|
|
||||||
} from '../../../../__mocks__/kea_logic';
|
|
||||||
import '../../../__mocks__/engine_logic.mock';
|
import '../../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { DEFAULT_META } from '../../../../shared/constants';
|
import { DEFAULT_META } from '../../../../shared/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../test_helpers';
|
||||||
|
|
||||||
import { SuggestionsAPIResponse, SuggestionsLogic } from './suggestions_logic';
|
import { SuggestionsAPIResponse, SuggestionsLogic } from './suggestions_logic';
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
|
@ -52,7 +50,6 @@ const MOCK_RESPONSE: SuggestionsAPIResponse = {
|
||||||
|
|
||||||
describe('SuggestionsLogic', () => {
|
describe('SuggestionsLogic', () => {
|
||||||
const { mount } = new LogicMounter(SuggestionsLogic);
|
const { mount } = new LogicMounter(SuggestionsLogic);
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -140,14 +137,9 @@ describe('SuggestionsLogic', () => {
|
||||||
expect(SuggestionsLogic.actions.onSuggestionsLoaded).toHaveBeenCalledWith(MOCK_RESPONSE);
|
expect(SuggestionsLogic.actions.onSuggestionsLoaded).toHaveBeenCalledWith(MOCK_RESPONSE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
SuggestionsLogic.actions.loadSuggestions();
|
SuggestionsLogic.actions.loadSuggestions();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,6 +15,8 @@ import '../../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../test_helpers';
|
||||||
|
|
||||||
import { CurationLogic } from './';
|
import { CurationLogic } from './';
|
||||||
|
|
||||||
describe('CurationLogic', () => {
|
describe('CurationLogic', () => {
|
||||||
|
@ -309,14 +311,8 @@ describe('CurationLogic', () => {
|
||||||
expect(CurationLogic.actions.loadCuration).toHaveBeenCalled();
|
expect(CurationLogic.actions.loadCuration).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('flashes any error messages', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount({ activeQuery: 'some query' });
|
|
||||||
|
|
||||||
CurationLogic.actions.convertToManual();
|
CurationLogic.actions.convertToManual();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -336,14 +332,9 @@ describe('CurationLogic', () => {
|
||||||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('flashes any errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
http.delete.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount({}, { curationId: 'cur-404' });
|
mount({}, { curationId: 'cur-404' });
|
||||||
|
|
||||||
CurationLogic.actions.deleteCuration();
|
CurationLogic.actions.deleteCuration();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { DEFAULT_META } from '../../../shared/constants';
|
import { DEFAULT_META } from '../../../shared/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { CurationsLogic } from './';
|
import { CurationsLogic } from './';
|
||||||
|
|
||||||
describe('CurationsLogic', () => {
|
describe('CurationsLogic', () => {
|
||||||
|
@ -130,14 +132,9 @@ describe('CurationsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
CurationsLogic.actions.loadCurations();
|
CurationsLogic.actions.loadCurations();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import '../../../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||||
import { HydratedCurationSuggestion } from '../../types';
|
import { HydratedCurationSuggestion } from '../../types';
|
||||||
|
|
||||||
import { CurationSuggestionLogic } from './curation_suggestion_logic';
|
import { CurationSuggestionLogic } from './curation_suggestion_logic';
|
||||||
|
@ -180,20 +181,6 @@ describe('CurationSuggestionLogic', () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const itHandlesErrors = (httpMethod: any, callback: () => void) => {
|
|
||||||
it('handles errors', async () => {
|
|
||||||
httpMethod.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mountLogic({
|
|
||||||
suggestion,
|
|
||||||
});
|
|
||||||
|
|
||||||
callback();
|
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
@ -271,7 +258,7 @@ describe('CurationSuggestionLogic', () => {
|
||||||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||||
});
|
});
|
||||||
|
|
||||||
itHandlesErrors(http.get, () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
CurationSuggestionLogic.actions.loadSuggestion();
|
CurationSuggestionLogic.actions.loadSuggestion();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -350,7 +337,8 @@ describe('CurationSuggestionLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
itHandlesErrors(http.put, () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
|
jest.spyOn(global, 'confirm').mockReturnValueOnce(true);
|
||||||
CurationSuggestionLogic.actions.acceptSuggestion();
|
CurationSuggestionLogic.actions.acceptSuggestion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -433,7 +421,8 @@ describe('CurationSuggestionLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
itHandlesErrors(http.put, () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
|
jest.spyOn(global, 'confirm').mockReturnValueOnce(true);
|
||||||
CurationSuggestionLogic.actions.acceptAndAutomateSuggestion();
|
CurationSuggestionLogic.actions.acceptAndAutomateSuggestion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -478,7 +467,7 @@ describe('CurationSuggestionLogic', () => {
|
||||||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||||
});
|
});
|
||||||
|
|
||||||
itHandlesErrors(http.put, () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
CurationSuggestionLogic.actions.rejectSuggestion();
|
CurationSuggestionLogic.actions.rejectSuggestion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -523,7 +512,7 @@ describe('CurationSuggestionLogic', () => {
|
||||||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||||
});
|
});
|
||||||
|
|
||||||
itHandlesErrors(http.put, () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
CurationSuggestionLogic.actions.rejectAndDisableSuggestion();
|
CurationSuggestionLogic.actions.rejectAndDisableSuggestion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ import {
|
||||||
mockHttpValues,
|
mockHttpValues,
|
||||||
} from '../../../../../../../__mocks__/kea_logic';
|
} from '../../../../../../../__mocks__/kea_logic';
|
||||||
import '../../../../../../__mocks__/engine_logic.mock';
|
import '../../../../../../__mocks__/engine_logic.mock';
|
||||||
|
import { DEFAULT_META } from '../../../../../../../shared/constants';
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../../../test_helpers';
|
||||||
|
|
||||||
// I don't know why eslint is saying this line is out of order
|
// I don't know why eslint is saying this line is out of order
|
||||||
// eslint-disable-next-line import/order
|
// eslint-disable-next-line import/order
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { DEFAULT_META } from '../../../../../../../shared/constants';
|
|
||||||
|
|
||||||
import { IgnoredQueriesLogic } from './ignored_queries_logic';
|
import { IgnoredQueriesLogic } from './ignored_queries_logic';
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
|
@ -142,13 +142,9 @@ describe('IgnoredQueriesLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
mount();
|
||||||
|
|
||||||
IgnoredQueriesLogic.actions.loadIgnoredQueries();
|
IgnoredQueriesLogic.actions.loadIgnoredQueries();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -185,13 +181,9 @@ describe('IgnoredQueriesLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalledWith(expect.any(String));
|
expect(flashSuccessToast).toHaveBeenCalledWith(expect.any(String));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
mount();
|
||||||
|
|
||||||
IgnoredQueriesLogic.actions.allowIgnoredQuery('test query');
|
IgnoredQueriesLogic.actions.allowIgnoredQuery('test query');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles inline errors', async () => {
|
it('handles inline errors', async () => {
|
||||||
|
|
|
@ -5,11 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockHttpValues } from '../../../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockHttpValues,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
} from '../../../../../__mocks__/kea_logic';
|
|
||||||
import '../../../../__mocks__/engine_logic.mock';
|
import '../../../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
jest.mock('../../curations_logic', () => ({
|
jest.mock('../../curations_logic', () => ({
|
||||||
|
@ -24,6 +20,7 @@ jest.mock('../../curations_logic', () => ({
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { CurationsLogic } from '../..';
|
import { CurationsLogic } from '../..';
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||||
import { EngineLogic } from '../../../engine';
|
import { EngineLogic } from '../../../engine';
|
||||||
|
|
||||||
import { CurationsSettingsLogic } from './curations_settings_logic';
|
import { CurationsSettingsLogic } from './curations_settings_logic';
|
||||||
|
@ -39,7 +36,6 @@ const DEFAULT_VALUES = {
|
||||||
describe('CurationsSettingsLogic', () => {
|
describe('CurationsSettingsLogic', () => {
|
||||||
const { mount } = new LogicMounter(CurationsSettingsLogic);
|
const { mount } = new LogicMounter(CurationsSettingsLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
@ -105,14 +101,8 @@ describe('CurationsSettingsLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('presents any API errors to the user', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
|
||||||
|
|
||||||
CurationsSettingsLogic.actions.loadCurationsSettings();
|
CurationsSettingsLogic.actions.loadCurationsSettings();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -223,14 +213,8 @@ describe('CurationsSettingsLogic', () => {
|
||||||
expect(CurationsLogic.actions.loadCurations).toHaveBeenCalled();
|
expect(CurationsLogic.actions.loadCurations).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('presents any API errors to the user', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
|
||||||
|
|
||||||
CurationsSettingsLogic.actions.updateCurationsSetting({});
|
CurationsSettingsLogic.actions.updateCurationsSetting({});
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,8 @@ import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { InternalSchemaType } from '../../../shared/schema/types';
|
import { InternalSchemaType } from '../../../shared/schema/types';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { DocumentDetailLogic } from './document_detail_logic';
|
import { DocumentDetailLogic } from './document_detail_logic';
|
||||||
|
|
||||||
describe('DocumentDetailLogic', () => {
|
describe('DocumentDetailLogic', () => {
|
||||||
|
@ -117,14 +119,9 @@ describe('DocumentDetailLogic', () => {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
mount();
|
mount();
|
||||||
http.delete.mockReturnValue(Promise.reject('An error occured'));
|
|
||||||
|
|
||||||
DocumentDetailLogic.actions.deleteDocument('1');
|
DocumentDetailLogic.actions.deleteDocument('1');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,11 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockHttpValues,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
} from '../../../__mocks__/kea_logic';
|
|
||||||
|
|
||||||
jest.mock('../engine', () => ({
|
jest.mock('../engine', () => ({
|
||||||
EngineLogic: { values: { engineName: 'some-engine' } },
|
EngineLogic: { values: { engineName: 'some-engine' } },
|
||||||
|
@ -17,12 +13,13 @@ jest.mock('../engine', () => ({
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { EngineOverviewLogic } from './';
|
import { EngineOverviewLogic } from './';
|
||||||
|
|
||||||
describe('EngineOverviewLogic', () => {
|
describe('EngineOverviewLogic', () => {
|
||||||
const { mount } = new LogicMounter(EngineOverviewLogic);
|
const { mount } = new LogicMounter(EngineOverviewLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
|
|
||||||
const mockEngineMetrics = {
|
const mockEngineMetrics = {
|
||||||
documentCount: 10,
|
documentCount: 10,
|
||||||
|
@ -83,14 +80,9 @@ describe('EngineOverviewLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
mount();
|
mount();
|
||||||
http.get.mockReturnValue(Promise.reject('An error occurred'));
|
|
||||||
|
|
||||||
EngineOverviewLogic.actions.loadOverviewMetrics();
|
EngineOverviewLogic.actions.loadOverviewMetrics();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occurred');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { DEFAULT_META } from '../../../shared/constants';
|
import { DEFAULT_META } from '../../../shared/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
import { EngineDetails, EngineTypes } from '../engine/types';
|
import { EngineDetails, EngineTypes } from '../engine/types';
|
||||||
|
|
||||||
import { EnginesLogic } from './';
|
import { EnginesLogic } from './';
|
||||||
|
@ -171,14 +172,9 @@ describe('EnginesLogic', () => {
|
||||||
expect(EnginesLogic.actions.onEnginesLoad).toHaveBeenCalledWith(MOCK_ENGINES_API_RESPONSE);
|
expect(EnginesLogic.actions.onEnginesLoad).toHaveBeenCalledWith(MOCK_ENGINES_API_RESPONSE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
EnginesLogic.actions.loadEngines();
|
EnginesLogic.actions.loadEngines();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -203,14 +199,9 @@ describe('EnginesLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
EnginesLogic.actions.loadMetaEngines();
|
EnginesLogic.actions.loadMetaEngines();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ import { mockEngineValues, mockEngineActions } from '../../__mocks__';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { Boost, BoostOperation, BoostType, FunctionalBoostFunction } from './types';
|
import { Boost, BoostOperation, BoostType, FunctionalBoostFunction } from './types';
|
||||||
|
|
||||||
import { RelevanceTuningLogic } from './';
|
import { RelevanceTuningLogic } from './';
|
||||||
|
@ -319,14 +321,9 @@ describe('RelevanceTuningLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
mount();
|
mount();
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
RelevanceTuningLogic.actions.initializeRelevanceTuning();
|
RelevanceTuningLogic.actions.initializeRelevanceTuning();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
mockHttpValues,
|
|
||||||
} from '../../../__mocks__/kea_logic';
|
|
||||||
import { mockEngineValues } from '../../__mocks__';
|
import { mockEngineValues } from '../../__mocks__';
|
||||||
|
|
||||||
import { omit } from 'lodash';
|
import { omit } from 'lodash';
|
||||||
|
@ -18,6 +14,8 @@ import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { Schema, SchemaConflicts, SchemaType } from '../../../shared/schema/types';
|
import { Schema, SchemaConflicts, SchemaType } from '../../../shared/schema/types';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { ServerFieldResultSettingObject } from './types';
|
import { ServerFieldResultSettingObject } from './types';
|
||||||
|
|
||||||
import { ResultSettingsLogic } from '.';
|
import { ResultSettingsLogic } from '.';
|
||||||
|
@ -508,7 +506,6 @@ describe('ResultSettingsLogic', () => {
|
||||||
|
|
||||||
describe('listeners', () => {
|
describe('listeners', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
let confirmSpy: jest.SpyInstance;
|
let confirmSpy: jest.SpyInstance;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
@ -844,14 +841,9 @@ describe('ResultSettingsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
mount();
|
mount();
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
ResultSettingsLogic.actions.initializeResultSettingsData();
|
ResultSettingsLogic.actions.initializeResultSettingsData();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -923,14 +915,9 @@ describe('ResultSettingsLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
mount();
|
mount();
|
||||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
ResultSettingsLogic.actions.saveResultSettings();
|
ResultSettingsLogic.actions.saveResultSettings();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does nothing if the user does not confirm', async () => {
|
it('does nothing if the user does not confirm', async () => {
|
||||||
|
|
|
@ -23,13 +23,15 @@ import {
|
||||||
} from '../../../shared/role_mapping/__mocks__/roles';
|
} from '../../../shared/role_mapping/__mocks__/roles';
|
||||||
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
|
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { RoleMappingsLogic } from './role_mappings_logic';
|
import { RoleMappingsLogic } from './role_mappings_logic';
|
||||||
|
|
||||||
const emptyUser = { username: '', email: '' };
|
const emptyUser = { username: '', email: '' };
|
||||||
|
|
||||||
describe('RoleMappingsLogic', () => {
|
describe('RoleMappingsLogic', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||||
const { mount } = new LogicMounter(RoleMappingsLogic);
|
const { mount } = new LogicMounter(RoleMappingsLogic);
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
attributes: [],
|
attributes: [],
|
||||||
|
@ -391,12 +393,8 @@ describe('RoleMappingsLogic', () => {
|
||||||
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
|
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
RoleMappingsLogic.actions.enableRoleBasedAccess();
|
RoleMappingsLogic.actions.enableRoleBasedAccess();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -411,12 +409,8 @@ describe('RoleMappingsLogic', () => {
|
||||||
expect(setRoleMappingsDataSpy).toHaveBeenCalledWith(mappingsServerProps);
|
expect(setRoleMappingsDataSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
RoleMappingsLogic.actions.initializeRoleMappings();
|
RoleMappingsLogic.actions.initializeRoleMappings();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resets roleMapping state', () => {
|
it('resets roleMapping state', () => {
|
||||||
|
@ -691,13 +685,9 @@ describe('RoleMappingsLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalled();
|
expect(flashSuccessToast).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
mount(mappingsServerProps);
|
mount(mappingsServerProps);
|
||||||
http.delete.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
RoleMappingsLogic.actions.handleDeleteMapping(roleMappingId);
|
RoleMappingsLogic.actions.handleDeleteMapping(roleMappingId);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,23 +5,20 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
mockHttpValues,
|
|
||||||
} from '../../../__mocks__/kea_logic';
|
|
||||||
import '../../__mocks__/engine_logic.mock';
|
import '../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { SchemaType } from '../../../shared/schema/types';
|
import { SchemaType } from '../../../shared/schema/types';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { SchemaBaseLogic } from './schema_base_logic';
|
import { SchemaBaseLogic } from './schema_base_logic';
|
||||||
|
|
||||||
describe('SchemaBaseLogic', () => {
|
describe('SchemaBaseLogic', () => {
|
||||||
const { mount } = new LogicMounter(SchemaBaseLogic);
|
const { mount } = new LogicMounter(SchemaBaseLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
|
|
||||||
const MOCK_SCHEMA = {
|
const MOCK_SCHEMA = {
|
||||||
some_text_field: SchemaType.Text,
|
some_text_field: SchemaType.Text,
|
||||||
|
@ -99,14 +96,9 @@ describe('SchemaBaseLogic', () => {
|
||||||
expect(SchemaBaseLogic.actions.onSchemaLoad).toHaveBeenCalledWith(MOCK_RESPONSE);
|
expect(SchemaBaseLogic.actions.onSchemaLoad).toHaveBeenCalledWith(MOCK_RESPONSE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
SchemaBaseLogic.actions.loadSchema();
|
SchemaBaseLogic.actions.loadSchema();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,8 @@ import { mockEngineValues } from '../../__mocks__';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { ActiveField } from './types';
|
import { ActiveField } from './types';
|
||||||
|
|
||||||
import { SearchUILogic } from './';
|
import { SearchUILogic } from './';
|
||||||
|
@ -21,7 +23,7 @@ import { SearchUILogic } from './';
|
||||||
describe('SearchUILogic', () => {
|
describe('SearchUILogic', () => {
|
||||||
const { mount } = new LogicMounter(SearchUILogic);
|
const { mount } = new LogicMounter(SearchUILogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors, setErrorMessage } = mockFlashMessageHelpers;
|
const { setErrorMessage } = mockFlashMessageHelpers;
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
dataLoading: true,
|
dataLoading: true,
|
||||||
|
@ -182,14 +184,9 @@ describe('SearchUILogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
SearchUILogic.actions.loadFieldData();
|
SearchUILogic.actions.loadFieldData();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,8 @@ import '../../__mocks__/engine_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { SYNONYMS_PAGE_META } from './constants';
|
import { SYNONYMS_PAGE_META } from './constants';
|
||||||
|
|
||||||
import { SynonymsLogic } from './';
|
import { SynonymsLogic } from './';
|
||||||
|
@ -146,14 +148,9 @@ describe('SynonymsLogic', () => {
|
||||||
expect(SynonymsLogic.actions.onSynonymsLoad).toHaveBeenCalledWith(MOCK_SYNONYMS_RESPONSE);
|
expect(SynonymsLogic.actions.onSynonymsLoad).toHaveBeenCalledWith(MOCK_SYNONYMS_RESPONSE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
mount();
|
mount();
|
||||||
|
|
||||||
SynonymsLogic.actions.loadSynonyms();
|
SynonymsLogic.actions.loadSynonyms();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,16 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { mockFlashMessageHelpers, mockHttpValues } from '../../../__mocks__/kea_logic';
|
import { mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { recursivelyFetchEngines } from './';
|
import { recursivelyFetchEngines } from './';
|
||||||
|
|
||||||
describe('recursivelyFetchEngines', () => {
|
describe('recursivelyFetchEngines', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
|
|
||||||
const MOCK_PAGE_1 = {
|
const MOCK_PAGE_1 = {
|
||||||
meta: {
|
meta: {
|
||||||
|
@ -100,12 +101,7 @@ describe('recursivelyFetchEngines', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
|
|
||||||
recursivelyFetchEngines({ endpoint: '/error', onComplete: MOCK_CALLBACK });
|
recursivelyFetchEngines({ endpoint: '/error', onComplete: MOCK_CALLBACK });
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,8 @@ import {
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { GenericEndpointInlineEditableTableLogic } from './generic_endpoint_inline_editable_table_logic';
|
import { GenericEndpointInlineEditableTableLogic } from './generic_endpoint_inline_editable_table_logic';
|
||||||
|
|
||||||
describe('GenericEndpointInlineEditableTableLogic', () => {
|
describe('GenericEndpointInlineEditableTableLogic', () => {
|
||||||
|
@ -119,14 +121,9 @@ describe('GenericEndpointInlineEditableTableLogic', () => {
|
||||||
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
const logic = mountLogic();
|
const logic = mountLogic();
|
||||||
|
|
||||||
logic.actions.addItem(item, onSuccess);
|
logic.actions.addItem(item, onSuccess);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -167,14 +164,9 @@ describe('GenericEndpointInlineEditableTableLogic', () => {
|
||||||
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
http.delete.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
const logic = mountLogic();
|
const logic = mountLogic();
|
||||||
|
|
||||||
logic.actions.deleteItem(item, onSuccess);
|
logic.actions.deleteItem(item, onSuccess);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -221,14 +213,9 @@ describe('GenericEndpointInlineEditableTableLogic', () => {
|
||||||
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles errors', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
|
||||||
const logic = mountLogic();
|
const logic = mountLogic();
|
||||||
|
|
||||||
logic.actions.updateItem(item, onSuccess);
|
logic.actions.updateItem(item, onSuccess);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||||
|
* 2.0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { mockFlashMessageHelpers } from '../__mocks__/kea_logic';
|
||||||
|
|
||||||
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
import { HttpHandler } from 'src/core/public';
|
||||||
|
|
||||||
|
export const itShowsServerErrorAsFlashMessage = (httpMethod: HttpHandler, callback: () => void) => {
|
||||||
|
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||||
|
it('shows any server errors as flash messages', async () => {
|
||||||
|
(httpMethod as jest.Mock).mockReturnValueOnce(Promise.reject('error'));
|
||||||
|
callback();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||||
|
});
|
||||||
|
};
|
|
@ -21,3 +21,4 @@ export {
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
export { expectedAsyncError } from './expected_async_error';
|
export { expectedAsyncError } from './expected_async_error';
|
||||||
|
export { itShowsServerErrorAsFlashMessage } from './error_handling';
|
||||||
|
|
|
@ -15,6 +15,8 @@ import { sourceConfigData } from '../../../../__mocks__/content_sources.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||||
|
|
||||||
jest.mock('../../../../app_logic', () => ({
|
jest.mock('../../../../app_logic', () => ({
|
||||||
AppLogic: { values: { isOrganization: true } },
|
AppLogic: { values: { isOrganization: true } },
|
||||||
}));
|
}));
|
||||||
|
@ -413,13 +415,8 @@ describe('AddSourceLogic', () => {
|
||||||
expect(setSourceConfigDataSpy).toHaveBeenCalledWith(sourceConfigData);
|
expect(setSourceConfigDataSpy).toHaveBeenCalledWith(sourceConfigData);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
AddSourceLogic.actions.getSourceConfigData('github');
|
AddSourceLogic.actions.getSourceConfigData('github');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -474,13 +471,8 @@ describe('AddSourceLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
AddSourceLogic.actions.getSourceConnectData('github', successCallback);
|
AddSourceLogic.actions.getSourceConnectData('github', successCallback);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -506,13 +498,8 @@ describe('AddSourceLogic', () => {
|
||||||
expect(setSourceConnectDataSpy).toHaveBeenCalledWith(sourceConnectData);
|
expect(setSourceConnectDataSpy).toHaveBeenCalledWith(sourceConnectData);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
AddSourceLogic.actions.getSourceReConnectData('github');
|
AddSourceLogic.actions.getSourceReConnectData('github');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -532,13 +519,8 @@ describe('AddSourceLogic', () => {
|
||||||
expect(setPreContentSourceConfigDataSpy).toHaveBeenCalledWith(config);
|
expect(setPreContentSourceConfigDataSpy).toHaveBeenCalledWith(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
AddSourceLogic.actions.getPreContentSourceConfigData();
|
AddSourceLogic.actions.getPreContentSourceConfigData();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -601,13 +583,8 @@ describe('AddSourceLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
AddSourceLogic.actions.saveSourceConfig(true);
|
AddSourceLogic.actions.saveSourceConfig(true);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ import { exampleResult } from '../../../../__mocks__/content_sources.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||||
|
|
||||||
const contentSource = { id: 'source123' };
|
const contentSource = { id: 'source123' };
|
||||||
jest.mock('../../source_logic', () => ({
|
jest.mock('../../source_logic', () => ({
|
||||||
SourceLogic: { values: { contentSource } },
|
SourceLogic: { values: { contentSource } },
|
||||||
|
@ -31,7 +33,7 @@ import { DisplaySettingsLogic, defaultSearchResultConfig } from './display_setti
|
||||||
describe('DisplaySettingsLogic', () => {
|
describe('DisplaySettingsLogic', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { navigateToUrl } = mockKibanaValues;
|
const { navigateToUrl } = mockKibanaValues;
|
||||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||||
const { mount } = new LogicMounter(DisplaySettingsLogic);
|
const { mount } = new LogicMounter(DisplaySettingsLogic);
|
||||||
|
|
||||||
const { searchResultConfig, exampleDocuments } = exampleResult;
|
const { searchResultConfig, exampleDocuments } = exampleResult;
|
||||||
|
@ -406,12 +408,8 @@ describe('DisplaySettingsLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
DisplaySettingsLogic.actions.initializeDisplaySettings();
|
DisplaySettingsLogic.actions.initializeDisplaySettings();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -434,12 +432,8 @@ describe('DisplaySettingsLogic', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
DisplaySettingsLogic.actions.setServerData();
|
DisplaySettingsLogic.actions.setServerData();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ Object.defineProperty(global.window, 'scrollTo', { value: spyScrollTo });
|
||||||
import { ADD, UPDATE } from '../../../../../shared/constants/operations';
|
import { ADD, UPDATE } from '../../../../../shared/constants/operations';
|
||||||
import { defaultErrorMessage } from '../../../../../shared/flash_messages/handle_api_errors';
|
import { defaultErrorMessage } from '../../../../../shared/flash_messages/handle_api_errors';
|
||||||
import { SchemaType } from '../../../../../shared/schema/types';
|
import { SchemaType } from '../../../../../shared/schema/types';
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||||
import { AppLogic } from '../../../../app_logic';
|
import { AppLogic } from '../../../../app_logic';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -40,8 +41,7 @@ import { SchemaLogic, dataTypeOptions } from './schema_logic';
|
||||||
|
|
||||||
describe('SchemaLogic', () => {
|
describe('SchemaLogic', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast, setErrorMessage } =
|
const { clearFlashMessages, flashSuccessToast, setErrorMessage } = mockFlashMessageHelpers;
|
||||||
mockFlashMessageHelpers;
|
|
||||||
const { mount } = new LogicMounter(SchemaLogic);
|
const { mount } = new LogicMounter(SchemaLogic);
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
|
@ -224,12 +224,8 @@ describe('SchemaLogic', () => {
|
||||||
expect(onInitializeSchemaSpy).toHaveBeenCalledWith(serverResponse);
|
expect(onInitializeSchemaSpy).toHaveBeenCalledWith(serverResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SchemaLogic.actions.initializeSchema();
|
SchemaLogic.actions.initializeSchema();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -447,12 +443,8 @@ describe('SchemaLogic', () => {
|
||||||
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
|
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SchemaLogic.actions.setServerField(schema, UPDATE);
|
SchemaLogic.actions.setServerField(schema, UPDATE);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { fullContentSources } from '../../../../__mocks__/content_sources.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
import { expectedAsyncError } from '../../../../../test_helpers';
|
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||||
|
|
||||||
jest.mock('../../source_logic', () => ({
|
jest.mock('../../source_logic', () => ({
|
||||||
SourceLogic: { actions: { setContentSource: jest.fn() } },
|
SourceLogic: { actions: { setContentSource: jest.fn() } },
|
||||||
|
@ -34,7 +34,7 @@ import {
|
||||||
|
|
||||||
describe('SynchronizationLogic', () => {
|
describe('SynchronizationLogic', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
const { flashSuccessToast } = mockFlashMessageHelpers;
|
||||||
const { navigateToUrl } = mockKibanaValues;
|
const { navigateToUrl } = mockKibanaValues;
|
||||||
const { mount } = new LogicMounter(SynchronizationLogic);
|
const { mount } = new LogicMounter(SynchronizationLogic);
|
||||||
const contentSource = fullContentSources[0];
|
const contentSource = fullContentSources[0];
|
||||||
|
@ -328,19 +328,8 @@ describe('SynchronizationLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalledWith('Source synchronization settings updated.');
|
expect(flashSuccessToast).toHaveBeenCalledWith('Source synchronization settings updated.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.patch, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.patch.mockReturnValue(promise);
|
|
||||||
SynchronizationLogic.actions.updateServerSettings(body);
|
SynchronizationLogic.actions.updateServerSettings(body);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { expectedAsyncError } from '../../../test_helpers';
|
||||||
jest.mock('../../app_logic', () => ({
|
jest.mock('../../app_logic', () => ({
|
||||||
AppLogic: { values: { isOrganization: true } },
|
AppLogic: { values: { isOrganization: true } },
|
||||||
}));
|
}));
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
import { AppLogic } from '../../app_logic';
|
import { AppLogic } from '../../app_logic';
|
||||||
|
|
||||||
import { SourceLogic } from './source_logic';
|
import { SourceLogic } from './source_logic';
|
||||||
|
@ -235,19 +236,8 @@ describe('SourceLogic', () => {
|
||||||
expect(onUpdateSummarySpy).toHaveBeenCalledWith(contentSource.summary);
|
expect(onUpdateSummarySpy).toHaveBeenCalledWith(contentSource.summary);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.get.mockReturnValue(promise);
|
|
||||||
SourceLogic.actions.initializeFederatedSummary(contentSource.id);
|
SourceLogic.actions.initializeFederatedSummary(contentSource.id);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -295,20 +285,8 @@ describe('SourceLogic', () => {
|
||||||
expect(actions.setSearchResults).toHaveBeenCalledWith(searchServerResponse);
|
expect(actions.setSearchResults).toHaveBeenCalledWith(searchServerResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
const error = {
|
searchContentSourceDocuments({ sourceId: contentSource.id }, mockBreakpoint);
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.post.mockReturnValue(promise);
|
|
||||||
|
|
||||||
await searchContentSourceDocuments({ sourceId: contentSource.id }, mockBreakpoint);
|
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -367,19 +345,8 @@ describe('SourceLogic', () => {
|
||||||
expect(onUpdateSourceNameSpy).toHaveBeenCalledWith(contentSource.name);
|
expect(onUpdateSourceNameSpy).toHaveBeenCalledWith(contentSource.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.patch, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.patch.mockReturnValue(promise);
|
|
||||||
SourceLogic.actions.updateContentSource(contentSource.id, contentSource);
|
SourceLogic.actions.updateContentSource(contentSource.id, contentSource);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -413,19 +380,8 @@ describe('SourceLogic', () => {
|
||||||
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
|
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.delete.mockReturnValue(promise);
|
|
||||||
SourceLogic.actions.removeContentSource(contentSource.id);
|
SourceLogic.actions.removeContentSource(contentSource.id);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -441,19 +397,8 @@ describe('SourceLogic', () => {
|
||||||
expect(initializeSourceSpy).toHaveBeenCalledWith(contentSource.id);
|
expect(initializeSourceSpy).toHaveBeenCalledWith(contentSource.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.post.mockReturnValue(promise);
|
|
||||||
SourceLogic.actions.initializeSourceSynchronization(contentSource.id);
|
SourceLogic.actions.initializeSourceSynchronization(contentSource.id);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,10 @@ import {
|
||||||
} from '../../../__mocks__/kea_logic';
|
} from '../../../__mocks__/kea_logic';
|
||||||
import { configuredSources, contentSources } from '../../__mocks__/content_sources.mock';
|
import { configuredSources, contentSources } from '../../__mocks__/content_sources.mock';
|
||||||
|
|
||||||
import { expectedAsyncError } from '../../../test_helpers';
|
|
||||||
|
|
||||||
jest.mock('../../app_logic', () => ({
|
jest.mock('../../app_logic', () => ({
|
||||||
AppLogic: { values: { isOrganization: true } },
|
AppLogic: { values: { isOrganization: true } },
|
||||||
}));
|
}));
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
import { AppLogic } from '../../app_logic';
|
import { AppLogic } from '../../app_logic';
|
||||||
|
|
||||||
import { SourcesLogic, fetchSourceStatuses, POLLING_INTERVAL } from './sources_logic';
|
import { SourcesLogic, fetchSourceStatuses, POLLING_INTERVAL } from './sources_logic';
|
||||||
|
@ -185,19 +184,8 @@ describe('SourcesLogic', () => {
|
||||||
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/account/sources');
|
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/account/sources');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.get.mockReturnValue(promise);
|
|
||||||
SourcesLogic.actions.initializeSources();
|
SourcesLogic.actions.initializeSources();
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles early logic unmount gracefully in org context', async () => {
|
it('handles early logic unmount gracefully in org context', async () => {
|
||||||
|
@ -259,19 +247,8 @@ describe('SourcesLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.put.mockReturnValue(promise);
|
|
||||||
SourcesLogic.actions.setSourceSearchability(id, true);
|
SourcesLogic.actions.setSourceSearchability(id, true);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -367,19 +344,8 @@ describe('SourcesLogic', () => {
|
||||||
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/account/sources/status');
|
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/account/sources/status');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
error: 'this is an error',
|
|
||||||
status: 400,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const promise = Promise.reject(error);
|
|
||||||
http.get.mockReturnValue(promise);
|
|
||||||
fetchSourceStatuses(true, mockBreakpoint);
|
fetchSourceStatuses(true, mockBreakpoint);
|
||||||
await expectedAsyncError(promise);
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { mockGroupValues } from './__mocks__/group_logic.mock';
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
import { GROUPS_PATH } from '../../routes';
|
import { GROUPS_PATH } from '../../routes';
|
||||||
|
|
||||||
import { GroupLogic } from './group_logic';
|
import { GroupLogic } from './group_logic';
|
||||||
|
@ -24,8 +25,7 @@ describe('GroupLogic', () => {
|
||||||
const { mount } = new LogicMounter(GroupLogic);
|
const { mount } = new LogicMounter(GroupLogic);
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { navigateToUrl } = mockKibanaValues;
|
const { navigateToUrl } = mockKibanaValues;
|
||||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast, setQueuedErrorMessage } =
|
const { clearFlashMessages, flashSuccessToast, setQueuedErrorMessage } = mockFlashMessageHelpers;
|
||||||
mockFlashMessageHelpers;
|
|
||||||
|
|
||||||
const group = groups[0];
|
const group = groups[0];
|
||||||
const sourceIds = ['123', '124'];
|
const sourceIds = ['123', '124'];
|
||||||
|
@ -222,13 +222,8 @@ describe('GroupLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalledWith('Group "group" was successfully deleted.');
|
expect(flashSuccessToast).toHaveBeenCalledWith('Group "group" was successfully deleted.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
http.delete.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupLogic.actions.deleteGroup();
|
GroupLogic.actions.deleteGroup();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,13 +248,8 @@ describe('GroupLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupLogic.actions.updateGroupName();
|
GroupLogic.actions.updateGroupName();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -284,13 +274,8 @@ describe('GroupLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupLogic.actions.saveGroupSources();
|
GroupLogic.actions.saveGroupSources();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -322,13 +307,8 @@ describe('GroupLogic', () => {
|
||||||
expect(onGroupPrioritiesChangedSpy).toHaveBeenCalledWith(group);
|
expect(onGroupPrioritiesChangedSpy).toHaveBeenCalledWith(group);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupLogic.actions.saveGroupSourcePrioritization();
|
GroupLogic.actions.saveGroupSourcePrioritization();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ import { nextTick } from '@kbn/test/jest';
|
||||||
import { JSON_HEADER as headers } from '../../../../../common/constants';
|
import { JSON_HEADER as headers } from '../../../../../common/constants';
|
||||||
import { DEFAULT_META } from '../../../shared/constants';
|
import { DEFAULT_META } from '../../../shared/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { GroupsLogic } from './groups_logic';
|
import { GroupsLogic } from './groups_logic';
|
||||||
|
|
||||||
// We need to mock out the debounced functionality
|
// We need to mock out the debounced functionality
|
||||||
|
@ -227,13 +229,8 @@ describe('GroupsLogic', () => {
|
||||||
expect(onInitializeGroupsSpy).toHaveBeenCalledWith(groupsResponse);
|
expect(onInitializeGroupsSpy).toHaveBeenCalledWith(groupsResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupsLogic.actions.initializeGroups();
|
GroupsLogic.actions.initializeGroups();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -310,13 +307,8 @@ describe('GroupsLogic', () => {
|
||||||
expect(setGroupUsersSpy).toHaveBeenCalledWith(users);
|
expect(setGroupUsersSpy).toHaveBeenCalledWith(users);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupsLogic.actions.fetchGroupUsers('123');
|
GroupsLogic.actions.fetchGroupUsers('123');
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -336,13 +328,8 @@ describe('GroupsLogic', () => {
|
||||||
expect(setNewGroupSpy).toHaveBeenCalledWith(groups[0]);
|
expect(setNewGroupSpy).toHaveBeenCalledWith(groups[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
GroupsLogic.actions.saveNewGroup();
|
GroupsLogic.actions.saveNewGroup();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ import {
|
||||||
} from '../../../shared/role_mapping/__mocks__/roles';
|
} from '../../../shared/role_mapping/__mocks__/roles';
|
||||||
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
|
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { RoleMappingsLogic } from './role_mappings_logic';
|
import { RoleMappingsLogic } from './role_mappings_logic';
|
||||||
|
|
||||||
const emptyUser = { username: '', email: '' };
|
const emptyUser = { username: '', email: '' };
|
||||||
|
@ -349,12 +351,8 @@ describe('RoleMappingsLogic', () => {
|
||||||
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
|
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
RoleMappingsLogic.actions.enableRoleBasedAccess();
|
RoleMappingsLogic.actions.enableRoleBasedAccess();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -369,12 +367,8 @@ describe('RoleMappingsLogic', () => {
|
||||||
expect(setRoleMappingsDataSpy).toHaveBeenCalledWith(mappingsServerProps);
|
expect(setRoleMappingsDataSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
RoleMappingsLogic.actions.initializeRoleMappings();
|
RoleMappingsLogic.actions.initializeRoleMappings();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resets roleMapping state', () => {
|
it('resets roleMapping state', () => {
|
||||||
|
|
|
@ -5,19 +5,16 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||||
LogicMounter,
|
|
||||||
mockHttpValues,
|
|
||||||
mockFlashMessageHelpers,
|
|
||||||
} from '../../../__mocks__/kea_logic';
|
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
|
|
||||||
import { SecurityLogic } from './security_logic';
|
import { SecurityLogic } from './security_logic';
|
||||||
|
|
||||||
describe('SecurityLogic', () => {
|
describe('SecurityLogic', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
|
||||||
const { mount } = new LogicMounter(SecurityLogic);
|
const { mount } = new LogicMounter(SecurityLogic);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -124,15 +121,8 @@ describe('SecurityLogic', () => {
|
||||||
expect(setServerPropsSpy).toHaveBeenCalledWith(serverProps);
|
expect(setServerPropsSpy).toHaveBeenCalledWith(serverProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
SecurityLogic.actions.initializeSourceRestrictions();
|
SecurityLogic.actions.initializeSourceRestrictions();
|
||||||
try {
|
|
||||||
await nextTick();
|
|
||||||
} catch {
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -150,15 +140,8 @@ describe('SecurityLogic', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.patch, () => {
|
||||||
http.patch.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
|
|
||||||
SecurityLogic.actions.saveSourceRestrictions();
|
SecurityLogic.actions.saveSourceRestrictions();
|
||||||
try {
|
|
||||||
await nextTick();
|
|
||||||
} catch {
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { configuredSources, oauthApplication } from '../../__mocks__/content_sou
|
||||||
|
|
||||||
import { nextTick } from '@kbn/test/jest';
|
import { nextTick } from '@kbn/test/jest';
|
||||||
|
|
||||||
|
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||||
import { ORG_UPDATED_MESSAGE, OAUTH_APP_UPDATED_MESSAGE } from '../../constants';
|
import { ORG_UPDATED_MESSAGE, OAUTH_APP_UPDATED_MESSAGE } from '../../constants';
|
||||||
|
|
||||||
import { SettingsLogic } from './settings_logic';
|
import { SettingsLogic } from './settings_logic';
|
||||||
|
@ -22,7 +23,7 @@ import { SettingsLogic } from './settings_logic';
|
||||||
describe('SettingsLogic', () => {
|
describe('SettingsLogic', () => {
|
||||||
const { http } = mockHttpValues;
|
const { http } = mockHttpValues;
|
||||||
const { navigateToUrl } = mockKibanaValues;
|
const { navigateToUrl } = mockKibanaValues;
|
||||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||||
const { mount } = new LogicMounter(SettingsLogic);
|
const { mount } = new LogicMounter(SettingsLogic);
|
||||||
const ORG_NAME = 'myOrg';
|
const ORG_NAME = 'myOrg';
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
|
@ -127,12 +128,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(setServerPropsSpy).toHaveBeenCalledWith(configuredSources);
|
expect(setServerPropsSpy).toHaveBeenCalledWith(configuredSources);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.initializeSettings();
|
SettingsLogic.actions.initializeSettings();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -150,12 +147,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(onInitializeConnectorsSpy).toHaveBeenCalledWith(serverProps);
|
expect(onInitializeConnectorsSpy).toHaveBeenCalledWith(serverProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.initializeConnectors();
|
SettingsLogic.actions.initializeConnectors();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -176,12 +169,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(setUpdatedNameSpy).toHaveBeenCalledWith({ organizationName: NAME });
|
expect(setUpdatedNameSpy).toHaveBeenCalledWith({ organizationName: NAME });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.updateOrgName();
|
SettingsLogic.actions.updateOrgName();
|
||||||
|
|
||||||
await nextTick();
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -205,12 +194,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(setIconSpy).toHaveBeenCalledWith(ICON);
|
expect(setIconSpy).toHaveBeenCalledWith(ICON);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.updateOrgIcon();
|
SettingsLogic.actions.updateOrgIcon();
|
||||||
|
|
||||||
await nextTick();
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -234,12 +219,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(setLogoSpy).toHaveBeenCalledWith(LOGO);
|
expect(setLogoSpy).toHaveBeenCalledWith(LOGO);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.updateOrgLogo();
|
SettingsLogic.actions.updateOrgLogo();
|
||||||
|
|
||||||
await nextTick();
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -291,12 +272,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalledWith(OAUTH_APP_UPDATED_MESSAGE);
|
expect(flashSuccessToast).toHaveBeenCalledWith(OAUTH_APP_UPDATED_MESSAGE);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.updateOauthApplication();
|
SettingsLogic.actions.updateOauthApplication();
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -313,12 +290,8 @@ describe('SettingsLogic', () => {
|
||||||
expect(flashSuccessToast).toHaveBeenCalled();
|
expect(flashSuccessToast).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles error', async () => {
|
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||||
http.delete.mockReturnValue(Promise.reject('this is an error'));
|
|
||||||
SettingsLogic.actions.deleteSourceConfig(SERVICE_TYPE, NAME);
|
SettingsLogic.actions.deleteSourceConfig(SERVICE_TYPE, NAME);
|
||||||
await nextTick();
|
|
||||||
|
|
||||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue