lundi 2 novembre 2020

Jasmine Karma Test case for drag and drop angular material

I have implemented drag and drop using angular material. which has a function drop. The drop function makes use of native element and uses the parentNode and perform the drag and drop. I am unable to get the native element to spy parentnode appendchild, removechild to write test cases in jasmine karma. Can someone help me to write test case for the drop method below? Below link has the sample code for drag and drop.

drop() {
    if (!this.target)
      return;

    let phElement = this.placeholder.element.nativeElement;
    let parent = phElement.parentNode;

    phElement.style.display = 'none';

    parent.removeChild(phElement);
    parent.appendChild(phElement);
    parent.insertBefore(this.source.element.nativeElement, parent.children[this.sourceIndex]);

    this.target = null;
    this.source = null;

    if (this.sourceIndex != this.targetIndex)
      moveItemInArray(this.items, this.sourceIndex, this.targetIndex);
  }

https://stackblitz.com/edit/angular-nuiviw

Aucun commentaire:

Enregistrer un commentaire