0

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

1 Answer 1

0

My understanding on how to do this is based on the jasmineExampleTests.resource. For asynchronous operations, the $T.waitFor can be used to block the test until the expected result has happened. In your case that result is the navigation to a new URL. (You also need to understand Jasmine's done mechanism.)

Unfortunately this design mixes up the waiting for the asynchronous work to be completed with the logical condition being asserted; I'd like to see a leaner mechanism in LTS e.g. Adding a waitForAura mechanism.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .