angular-docs-cn/modules/angular2/test/render/dom/events/key_events_spec.ts

65 lines
2.6 KiB
TypeScript
Raw Normal View History

2015-05-26 12:25:39 -04:00
import {
describe,
ddescribe,
it,
iit,
xit,
xdescribe,
expect,
beforeEach,
el
} from 'angular2/test_lib';
import {KeyEventsPlugin} from 'angular2/src/render/dom/events/key_events';
export function main() {
describe('KeyEvents', () => {
it('should ignore unrecognized events', () => {
expect(KeyEventsPlugin.parseEventName('keydown')).toEqual(null);
expect(KeyEventsPlugin.parseEventName('keyup')).toEqual(null);
expect(KeyEventsPlugin.parseEventName('keydown.unknownmodifier.enter')).toEqual(null);
expect(KeyEventsPlugin.parseEventName('keyup.unknownmodifier.enter')).toEqual(null);
expect(KeyEventsPlugin.parseEventName('unknownevent.control.shift.enter')).toEqual(null);
expect(KeyEventsPlugin.parseEventName('unknownevent.enter')).toEqual(null);
});
it('should correctly parse event names', () => {
// key with no modifier
2015-05-26 12:25:39 -04:00
expect(KeyEventsPlugin.parseEventName('keydown.enter'))
.toEqual({'domEventName': 'keydown', 'fullKey': 'enter'});
expect(KeyEventsPlugin.parseEventName('keyup.enter'))
.toEqual({'domEventName': 'keyup', 'fullKey': 'enter'});
// key with modifiers:
2015-05-26 12:25:39 -04:00
expect(KeyEventsPlugin.parseEventName('keydown.control.shift.enter'))
.toEqual({'domEventName': 'keydown', 'fullKey': 'control.shift.enter'});
expect(KeyEventsPlugin.parseEventName('keyup.control.shift.enter'))
.toEqual({'domEventName': 'keyup', 'fullKey': 'control.shift.enter'});
// key with modifiers in a different order:
2015-05-26 12:25:39 -04:00
expect(KeyEventsPlugin.parseEventName('keydown.shift.control.enter'))
.toEqual({'domEventName': 'keydown', 'fullKey': 'control.shift.enter'});
expect(KeyEventsPlugin.parseEventName('keyup.shift.control.enter'))
.toEqual({'domEventName': 'keyup', 'fullKey': 'control.shift.enter'});
// key that is also a modifier:
2015-05-26 12:25:39 -04:00
expect(KeyEventsPlugin.parseEventName('keydown.shift.control'))
.toEqual({'domEventName': 'keydown', 'fullKey': 'shift.control'});
expect(KeyEventsPlugin.parseEventName('keyup.shift.control'))
.toEqual({'domEventName': 'keyup', 'fullKey': 'shift.control'});
2015-05-26 12:25:39 -04:00
expect(KeyEventsPlugin.parseEventName('keydown.control.shift'))
.toEqual({'domEventName': 'keydown', 'fullKey': 'control.shift'});
expect(KeyEventsPlugin.parseEventName('keyup.control.shift'))
.toEqual({'domEventName': 'keyup', 'fullKey': 'control.shift'});
});
it('should alias esc to escape', () => {
expect(KeyEventsPlugin.parseEventName('keyup.control.esc'))
.toEqual(KeyEventsPlugin.parseEventName('keyup.control.escape'));
});
});
}