CollectionView itemsEdited testing

Posted by: ken_perregaux on 29 May 2020, 11:32 am EST

    • Post Options:
    • Link

    Posted 29 May 2020, 11:32 am EST

    I am using angular 9 and wijmo 5.20193.637 and I am trying to unit test some of my code. The problem is some of the code relies on itemsEdited being populated. I can not for the life of me figure out how to get itemsEdited to populate in my unit tests. I have tried calling editItem and commitEdit and it doesn’t appear to update for me. Any help would be greatly appreciated.

  • Posted 1 June 2020, 1:26 am EST

    Hi Ken,

    Have you tried setting the trackChanges property of CollectionView to true? If it is set to true, then only the CollectionView will keep track of the edited items in itemsEdited array.

    https://www.grapecity.com/wijmo/api/classes/wijmo.collectionview.html#trackchanges

    Please refer to the demo link for reference:

    https://www.grapecity.com/wijmo/demos/Core/CollectionView/EditingViews/TrackingChanges/purejs

    Regards,

    Ashwin

  • Posted 1 June 2020, 9:44 am EST

    trackChanges is being set. The actual application is working great. I am just trying to unit test my code and a piece of code is not getting reached during test because I can’t get the itemsAdded collection to change in the unit test. As I said I have tried editItem and commitEdit with not success. I just tried setCellData but that thows an exception.

  • Posted 1 June 2020, 4:19 pm EST

    So I kind of fixed this using setCellData, for some reason if I call setCellData on a cell that uses a dataMap that is when the exception is thrown, is there something special I need to do for that?

  • Posted 2 June 2020, 4:21 am EST

    Hi Ken,

    To populate the itemsEdited array, you actually have to edit an item. Just by calling the editItem and commitEdit method will not edit the item. You need to update any of the properties of the item and then call the commitEdit method:

    // view is the CollectionView
    // item is the item to be edited
    view.editItem(item);
    item.country = 'US'; // change the country
    view.commitEdit();
    

    The setCellData follows the same procedure internally. It should also work with DataMaps. Can you please let me know what exception is thrown while editing the cells with data map?

    ~regards

  • Posted 2 June 2020, 7:47 am EST

    Thank you for the clarification on the use of editItem and commitEdit, I was modifying the object before the editItem call. As for the exception, I figured that out too, there was a typo in one of my test data objects, the diplayMemberPath was not correct on one of the objects (ooops).

    Thank you so much for your time and help!

  • Posted 3 June 2020, 12:07 am EST

    Hi Ken,

    We are glad that you were able to resolve the issue.

    ~regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels