|
1 |
| -import { ChipsSampleComponent } from './../../../../../src/app/chips/chips.sample'; |
| 1 | +import { ChipsSampleComponent } from './../../../../../src/app/chips/chips.sample'; |
2 | 2 | import { Component, ViewChild, ViewChildren, QueryList } from '@angular/core';
|
3 | 3 | import {
|
4 | 4 | async,
|
@@ -555,6 +555,17 @@ describe('IgxChipsArea', () => {
|
555 | 555 | });
|
556 | 556 | });
|
557 | 557 |
|
| 558 | + it('should be able to select chip using api when selectable is set to false', () => { |
| 559 | + const fix = TestBed.createComponent(TestChipComponent); |
| 560 | + fix.detectChanges(); |
| 561 | + |
| 562 | + const selectedChip = fix.componentInstance.chipsArea.chipsList.toArray()[0]; |
| 563 | + selectedChip.selected = true; |
| 564 | + fix.detectChanges(); |
| 565 | + |
| 566 | + expect(selectedChip.selected).toBe(true); |
| 567 | + }); |
| 568 | + |
558 | 569 | it('should focus on chip correctly', () => {
|
559 | 570 | const fix = TestBed.createComponent(TestChipComponent);
|
560 | 571 | fix.detectChanges();
|
@@ -600,7 +611,7 @@ describe('IgxChipsArea', () => {
|
600 | 611 | expect(document.activeElement).toBe(firstChipComp.chipArea.nativeElement);
|
601 | 612 | });
|
602 | 613 |
|
603 |
| - it('should reorder chips when shift + leftarrow and shift + rightarrow is pressed', () => { |
| 614 | + it('should reorder chips when shift + leftarrow and shift + rightarrow is pressed', async(() => { |
604 | 615 | const leftKey = new KeyboardEvent('keydown', {
|
605 | 616 | 'key': 'ArrowLeft',
|
606 | 617 | shiftKey: true
|
@@ -651,9 +662,61 @@ describe('IgxChipsArea', () => {
|
651 | 662 | expect(firstChipLeft).toEqual(newFirstChipLeft);
|
652 | 663 | expect(newSecondChipLeft).toEqual(secondChipLeft);
|
653 | 664 | });
|
654 |
| - }); |
| 665 | + })); |
| 666 | + |
| 667 | + it('should reorder chips when shift + leftarrow is pressed and shift + rightarrow is pressed twice', async(() => { |
| 668 | + const fix = TestBed.createComponent(TestChipReorderComponent); |
| 669 | + fix.detectChanges(); |
| 670 | + |
| 671 | + const leftKey = new KeyboardEvent('keydown', { |
| 672 | + 'key': 'ArrowLeft', |
| 673 | + shiftKey: true |
| 674 | + }); |
| 675 | + const rightKey = new KeyboardEvent('keydown', { |
| 676 | + 'key': 'ArrowRight', |
| 677 | + shiftKey: true |
| 678 | + }); |
| 679 | + const chipAreaComponent = fix.componentInstance.chipsArea; |
| 680 | + const chipComponents = fix.debugElement.queryAll(By.directive(IgxChipComponent)); |
| 681 | + const targetChip = chipComponents[2].componentInstance; |
| 682 | + const targetChipElem = targetChip.chipArea.nativeElement; |
| 683 | + |
| 684 | + targetChipElem.focus(); |
| 685 | + fix.detectChanges(); |
| 686 | + |
| 687 | + expect(document.activeElement).toBe(targetChipElem); |
| 688 | + expect(chipAreaComponent.chipsList.toArray()[2].id).toEqual('Town'); |
| 689 | + expect(chipAreaComponent.chipsList.toArray()[3].id).toEqual('FirstName'); |
| 690 | + |
| 691 | + document.activeElement.dispatchEvent(rightKey); |
| 692 | + fix.detectChanges(); |
| 693 | + |
| 694 | + fix.whenStable().then(() => { |
| 695 | + expect(document.activeElement).toBe(targetChipElem); |
| 696 | + expect(chipAreaComponent.chipsList.toArray()[2].id).toEqual('FirstName'); |
| 697 | + expect(chipAreaComponent.chipsList.toArray()[3].id).toEqual('Town'); |
| 698 | + |
| 699 | + document.activeElement.dispatchEvent(leftKey); |
| 700 | + fix.detectChanges(); |
| 701 | + |
| 702 | + return fix.whenStable(); |
| 703 | + }).then(() => { |
| 704 | + expect(document.activeElement).toBe(targetChipElem); |
| 705 | + expect(chipAreaComponent.chipsList.toArray()[2].id).toEqual('Town'); |
| 706 | + expect(chipAreaComponent.chipsList.toArray()[3].id).toEqual('FirstName'); |
655 | 707 |
|
656 |
| - it('should not reorder chips when shift + leftarrow and shift + rightarrow is pressed when the chip is going out of bounce', () => { |
| 708 | + document.activeElement.dispatchEvent(leftKey); |
| 709 | + fix.detectChanges(); |
| 710 | + |
| 711 | + return fix.whenStable(); |
| 712 | + }).then(() => { |
| 713 | + expect(document.activeElement).toBe(targetChipElem); |
| 714 | + expect(chipAreaComponent.chipsList.toArray()[2].id).toEqual('City'); |
| 715 | + expect(chipAreaComponent.chipsList.toArray()[3].id).toEqual('FirstName'); |
| 716 | + }); |
| 717 | + })); |
| 718 | + |
| 719 | + it('should not reorder chips for shift + leftarrow and shift + rightarrow when the chip is going out of bounce', async(() => { |
657 | 720 | const leftKey = new KeyboardEvent('keydown', {
|
658 | 721 | 'key': 'ArrowLeft',
|
659 | 722 | shiftKey: true
|
@@ -694,7 +757,7 @@ describe('IgxChipsArea', () => {
|
694 | 757 | expect(firstChipLeft).toEqual(newFirstChipLeft);
|
695 | 758 | expect(newlastChipLeft).toEqual(lastChipLeft);
|
696 | 759 | });
|
697 |
| - }); |
| 760 | + })); |
698 | 761 |
|
699 | 762 | it('should delete chip when delete button is pressed and chip is removable', () => {
|
700 | 763 | const deleteKey = new KeyboardEvent('keydown', {
|
@@ -736,7 +799,7 @@ describe('IgxChipsArea', () => {
|
736 | 799 | expect(chipComponents.length).toEqual(3);
|
737 | 800 | });
|
738 | 801 |
|
739 |
| - it('chip should persist selected state when it is dragged and dropped', () => { |
| 802 | + it('chip should persist selected state when it is dragged and dropped', async(() => { |
740 | 803 | const spaceKeyEvent = new KeyboardEvent('keydown', {
|
741 | 804 | 'key': ' '
|
742 | 805 | });
|
@@ -786,7 +849,7 @@ describe('IgxChipsArea', () => {
|
786 | 849 | const firstChip = chipComponents[0].componentInstance;
|
787 | 850 | expect(firstChip.selected).not.toBeTruthy();
|
788 | 851 | });
|
789 |
| - }); |
| 852 | + })); |
790 | 853 |
|
791 | 854 | it('should not fire any event of the chip area when attempting deleting of a chip', () => {
|
792 | 855 | const fix = TestBed.createComponent(TestChipComponent);
|
|
0 commit comments