<commit_before>if (typeof define !== 'function') { var define = require('amdefine')(module) }

define([
  '../shortcut-manager',
  '../keyboard-event-util',
  '../browser-event-util',
  './util'
],function(
  ShortcutManager,
  keyboardEventUtil,
  browserEventUtil,
  util
) {

  var noop = function() {};

  // - register handler when possible shortcut started

  describe('a shortcut', function() {

    var manager;
    var shortcut = ['Meta', 'S'];
    var keyPressEmulation;
    var blurCallbacks;
    beforeEach(function() {
      // move this out into util.js
      blurCallbacks = [];
      spyOn(browserEventUtil, 'onWindowBlur').andCallFake(function(fn) {
        blurCallbacks.push(fn);
      });

      keyPressEmulation = new util.KeyPressEmulation(keyboardEventUtil);

      manager = new ShortcutManager();
      manager.registerShortcut(shortcut, noop);
    });

    it('started by pressing first key: fire the registered callback', function() {
      var callback = jasmine.createSpy('callback');
      manager.onPossibleShortcut(callback);
      keyPressEmulation.keyDownByKeyName(shortcut[0]);
      expect(callback).toHaveBeenCalled();
    });

    it('complete shortcut pressed: the callback shall be called the number of keys in the shortcut', function() {
      var callback = jasmine.createSpy('callback');
      manager.onPossibleShortcut(callback);
      keyPressEmulation.pressByKeyNames(shortcut);
      expect(callback.callCount).toBe(shortcut.length);
    });

    describe('fire onShortcutEnd() callback', function(){

      it('when the shortcut is done', function() {
        var callback = jasmine.createSpy('callback');
        manager.onShortcutEnd(callback);
        keyPressEmulation.pressByKeyNames(shortcut);
        expect(callback).toHaveBeenCalled();
      });

      it('also when shortcut + some other key was pressed (an unregistered shortcut)', function() {
        // e.g. Meta+S is a valid shortcut
        // but  Meta+S+S is pressed, it should fire since the shortcut turned invalid
        var callback = jasmine.createSpy('callback');
        manager.onShortcutEnd(callback);
        var lastKeyName = shortcut[shortcut.length-1];
        keyPressEmulation.pressByKeyNames(shortcut.concat(lastKeyName));
        expect(callback).toHaveBeenCalled();
      });

      it('when just first key of shortcut was pressed', function() {<commit_msg>Add another test that wasn't covered before and would have broken while refactoring.<commit_after>if (typeof define !== 'function') { var define = require('amdefine')(module) }

define([
  '../shortcut-manager',
  '../keyboard-event-util',
  '../browser-event-util',
  './util'
],function(
  ShortcutManager,
  keyboardEventUtil,
  browserEventUtil,
  util
) {

  var noop = function() {};

  // - register handler when possible shortcut started

  describe('a shortcut', function() {

    var manager;
    var shortcut = ['Meta', 'S'];
    var keyPressEmulation;
    var blurCallbacks;
    beforeEach(function() {
      // move this out into util.js
      blurCallbacks = [];
      spyOn(browserEventUtil, 'onWindowBlur').andCallFake(function(fn) {
        blurCallbacks.push(fn);
      });

      keyPressEmulation = new util.KeyPressEmulation(keyboardEventUtil);

      manager = new ShortcutManager();
      manager.registerShortcut(shortcut, noop);
    });

    describe('onPossibleShortcut() should', function() {
      describe('fire', function() {
        it('started by pressing first key: fire the registered callback', function() {
          var callback = jasmine.createSpy('callback');
          manager.onPossibleShortcut(callback);
          keyPressEmulation.keyDownByKeyName(shortcut[0]);
          expect(callback).toHaveBeenCalled();
        });

        it('complete shortcut pressed: the callback shall be called the number of keys in the shortcut', function() {
          var callback = jasmine.createSpy('callback');
          manager.onPossibleShortcut(callback);
          keyPressEmulation.pressByKeyNames(shortcut);
          expect(callback.callCount).toBe(shortcut.length);
        });
      });

      describe('NOT fire', function() {
        it('when unregistered first key of a shortcut was pressed', function() {
          var callback = jasmine.createSpy('callback');
          manager.onPossibleShortcut(callback);
          keyPressEmulation.pressByKeyNames(['Alt']);
          expect(callback).not.toHaveBeenCalled();
        });
      });
    });

    describe('fire onShortcutEnd() callback', function(){

      it('when the shortcut is done', function() {
        var callback = jasmine.createSpy('callback');
        manager.onShortcutEnd(callback);
        keyPressEmulation.pressByKeyNames(shortcut);
        expect(callback).toHaveBeenCalled();
      });

      it('also when shortcut + some other key was pressed (an unregistered shortcut)', function() {
        // e.g. Meta+S is a valid shortcut
        // but  Meta+S+S is pressed, it should fire since the shortcut turned invalid
        var callback = jasmine.createSpy('callback');
        manager.onShortcutEnd(callback);
        var lastKeyName = shortcut[shortcut.length-1];
        keyPressEmulation.pressByKeyNames(shortcut.concat(lastKeyName));
        expect(callback).toHaveBeenCalled();
      });

      it('when just first key of shortcut was pressed', function() {
{'fraction_non_alphanumeric': 0.12362688512381308, 'fraction_numerical': 0.0007447402718301992, 'mean_word_length': 3.2001563721657544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '131947', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1453, 'n_words': 354}