|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import { FtrProviderContext } from '../../../ftr_provider_context'; |
| 8 | +import { ML_JOB_FIELD_TYPES } from '../../../../../legacy/plugins/ml/common/constants/field_types'; |
| 9 | +import { FieldVisConfig } from '../../../../../legacy/plugins/ml/public/application/datavisualizer/index_based/common'; |
| 10 | + |
| 11 | +function getFieldTypes(cards: FieldVisConfig[]) { |
| 12 | + const fieldTypes: ML_JOB_FIELD_TYPES[] = []; |
| 13 | + cards.forEach(card => { |
| 14 | + const fieldType = card.type; |
| 15 | + if (fieldTypes.includes(fieldType) === false) { |
| 16 | + fieldTypes.push(fieldType); |
| 17 | + } |
| 18 | + }); |
| 19 | + |
| 20 | + return fieldTypes.sort(); |
| 21 | +} |
| 22 | + |
| 23 | +// eslint-disable-next-line import/no-default-export |
| 24 | +export default function({ getService }: FtrProviderContext) { |
| 25 | + const esArchiver = getService('esArchiver'); |
| 26 | + const ml = getService('ml'); |
| 27 | + |
| 28 | + const testDataList = [ |
| 29 | + { |
| 30 | + suiteTitle: 'with full farequote index', |
| 31 | + sourceIndexOrSavedSearch: 'farequote', |
| 32 | + metricFieldsFilter: 'document', |
| 33 | + nonMetricFieldsFilter: 'airline', |
| 34 | + nonMetricFieldsTypeFilter: 'keyword', |
| 35 | + expected: { |
| 36 | + totalDocCount: 86274, |
| 37 | + fieldsPanelCount: 2, // Metrics panel and Fields panel |
| 38 | + metricCards: [ |
| 39 | + { |
| 40 | + type: ML_JOB_FIELD_TYPES.NUMBER, // document count card |
| 41 | + existsInDocs: true, |
| 42 | + aggregatable: true, |
| 43 | + loading: false, |
| 44 | + }, |
| 45 | + { |
| 46 | + fieldName: 'responsetime', |
| 47 | + type: ML_JOB_FIELD_TYPES.NUMBER, |
| 48 | + existsInDocs: true, |
| 49 | + aggregatable: true, |
| 50 | + loading: false, |
| 51 | + }, |
| 52 | + ], |
| 53 | + nonMetricCards: [ |
| 54 | + { |
| 55 | + fieldName: '@timestamp', |
| 56 | + type: ML_JOB_FIELD_TYPES.DATE, |
| 57 | + existsInDocs: true, |
| 58 | + aggregatable: true, |
| 59 | + loading: false, |
| 60 | + }, |
| 61 | + { |
| 62 | + fieldName: '@version', |
| 63 | + type: ML_JOB_FIELD_TYPES.TEXT, |
| 64 | + existsInDocs: true, |
| 65 | + aggregatable: false, |
| 66 | + loading: false, |
| 67 | + }, |
| 68 | + { |
| 69 | + fieldName: '@version.keyword', |
| 70 | + type: ML_JOB_FIELD_TYPES.KEYWORD, |
| 71 | + existsInDocs: true, |
| 72 | + aggregatable: true, |
| 73 | + loading: false, |
| 74 | + }, |
| 75 | + { |
| 76 | + fieldName: 'airline', |
| 77 | + type: ML_JOB_FIELD_TYPES.KEYWORD, |
| 78 | + existsInDocs: true, |
| 79 | + aggregatable: true, |
| 80 | + loading: false, |
| 81 | + }, |
| 82 | + { |
| 83 | + fieldName: 'type', |
| 84 | + type: ML_JOB_FIELD_TYPES.TEXT, |
| 85 | + existsInDocs: true, |
| 86 | + aggregatable: false, |
| 87 | + loading: false, |
| 88 | + }, |
| 89 | + { |
| 90 | + fieldName: 'type.keyword', |
| 91 | + type: ML_JOB_FIELD_TYPES.KEYWORD, |
| 92 | + existsInDocs: true, |
| 93 | + aggregatable: true, |
| 94 | + loading: false, |
| 95 | + }, |
| 96 | + ], |
| 97 | + nonMetricFieldsTypeFilterCardCount: 3, |
| 98 | + metricFieldsFilterCardCount: 1, |
| 99 | + nonMetricFieldsFilterCardCount: 1, |
| 100 | + }, |
| 101 | + }, |
| 102 | + { |
| 103 | + suiteTitle: 'with lucene query on farequote index', |
| 104 | + sourceIndexOrSavedSearch: 'farequote_lucene', |
| 105 | + metricFieldsFilter: 'responsetime', |
| 106 | + nonMetricFieldsFilter: 'version', |
| 107 | + nonMetricFieldsTypeFilter: 'keyword', |
| 108 | + expected: { |
| 109 | + totalDocCount: 34416, |
| 110 | + fieldsPanelCount: 2, // Metrics panel and Fields panel |
| 111 | + metricCards: [ |
| 112 | + { |
| 113 | + type: ML_JOB_FIELD_TYPES.NUMBER, // document count card |
| 114 | + existsInDocs: true, |
| 115 | + aggregatable: true, |
| 116 | + loading: false, |
| 117 | + }, |
| 118 | + { |
| 119 | + fieldName: 'responsetime', |
| 120 | + type: ML_JOB_FIELD_TYPES.NUMBER, |
| 121 | + existsInDocs: true, |
| 122 | + aggregatable: true, |
| 123 | + loading: false, |
| 124 | + }, |
| 125 | + ], |
| 126 | + nonMetricCards: [ |
| 127 | + { |
| 128 | + fieldName: '@timestamp', |
| 129 | + type: ML_JOB_FIELD_TYPES.DATE, |
| 130 | + existsInDocs: true, |
| 131 | + aggregatable: true, |
| 132 | + loading: false, |
| 133 | + }, |
| 134 | + { |
| 135 | + fieldName: '@version', |
| 136 | + type: ML_JOB_FIELD_TYPES.TEXT, |
| 137 | + existsInDocs: true, |
| 138 | + aggregatable: false, |
| 139 | + loading: false, |
| 140 | + }, |
| 141 | + { |
| 142 | + fieldName: '@version.keyword', |
| 143 | + type: ML_JOB_FIELD_TYPES.KEYWORD, |
| 144 | + existsInDocs: true, |
| 145 | + aggregatable: true, |
| 146 | + loading: false, |
| 147 | + }, |
| 148 | + { |
| 149 | + fieldName: 'airline', |
| 150 | + type: ML_JOB_FIELD_TYPES.KEYWORD, |
| 151 | + existsInDocs: true, |
| 152 | + aggregatable: true, |
| 153 | + loading: false, |
| 154 | + }, |
| 155 | + { |
| 156 | + fieldName: 'type', |
| 157 | + type: ML_JOB_FIELD_TYPES.TEXT, |
| 158 | + existsInDocs: true, |
| 159 | + aggregatable: false, |
| 160 | + loading: false, |
| 161 | + }, |
| 162 | + { |
| 163 | + fieldName: 'type.keyword', |
| 164 | + type: ML_JOB_FIELD_TYPES.KEYWORD, |
| 165 | + existsInDocs: true, |
| 166 | + aggregatable: true, |
| 167 | + loading: false, |
| 168 | + }, |
| 169 | + ], |
| 170 | + nonMetricFieldsTypeFilterCardCount: 3, |
| 171 | + metricFieldsFilterCardCount: 2, |
| 172 | + nonMetricFieldsFilterCardCount: 1, |
| 173 | + }, |
| 174 | + }, |
| 175 | + ]; |
| 176 | + |
| 177 | + describe('index based', function() { |
| 178 | + this.tags(['smoke', 'mlqa']); |
| 179 | + before(async () => { |
| 180 | + await esArchiver.load('ml/farequote'); |
| 181 | + }); |
| 182 | + |
| 183 | + after(async () => { |
| 184 | + await esArchiver.unload('ml/farequote'); |
| 185 | + }); |
| 186 | + |
| 187 | + // TODO - add tests for |
| 188 | + // - validating metrics displayed inside the cards |
| 189 | + // - selecting a document sample size |
| 190 | + // - clicking on the link to the Advanced job wizard |
| 191 | + // - a test suite using a KQL based saved search |
| 192 | + for (const testData of testDataList) { |
| 193 | + describe(`${testData.suiteTitle}`, function() { |
| 194 | + it('loads the data visualizer selector page', async () => { |
| 195 | + await ml.navigation.navigateToMl(); |
| 196 | + await ml.navigation.navigateToDataVisualizer(); |
| 197 | + }); |
| 198 | + |
| 199 | + it('loads the saved search selection page', async () => { |
| 200 | + await ml.dataVisualizer.navigateToIndexPatternSelection(); |
| 201 | + }); |
| 202 | + |
| 203 | + it('loads the index data visualizer page', async () => { |
| 204 | + await ml.jobSourceSelection.selectSourceForIndexBasedDataVisualizer( |
| 205 | + testData.sourceIndexOrSavedSearch |
| 206 | + ); |
| 207 | + }); |
| 208 | + |
| 209 | + it('displays the time range step', async () => { |
| 210 | + await ml.dataVisualizerIndexBased.assertTimeRangeSelectorSectionExists(); |
| 211 | + }); |
| 212 | + |
| 213 | + it('loads data for full time range', async () => { |
| 214 | + await ml.dataVisualizerIndexBased.clickUseFullDataButton(testData.expected.totalDocCount); |
| 215 | + }); |
| 216 | + |
| 217 | + it('displays the panels of fields', async () => { |
| 218 | + await ml.dataVisualizerIndexBased.assertFieldsPanelsExist( |
| 219 | + testData.expected.fieldsPanelCount |
| 220 | + ); |
| 221 | + }); |
| 222 | + |
| 223 | + if (testData.expected.metricCards && testData.expected.metricCards.length > 0) { |
| 224 | + it('displays the Metrics panel', async () => { |
| 225 | + await ml.dataVisualizerIndexBased.assertFieldsPanelForTypesExist([ |
| 226 | + ML_JOB_FIELD_TYPES.NUMBER, |
| 227 | + ]); // document_count not exposed as a type in the panel |
| 228 | + }); |
| 229 | + |
| 230 | + it('displays the expected metric field cards', async () => { |
| 231 | + for (const fieldCard of testData.expected.metricCards) { |
| 232 | + await ml.dataVisualizerIndexBased.assertCardExists( |
| 233 | + fieldCard.type, |
| 234 | + fieldCard.fieldName |
| 235 | + ); |
| 236 | + } |
| 237 | + }); |
| 238 | + |
| 239 | + it('filters metric fields cards with search', async () => { |
| 240 | + await ml.dataVisualizerIndexBased.filterFieldsPanelWithSearchString( |
| 241 | + ['number'], |
| 242 | + testData.metricFieldsFilter, |
| 243 | + testData.expected.metricFieldsFilterCardCount |
| 244 | + ); |
| 245 | + }); |
| 246 | + } |
| 247 | + |
| 248 | + if (testData.expected.nonMetricCards && testData.expected.nonMetricCards.length > 0) { |
| 249 | + it('displays the non-metric Fields panel', async () => { |
| 250 | + await ml.dataVisualizerIndexBased.assertFieldsPanelForTypesExist( |
| 251 | + getFieldTypes(testData.expected.nonMetricCards) |
| 252 | + ); |
| 253 | + }); |
| 254 | + |
| 255 | + it('displays the expected non-metric field cards', async () => { |
| 256 | + for (const fieldCard of testData.expected.nonMetricCards) { |
| 257 | + await ml.dataVisualizerIndexBased.assertCardExists( |
| 258 | + fieldCard.type, |
| 259 | + fieldCard.fieldName |
| 260 | + ); |
| 261 | + } |
| 262 | + }); |
| 263 | + |
| 264 | + it('sets the non metric field types input', async () => { |
| 265 | + const fieldTypes: ML_JOB_FIELD_TYPES[] = getFieldTypes( |
| 266 | + testData.expected.nonMetricCards |
| 267 | + ); |
| 268 | + await ml.dataVisualizerIndexBased.assertFieldsPanelTypeInputExists(fieldTypes); |
| 269 | + await ml.dataVisualizerIndexBased.setFieldsPanelTypeInputValue( |
| 270 | + fieldTypes, |
| 271 | + testData.nonMetricFieldsTypeFilter, |
| 272 | + testData.expected.nonMetricFieldsTypeFilterCardCount |
| 273 | + ); |
| 274 | + }); |
| 275 | + |
| 276 | + it('filters non-metric fields cards with search', async () => { |
| 277 | + await ml.dataVisualizerIndexBased.filterFieldsPanelWithSearchString( |
| 278 | + getFieldTypes(testData.expected.nonMetricCards), |
| 279 | + testData.nonMetricFieldsFilter, |
| 280 | + testData.expected.nonMetricFieldsFilterCardCount |
| 281 | + ); |
| 282 | + }); |
| 283 | + } |
| 284 | + }); |
| 285 | + } |
| 286 | + }); |
| 287 | +} |
0 commit comments