[DURACOM-237] Fix tests

This commit is contained in:
Giuseppe Digilio
2024-03-21 16:33:32 +01:00
parent 5d24691bc2
commit abb284a2d6
3 changed files with 10 additions and 7 deletions

View File

@@ -14,7 +14,7 @@
(mouseout)="t.close()"> (mouseout)="t.close()">
<a class="flex-sm-fill text-sm-center nav-link active bg-info" <a class="flex-sm-fill text-sm-center nav-link active bg-info"
cdkDrag cdkDrag
(cdkDragStarted)="onDrag($event)" (cdkDragStarted)="onDrag(i)"
href="javascript:void(0);" href="javascript:void(0);"
[ngClass]="{'chip-selected disabled': (editable && c.editMode) || dragged === i}" [ngClass]="{'chip-selected disabled': (editable && c.editMode) || dragged === i}"
(click)="chipsSelected($event, i);"> (click)="chipsSelected($event, i);">

View File

@@ -134,18 +134,18 @@ describe('ChipsComponent test suite', () => {
})); }));
it('should save chips item index when drag and drop start', fakeAsync(() => { it('should save chips item index when drag and drop start', fakeAsync(() => {
const de = chipsFixture.debugElement.query(By.css('div.nav-item')); const de = chipsFixture.debugElement.query(By.css('a'));
de.triggerEventHandler('dragstart', null); de.triggerEventHandler('cdkDragStarted', null);
expect(chipsComp.dragged).toBe(0); expect(chipsComp.dragged).toBe(0);
})); }));
it('should update chips item order when drag and drop end', fakeAsync(() => { it('should update chips item order when drag and drop end', fakeAsync(() => {
spyOn(chipsComp.chips, 'updateOrder'); spyOn(chipsComp.chips, 'updateOrder');
const de = chipsFixture.debugElement.query(By.css('div.nav-item')); const de = chipsFixture.debugElement.query(By.css('div[role="list"]'));
de.triggerEventHandler('dragend', null); de.triggerEventHandler('cdkDropListDropped', { previousIndex: 0, currentIndex: 1 });
expect(chipsComp.dragged).toBe(-1); expect(chipsComp.dragged).toBe(-1);
expect(chipsComp.chips.updateOrder).toHaveBeenCalled(); expect(chipsComp.chips.updateOrder).toHaveBeenCalled();

View File

@@ -1,7 +1,6 @@
import { import {
CdkDrag, CdkDrag,
CdkDragDrop, CdkDragDrop,
CdkDragStart,
CdkDropList, CdkDropList,
moveItemInArray, moveItemInArray,
} from '@angular/cdk/drag-drop'; } from '@angular/cdk/drag-drop';
@@ -101,14 +100,18 @@ export class ChipsComponent implements OnChanges {
} }
} }
onDrag(event: CdkDragStart<ChipsItem[]>) { onDrag(index) {
this.isDragging.next(true); this.isDragging.next(true);
this.dragged = index;
} }
onDrop(event: CdkDragDrop<ChipsItem[]>) { onDrop(event: CdkDragDrop<ChipsItem[]>) {
console.log('onDrop', event);
moveItemInArray(this.chips.chipsItems.getValue(), event.previousIndex, event.currentIndex); moveItemInArray(this.chips.chipsItems.getValue(), event.previousIndex, event.currentIndex);
this.chips.updateOrder(); this.chips.updateOrder();
this.isDragging.next(false); this.isDragging.next(false);
} }
showTooltip(tooltip: NgbTooltip, index, field?) { showTooltip(tooltip: NgbTooltip, index, field?) {
tooltip.close(); tooltip.close();
if (this.isDragging.value) { if (this.isDragging.value) {