Skip to content

Commit

Permalink
Merge branch 'master' into renovate/master-@elasticcharts
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 14, 2021
2 parents 121f8cb + f0b1b90 commit 1b372ba
Show file tree
Hide file tree
Showing 38 changed files with 1,815 additions and 551 deletions.
18 changes: 8 additions & 10 deletions test/functional/apps/visualize/_data_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('should apply correct filter', async () => {
await retry.try(async () => {
await PageObjects.visChart.filterOnTableCell(1, 3);
await PageObjects.visChart.waitForVisualizationRenderingStabilized();
const data = await PageObjects.visChart.getTableVisContent();
expect(data).to.be.eql([
['png', '1,373'],
['gif', '918'],
['Other', '445'],
]);
});
await PageObjects.visChart.filterOnTableCell(1, 3);
await PageObjects.visChart.waitForVisualizationRenderingStabilized();
const data = await PageObjects.visChart.getTableVisContent();
expect(data).to.be.eql([
['png', '1,373'],
['gif', '918'],
['Other', '445'],
]);
});
});

Expand Down
3 changes: 1 addition & 2 deletions test/functional/apps/visualize/_heatmap_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const inspector = getService('inspector');
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

// FLAKY: https://github.com/elastic/kibana/issues/95642
describe.skip('heatmap chart', function indexPatternCreation() {
describe('heatmap chart', function indexPatternCreation() {
const vizName1 = 'Visualization HeatmapChart';

before(async function () {
Expand Down
5 changes: 0 additions & 5 deletions test/functional/apps/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_point_series_options'));
loadTestFile(require.resolve('./_vertical_bar_chart'));
loadTestFile(require.resolve('./_vertical_bar_chart_nontimeindex'));

// Test non-replaced vislib chart types
loadTestFile(require.resolve('./_gauge_chart'));
loadTestFile(require.resolve('./_heatmap_chart'));
loadTestFile(require.resolve('./_pie_chart'));
});

describe('', function () {
Expand Down
5 changes: 3 additions & 2 deletions test/functional/page_objects/visualize_chart_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,13 @@ export function VisualizeChartPageProvider({ getService, getPageObjects }: FtrPr
public async filterOnTableCell(columnIndex: number, rowIndex: number) {
await retry.try(async () => {
const cell = await dataGrid.getCellElement(rowIndex, columnIndex);
await cell.focus();
await cell.click();
const filterBtn = await testSubjects.findDescendant(
'tbvChartCell__filterForCellValue',
cell
);
await filterBtn.click();
await common.sleep(2000);
filterBtn.click();
});
}

Expand Down
4 changes: 1 addition & 3 deletions test/functional/page_objects/visualize_editor_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ export function VisualizeEditorPageProvider({ getService, getPageObjects }: FtrP
}

public async changeHeatmapColorNumbers(value = 6) {
const input = await testSubjects.find(`heatmapColorsNumber`);
await input.clearValueWithKeyboard();
await input.type(`${value}`);
await testSubjects.setValue('heatmapColorsNumber', `${value}`);
}

public async getBucketErrorMessage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

jest.mock('../../../../engines', () => ({
EnginesLogic: { actions: { deleteEngine: jest.fn() } },
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { mockKibanaValues, mockTelemetryActions } from '../../../../../__mocks__';

import React from 'react';

import { shallow } from 'enzyme';

import { EuiLinkTo } from '../../../../../shared/react_router_helpers';

import { navigateToEngine, renderEngineLink } from './engine_link_helpers';

describe('navigateToEngine', () => {
const { navigateToUrl } = mockKibanaValues;
const { sendAppSearchTelemetry } = mockTelemetryActions;

it('sends the user to the engine page and triggers a telemetry event', () => {
navigateToEngine('engine-a');
expect(navigateToUrl).toHaveBeenCalledWith('/engines/engine-a');
expect(sendAppSearchTelemetry).toHaveBeenCalledWith({
action: 'clicked',
metric: 'engine_table_link',
});
});
});

describe('renderEngineLink', () => {
const { sendAppSearchTelemetry } = mockTelemetryActions;

it('renders a link to the engine with telemetry', () => {
const wrapper = shallow(<div>{renderEngineLink('engine-b')}</div>);
const link = wrapper.find(EuiLinkTo);

expect(link.prop('to')).toEqual('/engines/engine-b');

link.simulate('click');
expect(sendAppSearchTelemetry).toHaveBeenCalledWith({
action: 'clicked',
metric: 'engine_table_link',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 React from 'react';

import { KibanaLogic } from '../../../../../shared/kibana';
import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
import { TelemetryLogic } from '../../../../../shared/telemetry';
import { ENGINE_PATH } from '../../../../routes';
import { generateEncodedPath } from '../../../../utils/encode_path_params';

const sendEngineTableLinkClickTelemetry = () => {
TelemetryLogic.actions.sendAppSearchTelemetry({
action: 'clicked',
metric: 'engine_table_link',
});
};

export const navigateToEngine = (engineName: string) => {
sendEngineTableLinkClickTelemetry();
KibanaLogic.values.navigateToUrl(generateEncodedPath(ENGINE_PATH, { engineName }));
};

export const renderEngineLink = (engineName: string) => (
<EuiLinkTo
to={generateEncodedPath(ENGINE_PATH, { engineName })}
onClick={sendEngineTableLinkClickTelemetry}
data-test-subj="EngineName"
>
{engineName}
</EuiLinkTo>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 { mountWithIntl, setMockValues } from '../../../../../__mocks__';
import '../../../../../__mocks__/enterprise_search_url.mock';
import './__mocks__/engines_logic.mock';

import React from 'react';

import { shallow } from 'enzyme';

import { EuiBasicTable } from '@elastic/eui';

import { EngineDetails } from '../../../engine/types';

import { EnginesTable } from './engines_table';

import { runSharedColumnsTests, runSharedPropsTests } from './test_helpers';

describe('EnginesTable', () => {
const data = [
{
name: 'test-engine',
created_at: 'Fri, 1 Jan 1970 12:00:00 +0000',
language: 'English',
isMeta: false,
document_count: 99999,
field_count: 10,
} as EngineDetails,
];
const props = {
items: data,
loading: false,
pagination: {
pageIndex: 0,
pageSize: 10,
totalItemCount: 1,
hidePerPageOptions: true,
},
onChange: () => {},
};
setMockValues({ myRole: { canManageEngines: false } });

beforeEach(() => {
jest.clearAllMocks();
});

it('renders', () => {
const wrapper = shallow(<EnginesTable {...props} />);
expect(wrapper.find(EuiBasicTable)).toHaveLength(1);
});

describe('columns', () => {
const wrapper = shallow(<EnginesTable {...props} />);
const tableContent = mountWithIntl(<EnginesTable {...props} />)
.find(EuiBasicTable)
.text();
runSharedColumnsTests(wrapper, tableContent);
});

describe('language column', () => {
it('renders language when set', () => {
const wrapper = mountWithIntl(
<EnginesTable {...props} items={[{ ...data[0], language: 'German' }]} />
);
expect(wrapper.find(EuiBasicTable).text()).toContain('German');
});

it('renders the language as Universal if no language is set', () => {
const wrapper = mountWithIntl(
<EnginesTable {...props} items={[{ ...data[0], language: null }]} />
);
expect(wrapper.find(EuiBasicTable).text()).toContain('Universal');
});
});

describe('passed props', () => {
const wrapper = shallow(<EnginesTable {...props} />);
runSharedPropsTests(wrapper);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 React from 'react';

import { useValues } from 'kea';

import { EuiBasicTable, EuiBasicTableColumn, EuiTableFieldDataColumnType } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { AppLogic } from '../../../../app_logic';
import { UNIVERSAL_LANGUAGE } from '../../../../constants';
import { EngineDetails } from '../../../engine/types';

import { renderEngineLink } from './engine_link_helpers';
import {
ACTIONS_COLUMN,
CREATED_AT_COLUMN,
DOCUMENT_COUNT_COLUMN,
FIELD_COUNT_COLUMN,
NAME_COLUMN,
} from './shared_columns';
import { EnginesTableProps } from './types';

const LANGUAGE_COLUMN: EuiTableFieldDataColumnType<EngineDetails> = {
field: 'language',
name: i18n.translate('xpack.enterpriseSearch.appSearch.enginesOverview.table.column.language', {
defaultMessage: 'Language',
}),
dataType: 'string',
render: (language: string) => language || UNIVERSAL_LANGUAGE,
};

export const EnginesTable: React.FC<EnginesTableProps> = ({
items,
loading,
noItemsMessage,
pagination,
onChange,
}) => {
const {
myRole: { canManageEngines },
} = useValues(AppLogic);

const columns: Array<EuiBasicTableColumn<EngineDetails>> = [
{
...NAME_COLUMN,
render: (name: string) => renderEngineLink(name),
},
CREATED_AT_COLUMN,
LANGUAGE_COLUMN,
DOCUMENT_COUNT_COLUMN,
FIELD_COUNT_COLUMN,
];

if (canManageEngines) {
columns.push(ACTIONS_COLUMN);
}

return (
<EuiBasicTable
items={items}
columns={columns}
loading={loading}
pagination={pagination}
onChange={onChange}
noItemsMessage={noItemsMessage}
/>
);
};
Loading

0 comments on commit 1b372ba

Please sign in to comment.