component handler which is need to be call
<aura:handler name="init" value="{!this}" action="{!c.getLoginUrls}" />
Component method
({
getLoginUrls : function(component, event, helper) {
//This method will handle login action
helper.handleLoginActionCallBack(component).then(
// resolve handler
$A.getCallback(function(response) {
//$A.get("e.force:closeQuickAction").fire()
response.data !='Insufficient Privileges'?helper.navigateToUrl(response):helper.toastMsg(response);
}),
// reject handler
$A.getCallback(function(response) {
//$A.get("e.force:closeQuickAction").fire()
return helper.toastMsg(response);
})
).catch(function(error){
$A.reportError("error message here", error);
});
}
})
helper method
({
handleLoginActionCallBack : function(component) {
var action = component.get("c.getUrl");
return new Promise(function(resolve, reject) {
action.setParams({ identifier : component.get("v.recordId") });
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
resolve({component: component, data: response.getReturnValue()})
}
else {
reject(new Error(response.getError()));
}
});
$A.enqueueAction(action);
});
},
/**
* navigateToUrl method will navigate to Url depending upon organization type login Url
*/
navigateToUrl : function(response) {
//open window with return value login url from server side action
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": response.data
});
urlEvent.fire();
},
/**
* toastMsg method will toast notification with a serverside message
*/
toastMsg : function(response) {
//toast while getting error message
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Error!",
"message": response.data,
type:"error"
});
toastEvent.fire();
}
})
how to test this method in jasmine LTS .tried to test through jasmine but con't resolve to test the component