<commit_before>import test from 'ava';
import R from 'ramda';
import { capture, decorateMenuWith, addCommand, bindUserAccelerators, rebindConflictedAccelerators } from './';


test('capture', t => {
  let storage = {};
  const config = { keymap: 'captured' };
  capture('keymap', storage)(config);

  t.is(storage.keymap, config.keymap);
});

test('decorateMenuWith', t => {
  const menu = [
    { submenu: [ 1, 2 ] },
    { submenu: [ 3, 4 ] }
  ];

  const actual = decorateMenuWith(R.multiply(10))(menu)
  const expected = [
    { submenu: [ 10, 20 ] },
    { submenu: [ 30, 40 ] }
  ];

  t.deepEqual(actual, expected);
});

test('addCommand if exists in predefined', t => {
  const predefined = [
    { role: 'about' },
    { label: 'LBL1', command: 'CMD1' },
    { type: 'separator' }
  ];
  const item = { label: 'LBL1', click() {} };

  const actual = addCommand(predefined)(item);
  const expected = { label: 'LBL1', click() {}, command: 'CMD1' };

  t.is(actual.command, expected.command);
});

test('dont addCommand if not exists in predefined', t => {
  const item = { label: 'LBL1', click() {} };

  const actual = addCommand([])(item);
  const expected = { label: 'LBL1', click() {}};

  t.is(actual.command, expected.command);
});

test('dont bindUserAccelerators if item doesnt have command prop', t => {
  const bindUserAcceleratorsFn = bindUserAccelerators({});
  const items = [
    { role: 'about' },
    { type: 'separator' }
  ];

  const actual = items.map(bindUserAcceleratorsFn);
  const expected = items;

  t.deepEqual(actual, expected);
});

test('bindUserAccelerators: users keymap has prio over default', t => {
  const bindUserAcceleratorsFn = bindUserAccelerators({
    userKeymapFn: R.always({ 'A': 'cmd' }),
    defaultKeymapFn: R.always({ 'B': 'cmd', 'C': 'cmd' }),
  });
  const item = { command: 'cmd' };

  const actual = bindUserAcceleratorsFn(item);
  const expected = { command: 'cmd', accelerator: 'A' };

  t.deepEqual(actual, expected);
});

test('bindUserAccelerators: default keymap is used when there is no suitable user keymap for relevand command', t => {
  const bindUserAcceleratorsFn = bindUserAccelerators({
    userKeymapFn: R.always({}),
    defaultKeymapFn: R.always({ 'B': 'cmd', 'C': 'cmd' }),
  });
  const item = { command: 'cmd' };

  const actual = bindUserAcceleratorsFn(item);
  const expected = { command: 'cmd', accelerator: 'B' };

  t.deepEqual(actual, expected);
});

test('rebindConflictedAccelerators: use another default accelerator if its conflicted', t => {
  const rebindConflictedAcceleratorsFn = rebindConflictedAccelerators({
    userKeymapFn: R.always({ 'CmdOrCtrl+Alt+Right': 'next-pane' }),
    defaultKeymapFn: R.always({
      'CmdOrCtrl+Alt+Right':   'next-tab',
      'ctrl+tab':              'next-tab',
      'CmdOrCtrl+Shift+Right': 'next-tab',
      'CmdOrCtrl+Shift+]':     'next-tab',
    }),
  });
  const items = [
    { command: 'next-tab', accelerator: 'CmdOrCtrl+Alt+Right' },
    { command: 'next-pane', accelerator: 'CmdOrCtrl+Alt+Right' },
  ];

  const actual = items.map(rebindConflictedAcceleratorsFn);
  const expected = [
    { command: 'next-tab', accelerator: 'ctrl+tab' },
    { command: 'next-pane', accelerator: 'CmdOrCtrl+Alt+Right' },
  ];

  t.deepEqual(actual, expected);
});<commit_msg>add more tests for rebindConflictedAccelerators()<commit_after>import test from 'ava';
import R from 'ramda';
import { capture, decorateMenuWith, addCommand, bindUserAccelerators, rebindConflictedAccelerators } from './';


test('capture', t => {
  let storage = {};
  const config = { keymap: 'captured' };
  capture('keymap', storage)(config);

  t.is(storage.keymap, config.keymap);
});

test('decorateMenuWith', t => {
  const menu = [
    { submenu: [ 1, 2 ] },
    { submenu: [ 3, 4 ] }
  ];

  const actual = decorateMenuWith(R.multiply(10))(menu)
  const expected = [
    { submenu: [ 10, 20 ] },
    { submenu: [ 30, 40 ] }
  ];

  t.deepEqual(actual, expected);
});

test('addCommand if exists in predefined', t => {
  const predefined = [
    { role: 'about' },
    { label: 'LBL1', command: 'CMD1' },
    { type: 'separator' }
  ];
  const item = { label: 'LBL1', click() {} };

  const actual = addCommand(predefined)(item);
  const expected = { label: 'LBL1', click() {}, command: 'CMD1' };

  t.is(actual.command, expected.command);
});

test('dont addCommand if not exists in predefined', t => {
  const item = { label: 'LBL1', click() {} };

  const actual = addCommand([])(item);
  const expected = { label: 'LBL1', click() {}};

  t.is(actual.command, expected.command);
});

test('dont bindUserAccelerators if item doesnt have command prop', t => {
  const bindUserAcceleratorsFn = bindUserAccelerators({});
  const items = [
    { role: 'about' },
    { type: 'separator' }
  ];

  const actual = items.map(bindUserAcceleratorsFn);
  const expected = items;

  t.deepEqual(actual, expected);
});

test('bindUserAccelerators: users keymap has prio over default', t => {
  const bindUserAcceleratorsFn = bindUserAccelerators({
    userKeymapFn: R.always({ 'A': 'cmd' }),
    defaultKeymapFn: R.always({ 'B': 'cmd', 'C': 'cmd' }),
  });
  const item = { command: 'cmd' };

  const actual = bindUserAcceleratorsFn(item);
  const expected = { command: 'cmd', accelerator: 'A' };

  t.deepEqual(actual, expected);
});

test('bindUserAccelerators: default keymap is used when there is no suitable user keymap for relevand command', t => {
  const bindUserAcceleratorsFn = bindUserAccelerators({
    userKeymapFn: R.always({}),
    defaultKeymapFn: R.always({ 'B': 'cmd', 'C': 'cmd' }),
  });
  const item = { command: 'cmd' };

  const actual = bindUserAcceleratorsFn(item);
  const expected = { command: 'cmd', accelerator: 'B' };

  t.deepEqual(actual, expected);
});

test('rebindConflictedAccelerators: ignore item wo/ "command" prop', t => {
  const rebindConflictedAcceleratorsFn = rebindConflictedAccelerators({});
  const items = [
    { role: 'about' },
    { type: 'separator' }
  ];

  const actual = items.map(rebindConflictedAcceleratorsFn);
  const expected = items;

  t.deepEqual(actual, expected);
});

test('rebindConflictedAccelerators: use another default accelerator if its conflicted', t => {
  const rebindConflictedAcceleratorsFn = rebindConflictedAccelerators({
    userKeymapFn: R.always({ 'CmdOrCtrl+Alt+Right': 'next-pane' }),
    defaultKeymapFn: R.always({
      'CmdOrCtrl+Alt+Right':   'next-tab',
      'ctrl+tab':              'next-tab',
      'CmdOrCtrl+Shift+Right': 'next-tab',
      'CmdOrCtrl+Shift+]':     'next-tab',
    }),
  });
  const items = [
    { command: 'next-tab', accelerator: 'CmdOrCtrl+Alt+Right' },
    { command: 'next-pane', accelerator: 'CmdOrCtrl+Alt+Right' },
  ];

  const actual = items.map(rebindConflictedAcceleratorsFn);
  const expected = [
    { command: 'next-tab', accelerator: 'ctrl+tab' },
    { command: 'next-pane', accelerator: 'CmdOrCtrl+Alt+Right' },
  ];

  t.deepEqual(actual, expected);
});
{'fraction_non_alphanumeric': 0.16964924838940587, 'fraction_numerical': 0.006012884753042233, 'mean_word_length': 4.004297994269341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '7157894', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2347, 'n_words': 550}