Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enterprise Search] Final KibanaPageTemplate cleanup #103355

Merged
merged 5 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { mockUseRouteMatch } from '../../../__mocks__/react_router';
import { mockEngineValues } from '../../__mocks__';

jest.mock('../../../shared/layout', () => ({
...jest.requireActual('../../../shared/layout'), // TODO: Remove once side nav components are gone
generateNavLink: jest.fn(({ to }) => ({ href: to })),
}));

Expand All @@ -20,9 +19,7 @@ import { shallow } from 'enzyme';

import { EuiBadge, EuiIcon } from '@elastic/eui';

import { rerender } from '../../../test_helpers';

import { useEngineNav, EngineNav } from './engine_nav';
import { useEngineNav } from './engine_nav';

describe('useEngineNav', () => {
const values = { ...mockEngineValues, myRole: {}, dataLoading: false };
Expand Down Expand Up @@ -321,182 +318,3 @@ describe('useEngineNav', () => {
});
});
});

describe('EngineNav', () => {
const values = { ...mockEngineValues, myRole: {}, dataLoading: false };

beforeEach(() => {
setMockValues(values);
});

it('does not render if async data is still loading', () => {
setMockValues({ ...values, dataLoading: true });
const wrapper = shallow(<EngineNav />);
expect(wrapper.isEmptyRender()).toBe(true);
});

it('does not render without an engine name', () => {
setMockValues({ ...values, engineName: '' });
const wrapper = shallow(<EngineNav />);
expect(wrapper.isEmptyRender()).toBe(true);
});

it('renders an engine label and badges', () => {
setMockValues({ ...values, isSampleEngine: false, isMetaEngine: false });
const wrapper = shallow(<EngineNav />);
const label = wrapper.find('[data-test-subj="EngineLabel"]').find('.eui-textTruncate');

expect(label.text()).toEqual('SOME-ENGINE');
expect(wrapper.find(EuiBadge)).toHaveLength(0);

setMockValues({ ...values, isSampleEngine: true });
rerender(wrapper);
expect(wrapper.find(EuiBadge).prop('children')).toEqual('SAMPLE ENGINE');

setMockValues({ ...values, isMetaEngine: true });
rerender(wrapper);
expect(wrapper.find(EuiBadge).prop('children')).toEqual('META ENGINE');
});

it('renders a default engine overview link', () => {
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineOverviewLink"]')).toHaveLength(1);
});

it('renders an analytics link', () => {
setMockValues({ ...values, myRole: { canViewEngineAnalytics: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineAnalyticsLink"]')).toHaveLength(1);
});

it('renders a documents link', () => {
setMockValues({ ...values, myRole: { canViewEngineDocuments: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineDocumentsLink"]')).toHaveLength(1);
});

it('renders a schema link', () => {
setMockValues({ ...values, myRole: { canViewEngineSchema: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineSchemaLink"]')).toHaveLength(1);
});

describe('schema nav icons', () => {
const myRole = { canViewEngineSchema: true };

it('renders schema errors alert icon', () => {
setMockValues({ ...values, myRole, hasSchemaErrors: true });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineNavSchemaErrors"]')).toHaveLength(1);
});

it('renders unconfirmed schema fields info icon', () => {
setMockValues({ ...values, myRole, hasUnconfirmedSchemaFields: true });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineNavSchemaUnconfirmedFields"]')).toHaveLength(1);
});

it('renders schema conflicts alert icon', () => {
setMockValues({ ...values, myRole, hasSchemaConflicts: true });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineNavSchemaConflicts"]')).toHaveLength(1);
});
});

describe('crawler link', () => {
const myRole = { canViewEngineCrawler: true };

it('renders', () => {
setMockValues({ ...values, myRole });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineCrawlerLink"]')).toHaveLength(1);
});

it('does not render for meta engines', () => {
setMockValues({ ...values, myRole, isMetaEngine: true });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineCrawlerLink"]')).toHaveLength(0);
});
});

describe('meta engine source engines link', () => {
const myRole = { canViewMetaEngineSourceEngines: true };

it('renders', () => {
setMockValues({ ...values, myRole, isMetaEngine: true });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="MetaEngineEnginesLink"]')).toHaveLength(1);
});

it('does not render for non meta engines', () => {
setMockValues({ ...values, myRole, isMetaEngine: false });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="MetaEngineEnginesLink"]')).toHaveLength(0);
});
});

it('renders a relevance tuning link', () => {
setMockValues({ ...values, myRole: { canManageEngineRelevanceTuning: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineRelevanceTuningLink"]')).toHaveLength(1);
});

describe('relevance tuning nav icons', () => {
const myRole = { canManageEngineRelevanceTuning: true };

it('renders unconfirmed schema fields info icon', () => {
const engine = { unsearchedUnconfirmedFields: true };
setMockValues({ ...values, myRole, engine });
const wrapper = shallow(<EngineNav />);
expect(
wrapper.find('[data-test-subj="EngineNavRelevanceTuningUnsearchedFields"]')
).toHaveLength(1);
});

it('renders schema conflicts alert icon', () => {
const engine = { invalidBoosts: true };
setMockValues({ ...values, myRole, engine });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineNavRelevanceTuningInvalidBoosts"]')).toHaveLength(
1
);
});

it('can render multiple icons', () => {
const engine = { invalidBoosts: true, unsearchedUnconfirmedFields: true };
setMockValues({ ...values, myRole, engine });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find(EuiIcon)).toHaveLength(2);
});
});

it('renders a synonyms link', () => {
setMockValues({ ...values, myRole: { canManageEngineSynonyms: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineSynonymsLink"]')).toHaveLength(1);
});

it('renders a curations link', () => {
setMockValues({ ...values, myRole: { canManageEngineCurations: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineCurationsLink"]')).toHaveLength(1);
});

it('renders a results settings link', () => {
setMockValues({ ...values, myRole: { canManageEngineResultSettings: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineResultSettingsLink"]')).toHaveLength(1);
});

it('renders a Search UI link', () => {
setMockValues({ ...values, myRole: { canManageEngineSearchUi: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineSearchUILink"]')).toHaveLength(1);
});

it('renders an API logs link', () => {
setMockValues({ ...values, myRole: { canViewEngineApiLogs: true } });
const wrapper = shallow(<EngineNav />);
expect(wrapper.find('[data-test-subj="EngineAPILogsLink"]')).toHaveLength(1);
});
});
Loading