@@ -24,37 +24,62 @@ export default function({ getService, getPageObjects }: FtrProviderContext) {
2424 return esArchiver . unload ( 'pre_calculated_histogram' ) ;
2525 } ) ;
2626
27- const initHistogramBarChart = async ( ) => {
28- await PageObjects . visualize . navigateToNewVisualization ( ) ;
29- await PageObjects . visualize . clickVerticalBarChart ( ) ;
30- await PageObjects . visualize . clickNewSearch ( 'histogram-test' ) ;
31- await PageObjects . visChart . waitForVisualization ( ) ;
32- } ;
33-
34- const getFieldOptionsForAggregation = async ( aggregation : string ) : Promise < string [ ] > => {
35- await PageObjects . visEditor . clickBucket ( 'Y-axis' , 'metrics' ) ;
36- await PageObjects . visEditor . selectAggregation ( aggregation , 'metrics' ) ;
37- const fieldValues = await PageObjects . visEditor . getField ( ) ;
38- return fieldValues ;
39- } ;
40-
4127 it ( 'appears correctly in discover' , async function ( ) {
4228 await PageObjects . common . navigateToApp ( 'discover' ) ;
4329 const rowData = await PageObjects . discover . getDocTableIndex ( 1 ) ;
4430 expect ( rowData . includes ( '"values": [ 0.3, 1, 3, 4.2, 4.8 ]' ) ) . to . be . ok ( ) ;
4531 } ) ;
4632
47- it ( 'appears in the field options of a Percentiles aggregation' , async function ( ) {
48- await initHistogramBarChart ( ) ;
49- const fieldValues : string [ ] = await getFieldOptionsForAggregation ( 'Percentiles' ) ;
50- log . debug ( 'Percentiles Fields = ' + fieldValues ) ;
51- expect ( fieldValues [ 0 ] ) . to . be ( 'histogram-content' ) ;
52- } ) ;
33+ describe ( 'works in visualizations' , ( ) => {
34+ before ( async ( ) => {
35+ await PageObjects . visualize . navigateToNewVisualization ( ) ;
36+ await PageObjects . visualize . clickDataTable ( ) ;
37+ await PageObjects . visualize . clickNewSearch ( 'histogram-test' ) ;
38+ await PageObjects . visChart . waitForVisualization ( ) ;
39+ await PageObjects . visEditor . clickMetricEditor ( ) ;
40+ } ) ;
41+
42+ const renderTableForAggregation = async ( aggregation : string ) => {
43+ await PageObjects . visEditor . selectAggregation ( aggregation , 'metrics' ) ;
44+ await PageObjects . visEditor . selectField ( 'histogram-content' , 'metrics' ) ;
45+ await PageObjects . visEditor . clickGo ( ) ;
46+
47+ return await PageObjects . visChart . getTableVisContent ( ) ;
48+ } ;
49+
50+ it ( 'with percentiles aggregation' , async ( ) => {
51+ const data = ( await renderTableForAggregation ( 'Percentiles' ) ) as string [ ] [ ] ;
52+ expect ( data [ 0 ] ) . to . have . property ( 'length' , 7 ) ;
53+ // Percentile values are not deterministic, so we can't check for the exact values here,
54+ // but just check they are all within the given range
55+ // see https://github.com/elastic/elasticsearch/issues/49225
56+ expect ( data [ 0 ] . every ( ( p : string ) => Number ( p ) >= 0.3 && Number ( p ) <= 5 ) ) . to . be ( true ) ;
57+ } ) ;
58+
59+ it ( 'with percentile ranks aggregation' , async ( ) => {
60+ const data = await renderTableForAggregation ( 'Percentile Ranks' ) ;
61+ expect ( data ) . to . eql ( [ [ '0%' ] ] ) ;
62+ } ) ;
63+
64+ it ( 'with average aggregation' , async ( ) => {
65+ const data = await renderTableForAggregation ( 'Average' ) ;
66+ expect ( data ) . to . eql ( [ [ '2.8510720308359434' ] ] ) ;
67+ } ) ;
68+
69+ it ( 'with median aggregation' , async ( ) => {
70+ // Percentile values (which are used by median behind the scenes) are not deterministic,
71+ // so we can't check for the exact values here, but just check they are all within the given range
72+ // see https://github.com/elastic/elasticsearch/issues/49225
73+ const data = await renderTableForAggregation ( 'Median' ) ;
74+ const value = Number ( data [ 0 ] [ 0 ] ) ;
75+ expect ( value ) . to . be . above ( 3.0 ) ;
76+ expect ( value ) . to . be . below ( 3.3 ) ;
77+ } ) ;
5378
54- it ( 'appears in the field options of a Percentile Ranks aggregation' , async function ( ) {
55- const fieldValues : string [ ] = await getFieldOptionsForAggregation ( 'Percentile Ranks ') ;
56- log . debug ( 'Percentile Ranks Fields = ' + fieldValues ) ;
57- expect ( fieldValues [ 0 ] ) . to . be ( 'histogram-content' ) ;
79+ it ( 'with sum aggregation' , async ( ) => {
80+ const data = await renderTableForAggregation ( 'Sum ') ;
81+ expect ( data ) . to . eql ( [ [ '11834.800000000001' ] ] ) ;
82+ } ) ;
5883 } ) ;
5984 } ) ;
6085}
0 commit comments