MCPcopy Index your code
hub / github.com/angular/components / assertCorrectKeyboardInteraction

Function assertCorrectKeyboardInteraction

src/material/stepper/stepper.spec.ts:1626–1724  ·  view source on GitHub ↗

Asserts that keyboard interaction works correctly.

(
  fixture: ComponentFixture<{stepper: MatStepper}>,
  stepHeaders: DebugElement[],
  orientation: StepperOrientation,
)

Source from the content-addressed store, hash-verified

1624
1625/** Asserts that keyboard interaction works correctly. */
1626function 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

Callers 1

stepper.spec.tsFile · 0.85

Calls 3

dispatchKeyboardEventFunction · 0.85
_getFocusIndexMethod · 0.80
updateActiveItemMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…