Asserts that keyboard interaction works correctly.
(
fixture: ComponentFixture<{stepper: MatStepper}>,
stepHeaders: DebugElement[],
orientation: StepperOrientation,
)
| 1624 | |
| 1625 | /** Asserts that keyboard interaction works correctly. */ |
| 1626 | function assertCorrectKeyboardInteraction( |
| 1627 | fixture: ComponentFixture<{stepper: MatStepper}>, |
| 1628 | stepHeaders: DebugElement[], |
| 1629 | orientation: StepperOrientation, |
| 1630 | ) { |
| 1631 | const stepper = fixture.componentInstance.stepper; |
| 1632 | const nextKey = orientation === 'vertical' ? DOWN_ARROW : RIGHT_ARROW; |
| 1633 | const prevKey = orientation === 'vertical' ? UP_ARROW : LEFT_ARROW; |
| 1634 | |
| 1635 | expect(stepper._getFocusIndex()).toBe(0); |
| 1636 | expect(stepper.selectedIndex).toBe(0); |
| 1637 | |
| 1638 | let stepHeaderEl = stepHeaders[0].nativeElement; |
| 1639 | dispatchKeyboardEvent(stepHeaderEl, 'keydown', nextKey); |
| 1640 | fixture.detectChanges(); |
| 1641 | |
| 1642 | expect(stepper._getFocusIndex()) |
| 1643 | .withContext('Expected index of focused step to increase by 1 after pressing the next key.') |
| 1644 | .toBe(1); |
| 1645 | expect(stepper.selectedIndex) |
| 1646 | .withContext('Expected index of selected step to remain unchanged after pressing the next key.') |
| 1647 | .toBe(0); |
| 1648 | |
| 1649 | stepHeaderEl = stepHeaders[1].nativeElement; |
| 1650 | dispatchKeyboardEvent(stepHeaderEl, 'keydown', ENTER); |
| 1651 | fixture.detectChanges(); |
| 1652 | |
| 1653 | expect(stepper._getFocusIndex()) |
| 1654 | .withContext('Expected index of focused step to remain unchanged after ENTER event.') |
| 1655 | .toBe(1); |
| 1656 | expect(stepper.selectedIndex) |
| 1657 | .withContext( |
| 1658 | 'Expected index of selected step to change to index of focused step ' + 'after ENTER event.', |
| 1659 | ) |
| 1660 | .toBe(1); |
| 1661 | |
| 1662 | stepHeaderEl = stepHeaders[1].nativeElement; |
| 1663 | dispatchKeyboardEvent(stepHeaderEl, 'keydown', prevKey); |
| 1664 | fixture.detectChanges(); |
| 1665 | |
| 1666 | expect(stepper._getFocusIndex()) |
| 1667 | .withContext( |
| 1668 | 'Expected index of focused step to decrease by 1 after pressing the ' + 'previous key.', |
| 1669 | ) |
| 1670 | .toBe(0); |
| 1671 | expect(stepper.selectedIndex) |
| 1672 | .withContext( |
| 1673 | 'Expected index of selected step to remain unchanged after pressing the ' + 'previous key.', |
| 1674 | ) |
| 1675 | .toBe(1); |
| 1676 | |
| 1677 | // When the focus is on the last step and right arrow key is pressed, the focus should cycle |
| 1678 | // through to the first step. |
| 1679 | (stepper as any)._keyManager.updateActiveItem(2); |
| 1680 | stepHeaderEl = stepHeaders[2].nativeElement; |
| 1681 | dispatchKeyboardEvent(stepHeaderEl, 'keydown', nextKey); |
| 1682 | fixture.detectChanges(); |
| 1683 |
no test coverage detected
searching dependent graphs…