lundi 28 septembre 2015

Jasmine Testing a window.Return value from showModalDialog

So,I am showing a pop up window using showModalDialog.From this popup window,I am returning a value to the calling window using window.return value.

The small snippet of code is as shown below.

      if ($.isNumeric(rowDataID) && rowDataID != "") {
           if (searchMode !== "") {
                switch (searchMode) {
               case "4":
                     window.returnValue = rowDataID + "*" + "2" + "*" + "False"
                     break;}}
              window.close();}

How would I go about unit testing this code using Jasmine Unit testing? I am using jqGrid and this value is being returned on the click of a select button.

I have the jqGrid preloaded in the beforeEach.This is what I have so far.

it("selectDatafromGrid() -> Blah Blah Blah", function () {
    $("#divVars").attr("searchMode", 4);
    var searchMode = getSearchMode(); //this gets me the value 4

    spyOn(window, 'showModalDialog').andCallFake(function() {  return '20000*2*False';  });
    var testdata = [{"PatientID":"20000","LastName":"Mohanty","FirstName":"Pritam"},{"PatientID":"30000","LastName":"Burson","FirstName":"Johnny"}];
    addRowDataToGrid(testdata); //Adds the data to the Grid.
    var gridRowIDs = $("#jqGridPatientSearch").jqGrid("getDataIDs"); 
    $("#jqGridPatientSearch").jqGrid("setSelection", gridRowIDs[0]); 
    selectDatafromGrid(searchMode);
    expect().toBe('20000*2*False');
});

But , whats happening is that the Grid is getting displayed when I run this test.Dont know,where I am going wrong.

Aucun commentaire:

Enregistrer un commentaire