stuck in here to write a test class,please suggest a test class ,below test class which was written didn't solved the purpose
@isTest
public class testStack {
public static testMethod void testCallClass(){
Account acc = new Account(Name='Test Account');
insert acc;
Test.startTest();
LookupSearchResult lcr = new LookupSearchResult(acc.id,'Account','Test Icon','Test Title','Test Sub-Title');
system.assert(lcr.getId() == acc.id);
system.assert(lcr.getSObjectType() == 'Account');
system.assert(lcr.getIcon() == 'Test Icon');
system.assert(lcr.getTitle() == 'Test Title');
system.assert(lcr.getSubtitle() == 'Test Sub-Title');
Case_Type_Data__c ctd = new Case_Type_Data__c(Name='500J000000Mo18fIAB',Level_1__c='Acct management issues',Level_2__c='Issue1',Level_3__c='Issue4');
insert ctd;
List < List < SObject > > searchResults = Stack.search( '500J000000Mo18fIAB',acc.id );
List < Case_Type_Data__c > listctd = searchResults.get( 0 );
system.assertEquals( 0, listctd.size() );
Test.stopTest();
}
}
here is the aura enabled class for which test class is needed
public class Stack {
@AuraEnabled(cacheable=true)
public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
if(String.isBlank(searchTerm) || searchTerm.length() < 2){
return null;
}
String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
FROM Case_Type_Data__c
WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
ORDER BY Level_1__c, Level_2__c, Level_3__c
LIMIT 20];
/* You could also experiment with SOSL?
records = [FIND :('*' + searchTerm + '*') IN ALL FIELDS
RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
*/
List<LookupSearchResult> results = new List<LookupSearchResult>();
for(Case_Type_Data__c ctd : records){
results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
));
}
return results;
}
}
Previously written tests for PickListHandler which tests all levels namely level1 level2 and level3
@IsTest
public class testGetAllLevels {
@IsTest
static void testGetLevel1()
{
Case_Type_Data__c obj = new Case_Type_Data__c();
obj.Level_1__c = 'Test Level 1';
insert obj;
List<String> s = PickListHandler.getLevel1();
}
@IsTest
static void testGetLevel2()
{
Case_Type_Data__c obj = new Case_Type_Data__c();
obj.Level_1__c = 'Test Level 1';
insert obj;
List<String> s = PickListHandler.getLevel2('Test Level 1');
}
@IsTest
static void testGetLevel3()
{
Case_Type_Data__c obj = new Case_Type_Data__c();
obj.Level_1__c = 'Test Level 1';
obj.Level_2__c = 'Test Level 2';
obj.Level_3__c = 'Test Level 3';
insert obj;
List<String> s = PickListHandler.getLevel3('Test Level 1','Test Level 2');
}
@IsTest
static void testsaveCaseType(){
// Create the Case Record.
Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email');
insert cas;
ERT_Case_Type__c obj=new ERT_Case_Type__c();
string one='one';
string two='two';
string three='three';
test.startTest();
String testing=PickListHandler.savecasetype(one,two,three,cas.id);
test.stopTest();
}