From 06de36de16c8713ec34d5738ebea88a581e07910 Mon Sep 17 00:00:00 2001 From: Melissa Date: Wed, 14 Sep 2022 18:57:23 -0600 Subject: [PATCH] fix functional test and remove commented code --- .../spike_analysis_table_groups.tsx | 28 ++++------- .../apps/aiops/explain_log_rate_spikes.ts | 7 +-- .../test/functional/apps/aiops/test_data.ts | 1 + x-pack/test/functional/apps/aiops/types.ts | 1 + ...n_log_rate_spikes_analysis_groups_table.ts | 50 +++++++++++++++++++ .../test/functional/services/aiops/index.ts | 4 ++ 6 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 x-pack/test/functional/services/aiops/explain_log_rate_spikes_analysis_groups_table.ts diff --git a/x-pack/plugins/aiops/public/components/spike_analysis_table/spike_analysis_table_groups.tsx b/x-pack/plugins/aiops/public/components/spike_analysis_table/spike_analysis_table_groups.tsx index 3d733ec4a691..78ec29862b62 100644 --- a/x-pack/plugins/aiops/public/components/spike_analysis_table/spike_analysis_table_groups.tsx +++ b/x-pack/plugins/aiops/public/components/spike_analysis_table/spike_analysis_table_groups.tsx @@ -123,7 +123,7 @@ export const SpikeAnalysisGroupsTable: FC = ({ ), }, { - 'data-test-subj': 'aiopsSpikeAnalysisTableColumnGroup', + 'data-test-subj': 'aiopsSpikeAnalysisGroupsTableColumnGroup', field: 'group', name: i18n.translate( 'xpack.aiops.correlations.failedTransactions.correlationsTable.groupLabel', @@ -155,7 +155,7 @@ export const SpikeAnalysisGroupsTable: FC = ({ <> +{Object.keys(repeatedValues).length} more @@ -166,26 +166,11 @@ export const SpikeAnalysisGroupsTable: FC = ({ } return valuesBadges; }, - // render: (_, { group }) => ( - // - // {JSON.stringify(group, null, 2)} - // - // ), sortable: false, textOnly: true, }, { - 'data-test-subj': 'aiopsSpikeAnalysisTableColumnDocCount', + 'data-test-subj': 'aiopsSpikeAnalysisGroupsTableColumnDocCount', field: 'docCount', name: i18n.translate('xpack.aiops.correlations.correlationsTable.docCountLabel', { defaultMessage: 'Doc count', @@ -238,7 +223,7 @@ export const SpikeAnalysisGroupsTable: FC = ({ return ( = ({ pagination={pagination} loading={false} sorting={sorting as EuiTableSortingType} + rowProps={(group) => { + return { + 'data-test-subj': `aiopsSpikeAnalysisGroupsTableRow row-${group.id}`, + }; + }} /> ); }; diff --git a/x-pack/test/functional/apps/aiops/explain_log_rate_spikes.ts b/x-pack/test/functional/apps/aiops/explain_log_rate_spikes.ts index 39c0d1500945..77a7598215c6 100644 --- a/x-pack/test/functional/apps/aiops/explain_log_rate_spikes.ts +++ b/x-pack/test/functional/apps/aiops/explain_log_rate_spikes.ts @@ -114,11 +114,12 @@ export default function ({ getPageObject, getService }: FtrProviderContext) { await aiops.explainLogRateSpikes.clickRerunAnalysisButton(true); await aiops.explainLogRateSpikes.assertProgressTitle('Progress: 100% — Done.'); - await aiops.explainLogRateSpikesAnalysisTable.assertSpikeAnalysisTableExists(); + await aiops.explainLogRateSpikesAnalysisGroupsTable.assertSpikeAnalysisTableExists(); - const analysisTable = await aiops.explainLogRateSpikesAnalysisTable.parseAnalysisTable(); + const analysisGroupsTable = + await aiops.explainLogRateSpikesAnalysisGroupsTable.parseAnalysisTable(); - expect(analysisTable).to.be.eql(testData.expected.analysisTable); + expect(analysisGroupsTable).to.be.eql(testData.expected.analysisGroupsTable); }); } diff --git a/x-pack/test/functional/apps/aiops/test_data.ts b/x-pack/test/functional/apps/aiops/test_data.ts index 635e2a768c85..332e9ac91121 100644 --- a/x-pack/test/functional/apps/aiops/test_data.ts +++ b/x-pack/test/functional/apps/aiops/test_data.ts @@ -14,6 +14,7 @@ export const farequoteDataViewTestData: TestData = { brushTargetTimestamp: 1455033600000, expected: { totalDocCountFormatted: '86,274', + analysisGroupsTable: [{ group: 'airline: AAL', docCount: '297' }], analysisTable: [ { fieldName: 'airline', diff --git a/x-pack/test/functional/apps/aiops/types.ts b/x-pack/test/functional/apps/aiops/types.ts index 761ddcc5ad43..5c88fac3595b 100644 --- a/x-pack/test/functional/apps/aiops/types.ts +++ b/x-pack/test/functional/apps/aiops/types.ts @@ -13,6 +13,7 @@ export interface TestData { brushTargetTimestamp: number; expected: { totalDocCountFormatted: string; + analysisGroupsTable: Array<{ group: string; docCount: string }>; analysisTable: Array<{ fieldName: string; fieldValue: string; diff --git a/x-pack/test/functional/services/aiops/explain_log_rate_spikes_analysis_groups_table.ts b/x-pack/test/functional/services/aiops/explain_log_rate_spikes_analysis_groups_table.ts new file mode 100644 index 000000000000..b79fc0bb2802 --- /dev/null +++ b/x-pack/test/functional/services/aiops/explain_log_rate_spikes_analysis_groups_table.ts @@ -0,0 +1,50 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export function ExplainLogRateSpikesAnalysisGroupsTableProvider({ + getService, +}: FtrProviderContext) { + const testSubjects = getService('testSubjects'); + + return new (class AnalysisTable { + public async assertSpikeAnalysisTableExists() { + await testSubjects.existOrFail(`aiopsSpikeAnalysisGroupsTable`); + } + + public async parseAnalysisTable() { + const table = await testSubjects.find('~aiopsSpikeAnalysisGroupsTable'); + const $ = await table.parseDomContent(); + const rows = []; + + for (const tr of $.findTestSubjects('~aiopsSpikeAnalysisGroupsTableRow').toArray()) { + const $tr = $(tr); + + const rowObject: { + group: any; + docCount: number; + } = { + group: $tr + .findTestSubject('aiopsSpikeAnalysisGroupsTableColumnGroup') + .find('.euiTableCellContent') + .text() + .trim(), + docCount: $tr + .findTestSubject('aiopsSpikeAnalysisGroupsTableColumnDocCount') + .find('.euiTableCellContent') + .text() + .trim(), + }; + + rows.push(rowObject); + } + + return rows; + } + })(); +} diff --git a/x-pack/test/functional/services/aiops/index.ts b/x-pack/test/functional/services/aiops/index.ts index adb6789919c5..9fca53856a85 100644 --- a/x-pack/test/functional/services/aiops/index.ts +++ b/x-pack/test/functional/services/aiops/index.ts @@ -9,13 +9,17 @@ import type { FtrProviderContext } from '../../ftr_provider_context'; import { ExplainLogRateSpikesProvider } from './explain_log_rate_spikes'; import { ExplainLogRateSpikesAnalysisTableProvider } from './explain_log_rate_spikes_analysis_table'; +import { ExplainLogRateSpikesAnalysisGroupsTableProvider } from './explain_log_rate_spikes_analysis_groups_table'; export function AiopsProvider(context: FtrProviderContext) { const explainLogRateSpikes = ExplainLogRateSpikesProvider(context); const explainLogRateSpikesAnalysisTable = ExplainLogRateSpikesAnalysisTableProvider(context); + const explainLogRateSpikesAnalysisGroupsTable = + ExplainLogRateSpikesAnalysisGroupsTableProvider(context); return { explainLogRateSpikes, explainLogRateSpikesAnalysisTable, + explainLogRateSpikesAnalysisGroupsTable, }; }