@@ -10,6 +10,7 @@ import {ModifierKeys} from '@angular/cdk/testing';
1010import { browser , ElementFinder , Key } from 'protractor' ;
1111import { TestElement , TestKey } from '../test-element' ;
1212
13+ /** Maps the `TestKey` constants to Protractor's `Key` constants. */
1314const keyMap = {
1415 [ TestKey . BACKSPACE ] : Key . BACK_SPACE ,
1516 [ TestKey . TAB ] : Key . TAB ,
@@ -43,6 +44,24 @@ const keyMap = {
4344 [ TestKey . META ] : Key . META
4445} ;
4546
47+ /** Converts a `ModifierKeys` object to a list of Protractor `Key`s. */
48+ function toProtractorModifierKeys ( modifiers : ModifierKeys ) : string [ ] {
49+ const result : string [ ] = [ ] ;
50+ if ( modifiers . control ) {
51+ result . push ( Key . CONTROL ) ;
52+ }
53+ if ( modifiers . alt ) {
54+ result . push ( Key . ALT ) ;
55+ }
56+ if ( modifiers . shift ) {
57+ result . push ( Key . SHIFT ) ;
58+ }
59+ if ( modifiers . meta ) {
60+ result . push ( Key . META ) ;
61+ }
62+ return result ;
63+ }
64+
4665/** A `TestElement` implementation for Protractor. */
4766export class ProtractorElement implements TestElement {
4867 constructor ( readonly element : ElementFinder ) { }
@@ -87,12 +106,7 @@ export class ProtractorElement implements TestElement {
87106 rest = modifiersAndKeys ;
88107 }
89108
90- const modifierKeys = [
91- modifiers . control ? Key . CONTROL : '' ,
92- modifiers . alt ? Key . ALT : '' ,
93- modifiers . shift ? Key . SHIFT : '' ,
94- modifiers . meta ? Key . META : ''
95- ] . filter ( k => k ) ;
109+ const modifierKeys = toProtractorModifierKeys ( modifiers ) ;
96110 const keys = rest . map ( k => typeof k === 'string' ? k . split ( '' ) : [ keyMap [ k ] ] )
97111 . reduce ( ( arr , k ) => arr . concat ( k ) , [ ] )
98112 . map ( k => Key . chord ( ...modifierKeys , k ) ) ;
0 commit comments