@@ -32,11 +32,21 @@ function sampleArgs() {
3232 accessor : 'a' ,
3333 layerId : 'l1' ,
3434 title : 'My fanci metric chart' ,
35+ description : 'Fancy chart description' ,
3536 metricTitle : 'My fanci metric chart' ,
3637 mode : 'full' ,
3738 } ;
3839
39- return { data, args } ;
40+ const noAttributesArgs : MetricConfig = {
41+ accessor : 'a' ,
42+ layerId : 'l1' ,
43+ title : '' ,
44+ description : '' ,
45+ metricTitle : 'My fanci metric chart' ,
46+ mode : 'full' ,
47+ } ;
48+
49+ return { data, args, noAttributesArgs } ;
4050}
4151
4252describe ( 'metric_expression' , ( ) => {
@@ -54,14 +64,15 @@ describe('metric_expression', () => {
5464 } ) ;
5565
5666 describe ( 'MetricChart component' , ( ) => {
57- test ( 'it renders the title and value' , ( ) => {
67+ test ( 'it renders the all attributes when passed ( title, description, metricTitle, value) ' , ( ) => {
5868 const { data, args } = sampleArgs ( ) ;
5969
6070 expect (
6171 shallow ( < MetricChart data = { data } args = { args } formatFactory = { ( x ) => x as IFieldFormat } /> )
6272 ) . toMatchInlineSnapshot ( `
6373 <VisualizationContainer
6474 className="lnsMetricExpression__container"
75+ reportDescription="Fancy chart description"
6576 reportTitle="My fanci metric chart"
6677 >
6778 <AutoScale>
@@ -91,21 +102,66 @@ describe('metric_expression', () => {
91102 ` ) ;
92103 } ) ;
93104
94- test ( 'it does not render title in reduced mode ' , ( ) => {
95- const { data, args } = sampleArgs ( ) ;
105+ test ( 'it renders only chart content when title and description are empty strings ' , ( ) => {
106+ const { data, noAttributesArgs } = sampleArgs ( ) ;
96107
97108 expect (
98109 shallow (
99110 < MetricChart
100111 data = { data }
101- args = { { ... args , mode : 'reduced' } }
112+ args = { noAttributesArgs }
102113 formatFactory = { ( x ) => x as IFieldFormat }
103114 />
104115 )
105116 ) . toMatchInlineSnapshot ( `
106117 <VisualizationContainer
107118 className="lnsMetricExpression__container"
108- reportTitle="My fanci metric chart"
119+ reportDescription=""
120+ reportTitle=""
121+ >
122+ <AutoScale>
123+ <div
124+ data-test-subj="lns_metric_value"
125+ style={
126+ Object {
127+ "fontSize": "60pt",
128+ "fontWeight": 600,
129+ }
130+ }
131+ >
132+ 10110
133+ </div>
134+ <div
135+ data-test-subj="lns_metric_title"
136+ style={
137+ Object {
138+ "fontSize": "24pt",
139+ }
140+ }
141+ >
142+ My fanci metric chart
143+ </div>
144+ </AutoScale>
145+ </VisualizationContainer>
146+ ` ) ;
147+ } ) ;
148+
149+ test ( 'it does not render metricTitle in reduced mode' , ( ) => {
150+ const { data, noAttributesArgs } = sampleArgs ( ) ;
151+
152+ expect (
153+ shallow (
154+ < MetricChart
155+ data = { data }
156+ args = { { ...noAttributesArgs , mode : 'reduced' } }
157+ formatFactory = { ( x ) => x as IFieldFormat }
158+ />
159+ )
160+ ) . toMatchInlineSnapshot ( `
161+ <VisualizationContainer
162+ className="lnsMetricExpression__container"
163+ reportDescription=""
164+ reportTitle=""
109165 >
110166 <AutoScale>
111167 <div
0 commit comments