<commit_before>/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import expect = require('expect.js');

import {
  simulate
} from 'simulate-event';

import {
  toArray
} from '../../../lib/algorithm/iteration';

import {
  JSONObject
} from '../../../lib/algorithm/json';

import {
  Message
} from '../../../lib/core/messaging';

import {
  commands
} from '../../../lib/ui/commands';

import {
  keymap
} from '../../../lib/ui/keymap';

import {
  Menu, MenuItem
} from '../../../lib/ui/menu';

import {
  Widget
} from '../../../lib/ui/widget';


// Set up a default command and its keybinding.
const DEFAULT_CMD = 'menu.spec.ts:defaultCmd';

commands.addCommand(DEFAULT_CMD, {
  execute: (args: JSONObject) => { return args; },
  label: 'LABEL',
  icon: 'foo',
  className: 'bar',
  isToggled: (args: JSONObject) => { return true; },
  mnemonic: 1
});

keymap.addBinding({
  keys: ['A'],
  selector: '*',
  command: DEFAULT_CMD
});


class LogMenu extends Menu {

  events: string[] = [];

  methods: string[] = [];

  handleEvent(event: Event): void {
    super.handleEvent(event);
    this.events.push(event.type);
  }

  protected onAfterAttach(msg: Message): void {
    super.onAfterAttach(msg);
    this.methods.push('onAfterAttach');
  }

  protected onBeforeDetach(msg: Message): void {
    super.onBeforeDetach(msg);
    this.methods.push('onBeforeDetach');
  }

  protected onUpdateRequest(msg: Message): void {
    super.onUpdateRequest(msg);
    this.methods.push('onUpdateRequest');
  }

  protected onCloseRequest(msg: Message): void {
    super.onCloseRequest(msg);
    this.methods.push('onCloseRequest');
  }
}


describe('ui/menu', () => {

  describe('MenuItem', () => {<commit_msg>ensure registrations are cleaned up<commit_after>/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2016, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import expect = require('expect.js');

import {
  simulate
} from 'simulate-event';

import {
  toArray
} from '../../../lib/algorithm/iteration';

import {
  JSONObject
} from '../../../lib/algorithm/json';

import {
  DisposableSet
} from '../../../lib/core/disposable';

import {
  Message
} from '../../../lib/core/messaging';

import {
  commands
} from '../../../lib/ui/commands';

import {
  keymap
} from '../../../lib/ui/keymap';

import {
  Menu, MenuItem
} from '../../../lib/ui/menu';

import {
  Widget
} from '../../../lib/ui/widget';


class LogMenu extends Menu {

  events: string[] = [];

  methods: string[] = [];

  handleEvent(event: Event): void {
    super.handleEvent(event);
    this.events.push(event.type);
  }

  protected onAfterAttach(msg: Message): void {
    super.onAfterAttach(msg);
    this.methods.push('onAfterAttach');
  }

  protected onBeforeDetach(msg: Message): void {
    super.onBeforeDetach(msg);
    this.methods.push('onBeforeDetach');
  }

  protected onUpdateRequest(msg: Message): void {
    super.onUpdateRequest(msg);
    this.methods.push('onUpdateRequest');
  }

  protected onCloseRequest(msg: Message): void {
    super.onCloseRequest(msg);
    this.methods.push('onCloseRequest');
  }
}


describe('ui/menu', () => {

  const DEFAULT_CMD = 'menu.spec.ts:defaultCmd';

  const disposables = new DisposableSet();

  before(() => {
    let cmd = commands.addCommand(DEFAULT_CMD, {
      execute: (args: JSONObject) => { return args; },
      label: 'LABEL',
      icon: 'foo',
      className: 'bar',
      isToggled: (args: JSONObject) => { return true; },
      mnemonic: 1
    });
    let kbd = keymap.addBinding({
      keys: ['A'],
      selector: '*',
      command: DEFAULT_CMD
    });
    disposables.add(cmd);
    disposables.add(kbd);
  });

  after(() => {
    disposables.dispose();
  });

  describe('MenuItem', () => {
{'fraction_non_alphanumeric': 0.23857276119402984, 'fraction_numerical': 0.0046641791044776115, 'mean_word_length': 2.366562009419152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6478423', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1305, 'n_words': 289}