You need to sign in to do that
Don't have an account?
Ludivine
Help to write a Test Class for Aura Component
Hello,
I have created a lightning component in sandbox to display the lock/ Unlock icon on my record Page.
This needs to create the following Apex method:
I have tried to fire approval from my test class but it is not testing these aura method...
Mant thanks in advance.
Best Regards.
I have created a lightning component in sandbox to display the lock/ Unlock icon on my record Page.
This needs to create the following Apex method:
public class UnlockRecordUtil { @AuraEnabled public static Boolean islocked(String recordId){ return Approval.isLocked(Id.ValueOf(recordId)); } @AuraEnabled public static boolean unlockRecord(String objId){ List<String> unlockrec = new List<string>(); unlockrec.add(objId); Approval.UnlockResult[] unlockedRersult = Approval.unlock(unlockrec); return true; } @AuraEnabled public static Boolean LockRecords(String objId){ List<Account> sobjectre = [Select Id FROM Account WHERE ID =:objId]; Approval.LockResult[] lrList = Approval.lock(sobjectre, false); return true; } }However, I don't know how to do the test class for this ligthning component.
I have tried to fire approval from my test class but it is not testing these aura method...
Mant thanks in advance.
Best Regards.
I was able to get 81% coverage. not able to cover the return statements.Please find the code below:
@isTest
private class UnlockRecordUtiltest{
static testmethod void islockedtest(){
Account acc1 = new Account(name='test');
insert acc1;
UnlockRecordUtil.islocked(string.valueof(acc1.id));
}
static testmethod void unlockRecordtest(){
Account acc2 = new Account(name='test');
insert acc2;
UnlockRecordUtil.unlockRecord(string.valueof(acc2.id));
}
static testmethod void LockRecordstest(){
Account acc = new Account(name='test Account');
UnlockRecordUtil.LockRecords(string.valueof(acc.id));
}
}
All Answers
I was able to get 81% coverage. not able to cover the return statements.Please find the code below:
@isTest
private class UnlockRecordUtiltest{
static testmethod void islockedtest(){
Account acc1 = new Account(name='test');
insert acc1;
UnlockRecordUtil.islocked(string.valueof(acc1.id));
}
static testmethod void unlockRecordtest(){
Account acc2 = new Account(name='test');
insert acc2;
UnlockRecordUtil.unlockRecord(string.valueof(acc2.id));
}
static testmethod void LockRecordstest(){
Account acc = new Account(name='test Account');
UnlockRecordUtil.LockRecords(string.valueof(acc.id));
}
}
$hwet@,Many thanks, I managed to cover 100% of my Apex Class! Awesome!