<commit_before>jest.unmock('../bindCommands');

import bindCommands from '../bindCommands';
import {toPairs, forEach, compose} from 'ramda';

const mockComponent = () => ({
  state: {
    visibles: [],
    history: [],
  },
  setState(obj) {
    const setThis = compose(
      forEach(pair => { this.state[pair[0]] = pair[1]; }),
      toPairs
    );
    setThis(obj);
  },
});

const mockCommands = {
  ls: (self, args) => `ls: ${args}`,
  lmao: (self, args) => `lmao: ${args}`,
};

describe('bindCommands()', () => {
  it('should bind commands to "this" and update the state', () => {
    const component = mockComponent();
    const finalCommands = bindCommands(mockCommands, component);

    compose(
      forEach(command => { command[1](['a', 'b']); }),
      toPairs
    )(finalCommands);

    expect(component.state).toEqual({
      history: ['ls', 'lmao'],
      visibles: [
        ['ls', 'ls: a,b'],
        ['lmao', 'lmao: a,b'],
      ],
    });
  });
});<commit_msg>solidfy tests<commit_after>jest.unmock('../bindCommands');

import bindCommands from '../bindCommands';
import {toPairs, forEach, compose} from 'ramda';

const mockComponent = () => ({
  state: {
    visibles: [],
    history: [],
  },
  setState(obj) {
    const setThis = compose(
      forEach(pair => { this.state[pair[0]] = pair[1]; }),
      toPairs
    );
    setThis(obj);
  },
});

describe('bindCommands()', () => {
  it('should bind commands to "this" and update the state', () => {
    const component = mockComponent();
    const mockCommands = {
      ls: (self, args) => `ls: ${args}`,
      lmao: (self, args) => `lmao: ${args}`,
    };

    const finalCommands = bindCommands(mockCommands, component);

    compose(
      forEach(command => { command[1](['a', 'b']); }),
      toPairs
    )(finalCommands);

    expect(component.state).toEqual({
      history: ['ls', 'lmao'],
      visibles: [
        ['ls', 'ls: a,b'],
        ['lmao', 'lmao: a,b'],
      ],
    });
  });

  it('does not update the state if the function returns undefined', () => {
    const component = mockComponent();
    const mockCommands = {
      clear: () => {},
    };

    const finalCommands = bindCommands(mockCommands, component);

    compose(
      forEach(command => { command[1](['a', 'b']); }),
      toPairs
    )(finalCommands);

    expect(component.state).toEqual({
      history: ['clear'],
      visibles: [],
    });
  });
});
{'fraction_non_alphanumeric': 0.2033898305084746, 'fraction_numerical': 0.0028937577511368336, 'mean_word_length': 2.896940418679549, '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': '6527693', 'n_tokens_mistral': 799, 'n_tokens_neox': 812, 'n_words': 173}