SalesforceLabs / EnhancedLightningGrid

Component that allows you to sort and filter data within the Lightning Experience. Use as a replacement for a Related List, or create a new grid that shows results from a custom query.
BSD 3-Clause "New" or "Revised" License
136 stars 96 forks source link

test for custom data provider #24

Open mkdir-not-war opened 5 years ago

mkdir-not-war commented 5 years ago

Hello, we have been using your example class as a framework for our own custom data provider classes.

global with sharing class mydp implements sortablegrid.sdgIDataProvider {

but we are having an issue with getting code coverage. Specifically on the private methods GetFields and GetActions, as well as especially the LoadSDG function, which is non-static. Since the custom class implements the sdgIDataProvider, which is an interface and cannot be instantiated, and since the custom class itself has no constructor, it would stand to reason that only static methods from it could be called. There is no way to instantiate the class, so there is no way to call instance methods. I see you found a creative way around this in your class "sdgDataProviderFactory," but unfortunately that class is not visible to us using the managed package. If you could provide some insight on how to call the LoadSDG function in your own example, it would greatly help us do the same in our own. Thanks.

justinclarke-sc commented 4 years ago

this is the code we're using to get code coverage:

Id testRecordId = yourParentRecordId;

// instantiate class
yourLightningGridClassName lgMA = new yourLightningGridClassName();
sortablegrid.SDG coreSDG = lgMA.LoadSDG('', testRecordId);

system.assertNotEquals(null, coreSDG);
system.assertNotEquals(0, coreSDG.SDGActions.size());
system.assertNotEquals(0, coreSDG.SDGFields.size());

// create the user request
sortablegrid.SDGRequest request = new sortablegrid.SDGRequest();
request.parentRecordId = testRecordId;
request.pageId = 1;
request.pageSize = 10;
request.SortColumn = '1';
request.SortOrder = 'A';

// get data
result = yourLightningGridClassName.getData(coreSDG, request);
system.assertNotEquals(null, result);