diff --git a/__tests__/unit/chartBuilder.test.js b/__tests__/unit/chartBuilder.test.js index 97c0ca2a..29a10a5f 100644 --- a/__tests__/unit/chartBuilder.test.js +++ b/__tests__/unit/chartBuilder.test.js @@ -58,7 +58,7 @@ describe('call server and get chart data when', () => { element.handler = 'FakeHandler'; return flushPromises().then(() => { - expect(element.details).toMatchObject([]); + expect(element.details).toBeNull(); }); }); }); diff --git a/force-app/main/default/classes/ChartBuilderControllerTest.cls b/force-app/main/default/classes/ChartBuilderControllerTest.cls index 9fd0c05a..b7332010 100755 --- a/force-app/main/default/classes/ChartBuilderControllerTest.cls +++ b/force-app/main/default/classes/ChartBuilderControllerTest.cls @@ -23,8 +23,8 @@ private class ChartBuilderControllerTest { ); Test.stopTest(); System.assertEquals( - OPPORTUNITY_STAGE_NAME, - chartDatas[0].label, + new List{ OPPORTUNITY_STAGE_NAME }, + chartDatas[0].labels, 'chartDatas.label must equals ' + OPPORTUNITY_STAGE_NAME ); System.assertEquals( @@ -68,9 +68,9 @@ private class ChartBuilderControllerTest { ); Test.stopTest(); System.assertEquals( - ChartDataProviderTest.TEST_LABEL, - chartDatas[0].label, - 'chartDatas.label must equals ' + ChartDataProviderTest.TEST_LABEL + ChartDataProviderTest.TEST_LABELS, + chartDatas[0].labels, + 'chartDatas.label must equals ' + ChartDataProviderTest.TEST_LABELS ); System.assertEquals( ChartDataProviderTest.TEST_DATA, diff --git a/force-app/main/default/classes/ChartDataProvider.cls b/force-app/main/default/classes/ChartDataProvider.cls index 11942fce..977741c0 100755 --- a/force-app/main/default/classes/ChartDataProvider.cls +++ b/force-app/main/default/classes/ChartDataProvider.cls @@ -25,7 +25,7 @@ public inherited sharing abstract class ChartDataProvider { * @description contains the label for this data */ @AuraEnabled - public String label; + public List labels; /******************************************************************************************************* * @description contains the values for this data diff --git a/force-app/main/default/classes/ChartDataProviderTest.cls b/force-app/main/default/classes/ChartDataProviderTest.cls index e63531b2..cc98e804 100755 --- a/force-app/main/default/classes/ChartDataProviderTest.cls +++ b/force-app/main/default/classes/ChartDataProviderTest.cls @@ -20,9 +20,9 @@ public class ChartDataProviderTest { final List chartDatas = aChartDataProvider.getData(); Test.stopTest(); System.assertEquals( - TEST_LABEL, - chartDatas[0].label, - 'chartDatas.label must equals ' + TEST_LABEL + TEST_LABELS, + chartDatas[0].labels, + 'chartDatas.label must equals ' + TEST_LABELS ); System.assertEquals( TEST_DATA, @@ -46,14 +46,14 @@ public class ChartDataProviderTest { public override List getData() { final List chartDatas = new List(); ChartDataProvider.ChartData aChartData = new ChartDataProvider.ChartData(); - aChartData.label = TEST_LABEL; + aChartData.labels = TEST_LABELS; aChartData.detail = TEST_DATA; aChartData.bgColor = TEST_COLOR; chartDatas.add(aChartData); return chartDatas; } } - public static final String TEST_LABEL = 'test'; + public static final List TEST_LABELS = new List{ 'test' }; public static final List TEST_DATA = new List{ 42 }; public static final String TEST_COLOR = 'test'; } diff --git a/force-app/main/default/classes/SOQLDataProvider.cls b/force-app/main/default/classes/SOQLDataProvider.cls index 7c6925e4..2664a0e1 100755 --- a/force-app/main/default/classes/SOQLDataProvider.cls +++ b/force-app/main/default/classes/SOQLDataProvider.cls @@ -64,21 +64,23 @@ public inherited sharing virtual class SOQLDataProvider extends ChartDataProvide ); } - final List chartDatas = new List(); // When building the chart in the app builder and using :recordId in the query // The context is not set and :recordId is undefined // In this case we can't get not data but it is still possible to build the chart in the App Builder if (this.query.contains(UNDEFINED_RECORDID)) { - return chartDatas; + return new List(); } + + final ChartDataProvider.ChartData aChartData = new ChartDataProvider.ChartData(); + aChartData.labels = new List(); + aChartData.detail = new List(); + for (AggregateResult aResult : Database.query(this.query)) { - ChartDataProvider.ChartData aChartData = new ChartDataProvider.ChartData(); - aChartData.label = (String) aResult.get(LABEL_ALIAS); - aChartData.detail = new List{ aResult.get(VALUE_ALIAS) }; - chartDatas.Add(aChartData); + aChartData.labels.add((String) aResult.get(LABEL_ALIAS)); + aChartData.detail.add(aResult.get(VALUE_ALIAS)); } - return chartDatas; + return new List{ aChartData }; } public class SOQLDataProviderException extends Exception { diff --git a/force-app/main/default/classes/SOQLDataProviderTest.cls b/force-app/main/default/classes/SOQLDataProviderTest.cls index c8c9a480..5801ffab 100755 --- a/force-app/main/default/classes/SOQLDataProviderTest.cls +++ b/force-app/main/default/classes/SOQLDataProviderTest.cls @@ -146,8 +146,8 @@ private class SOQLDataProviderTest { final List chartDatas = aSOQLDataProvider.getData(); Test.stopTest(); System.assertEquals( - OPPORTUNITY_STAGE_NAME, - chartDatas[0].label, + new List{ OPPORTUNITY_STAGE_NAME }, + chartDatas[0].labels, 'chartDatas.label must equals ' + OPPORTUNITY_STAGE_NAME ); System.assertEquals( diff --git a/force-app/main/default/lwc/chartBuilder/chartBuilder.html b/force-app/main/default/lwc/chartBuilder/chartBuilder.html index 40a90695..b7109e9b 100644 --- a/force-app/main/default/lwc/chartBuilder/chartBuilder.html +++ b/force-app/main/default/lwc/chartBuilder/chartBuilder.html @@ -10,11 +10,11 @@ stylecss={styleCss} onlwccerror={handleError} > - +