|
1 | 1 | import { Component, ViewChildren, QueryList, ViewChild, ElementRef, TemplateRef, Renderer2 } from '@angular/core';
|
2 | 2 | import { async, TestBed, ComponentFixture } from '@angular/core/testing';
|
| 3 | +import { By } from '@angular/platform-browser'; |
3 | 4 | import { FormsModule } from '@angular/forms';
|
4 |
| -import { IgxDragDropModule, IgxDragDirective, IgxDropDirective, IgxDragLocation, IDropDroppedEventArgs } from './drag-drop.directive'; |
5 | 5 | import { UIInteractions, wait} from '../../test-utils/ui-interactions.spec';
|
6 | 6 | import { configureTestSuite } from '../../test-utils/configure-suite';
|
7 |
| -import { IgxInsertDropStrategy, IgxAppendDropStrategy, IgxPrependDropStrategy } from './drag-drop.strategy'; |
8 | 7 | import { first } from 'rxjs/operators';
|
| 8 | +import { IgxInsertDropStrategy, IgxAppendDropStrategy, IgxPrependDropStrategy } from './drag-drop.strategy'; |
| 9 | +import { |
| 10 | + IgxDragDropModule, |
| 11 | + IgxDragDirective, |
| 12 | + IgxDropDirective, |
| 13 | + IgxDragLocation, |
| 14 | + IDropDroppedEventArgs, |
| 15 | + DragDirection |
| 16 | +} from './drag-drop.directive'; |
9 | 17 |
|
10 | 18 | describe('General igxDrag/igxDrop', () => {
|
11 | 19 | let fix: ComponentFixture<TestDragDropComponent>;
|
@@ -37,10 +45,14 @@ describe('General igxDrag/igxDrop', () => {
|
37 | 45 | });
|
38 | 46 |
|
39 | 47 | it('should correctly initialize drag and drop directives.', () => {
|
| 48 | + const ignoredElem = fix.debugElement.query(By.css('.ignoredElem')).nativeElement; |
| 49 | + |
40 | 50 | expect(fix.componentInstance.dragElems.length).toEqual(3);
|
41 | 51 | expect(fix.componentInstance.dragElems.last.data).toEqual({ key: 3 });
|
42 | 52 | expect(fix.componentInstance.dropArea).toBeTruthy();
|
43 | 53 | expect(fix.componentInstance.dropArea.data).toEqual({ key: 333 });
|
| 54 | + expect(fix.componentInstance.dragElems.last.dragIgnoredElems.length).toEqual(1); |
| 55 | + expect(fix.componentInstance.dragElems.last.dragIgnoredElems.first.element.nativeElement).toEqual(ignoredElem); |
44 | 56 | });
|
45 | 57 |
|
46 | 58 | it('should create drag ghost element and trigger ghostCreate/ghostDestroy.', (async() => {
|
@@ -257,6 +269,70 @@ describe('General igxDrag/igxDrop', () => {
|
257 | 269 | await wait();
|
258 | 270 | }));
|
259 | 271 |
|
| 272 | + it('should move ghost only horizontally when drag direction is set to horizontal.', (async() => { |
| 273 | + const firstDrag = fix.componentInstance.dragElems.first; |
| 274 | + const firstElement = firstDrag.element.nativeElement; |
| 275 | + const startingX = (dragDirsRects[0].left + dragDirsRects[0].right) / 2; |
| 276 | + const startingY = (dragDirsRects[0].top + dragDirsRects[0].bottom) / 2; |
| 277 | + firstDrag.dragDirection = DragDirection.HORIZONTAL; |
| 278 | + |
| 279 | + // Step 1. |
| 280 | + UIInteractions.simulatePointerEvent('pointerdown', firstElement, startingX, startingY); |
| 281 | + fix.detectChanges(); |
| 282 | + await wait(); |
| 283 | + |
| 284 | + // Step 2. |
| 285 | + UIInteractions.simulatePointerEvent('pointermove', firstElement, startingX + 10, startingY + 10); |
| 286 | + fix.detectChanges(); |
| 287 | + await wait(100); |
| 288 | + |
| 289 | + // Step 3. |
| 290 | + UIInteractions.simulatePointerEvent('pointermove', firstDrag.ghostElement, startingX + 20, startingY + 20); |
| 291 | + fix.detectChanges(); |
| 292 | + await wait(100); |
| 293 | + |
| 294 | + // We compare the base position and the new position + how much the mouse has moved. |
| 295 | + expect(firstDrag.ghostElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left + 20); |
| 296 | + expect(firstDrag.ghostElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top); |
| 297 | + |
| 298 | + // Step 4. |
| 299 | + UIInteractions.simulatePointerEvent('pointerup', firstDrag.ghostElement, startingX + 20, startingY + 20); |
| 300 | + fix.detectChanges(); |
| 301 | + await wait(); |
| 302 | + })); |
| 303 | + |
| 304 | + it('should move ghost only vertically when drag direction is set to vertical.', (async() => { |
| 305 | + const firstDrag = fix.componentInstance.dragElems.first; |
| 306 | + const firstElement = firstDrag.element.nativeElement; |
| 307 | + const startingX = (dragDirsRects[0].left + dragDirsRects[0].right) / 2; |
| 308 | + const startingY = (dragDirsRects[0].top + dragDirsRects[0].bottom) / 2; |
| 309 | + firstDrag.dragDirection = DragDirection.VERTICAL; |
| 310 | + |
| 311 | + // Step 1. |
| 312 | + UIInteractions.simulatePointerEvent('pointerdown', firstElement, startingX, startingY); |
| 313 | + fix.detectChanges(); |
| 314 | + await wait(); |
| 315 | + |
| 316 | + // Step 2. |
| 317 | + UIInteractions.simulatePointerEvent('pointermove', firstElement, startingX + 10, startingY + 10); |
| 318 | + fix.detectChanges(); |
| 319 | + await wait(100); |
| 320 | + |
| 321 | + // Step 3. |
| 322 | + UIInteractions.simulatePointerEvent('pointermove', firstDrag.ghostElement, startingX + 20, startingY + 20); |
| 323 | + fix.detectChanges(); |
| 324 | + await wait(100); |
| 325 | + |
| 326 | + // We compare the base position and the new position + how much the mouse has moved. |
| 327 | + expect(firstDrag.ghostElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left); |
| 328 | + expect(firstDrag.ghostElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top + 20); |
| 329 | + |
| 330 | + // Step 4. |
| 331 | + UIInteractions.simulatePointerEvent('pointerup', firstDrag.ghostElement, startingX + 20, startingY + 20); |
| 332 | + fix.detectChanges(); |
| 333 | + await wait(); |
| 334 | + })); |
| 335 | + |
260 | 336 | it('should position ghost relative to the mouse using offsetX and offsetY correctly.', (async() => {
|
261 | 337 | const firstDrag = fix.componentInstance.dragElems.first;
|
262 | 338 | const firstElement = firstDrag.element.nativeElement;
|
@@ -449,6 +525,88 @@ describe('General igxDrag/igxDrop', () => {
|
449 | 525 | expect(firstDrag.dragEnd.emit).toHaveBeenCalled();
|
450 | 526 | }));
|
451 | 527 |
|
| 528 | + it('should move igxDrag element only horizontally when ghost is disabled and direction is set to horizontal.', (async() => { |
| 529 | + const firstDrag = fix.componentInstance.dragElems.first; |
| 530 | + const firstElement = firstDrag.element.nativeElement; |
| 531 | + const startingX = (dragDirsRects[0].left + dragDirsRects[0].right) / 2; |
| 532 | + const startingY = (dragDirsRects[0].top + dragDirsRects[0].bottom) / 2; |
| 533 | + firstDrag.ghost = false; |
| 534 | + firstDrag.dragDirection = DragDirection.HORIZONTAL; |
| 535 | + fix.detectChanges(); |
| 536 | + |
| 537 | + // Step 1. |
| 538 | + UIInteractions.simulatePointerEvent('pointerdown', firstElement, startingX, startingY); |
| 539 | + fix.detectChanges(); |
| 540 | + await wait(); |
| 541 | + |
| 542 | + // Step 2. |
| 543 | + UIInteractions.simulatePointerEvent('pointermove', firstElement, startingX + 10, startingY + 10); |
| 544 | + fix.detectChanges(); |
| 545 | + await wait(100); |
| 546 | + |
| 547 | + expect(firstDrag.ghostElement).not.toBeDefined(); |
| 548 | + expect(firstElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left + 10); |
| 549 | + expect(firstElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top); |
| 550 | + |
| 551 | + // Step 3. |
| 552 | + UIInteractions.simulatePointerEvent('pointermove', firstElement, startingX + 20, startingY + 20); |
| 553 | + fix.detectChanges(); |
| 554 | + await wait(100); |
| 555 | + |
| 556 | + expect(firstDrag.ghostElement).not.toBeDefined(); |
| 557 | + expect(firstElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left + 20); |
| 558 | + expect(firstElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top); |
| 559 | + |
| 560 | + // Step 4. |
| 561 | + UIInteractions.simulatePointerEvent('pointerup', firstElement, startingX + 20, startingY + 20); |
| 562 | + fix.detectChanges(); |
| 563 | + await wait(); |
| 564 | + |
| 565 | + expect(firstElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left + 20); |
| 566 | + expect(firstElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top); |
| 567 | + })); |
| 568 | + |
| 569 | + it('should move igxDrag element only vertically when ghost is disabled and direction is set to vertical.', (async() => { |
| 570 | + const firstDrag = fix.componentInstance.dragElems.first; |
| 571 | + const firstElement = firstDrag.element.nativeElement; |
| 572 | + const startingX = (dragDirsRects[0].left + dragDirsRects[0].right) / 2; |
| 573 | + const startingY = (dragDirsRects[0].top + dragDirsRects[0].bottom) / 2; |
| 574 | + firstDrag.ghost = false; |
| 575 | + firstDrag.dragDirection = DragDirection.VERTICAL; |
| 576 | + fix.detectChanges(); |
| 577 | + |
| 578 | + // Step 1. |
| 579 | + UIInteractions.simulatePointerEvent('pointerdown', firstElement, startingX, startingY); |
| 580 | + fix.detectChanges(); |
| 581 | + await wait(); |
| 582 | + |
| 583 | + // Step 2. |
| 584 | + UIInteractions.simulatePointerEvent('pointermove', firstElement, startingX + 10, startingY + 10); |
| 585 | + fix.detectChanges(); |
| 586 | + await wait(100); |
| 587 | + |
| 588 | + expect(firstDrag.ghostElement).not.toBeDefined(); |
| 589 | + expect(firstElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left); |
| 590 | + expect(firstElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top + 10); |
| 591 | + |
| 592 | + // Step 3. |
| 593 | + UIInteractions.simulatePointerEvent('pointermove', firstElement, startingX + 20, startingY + 20); |
| 594 | + fix.detectChanges(); |
| 595 | + await wait(100); |
| 596 | + |
| 597 | + expect(firstDrag.ghostElement).not.toBeDefined(); |
| 598 | + expect(firstElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left); |
| 599 | + expect(firstElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top + 20); |
| 600 | + |
| 601 | + // Step 4. |
| 602 | + UIInteractions.simulatePointerEvent('pointerup', firstElement, startingX + 20, startingY + 20); |
| 603 | + fix.detectChanges(); |
| 604 | + await wait(); |
| 605 | + |
| 606 | + expect(firstElement.getBoundingClientRect().left).toEqual(dragDirsRects[0].left); |
| 607 | + expect(firstElement.getBoundingClientRect().top).toEqual(dragDirsRects[0].top + 20); |
| 608 | + })); |
| 609 | + |
452 | 610 | it('should prevent dragging if it does not exceed dragTolerance and ghost is disabled.', (async() => {
|
453 | 611 | const firstDrag = fix.componentInstance.dragElems.first;
|
454 | 612 | const firstElement = firstDrag.element.nativeElement;
|
@@ -1732,6 +1890,7 @@ const generalStyles = [`
|
1732 | 1890 | <div id="thirdDrag" class="dragElem" [igxDrag]="{ key: 3 }">
|
1733 | 1891 | Drag 3
|
1734 | 1892 | <div igxDragHandle class="dragHandle"></div>
|
| 1893 | + <div igxDragIgnore class="ignoredElem"></div> |
1735 | 1894 | </div>
|
1736 | 1895 | <ng-template #ghostTemplate>
|
1737 | 1896 | <div class="ghostElement">Drag Template</div>
|
|
0 commit comments