<commit_before>import React from 'react';
import {mount} from 'enzyme';

import OpenCommitDialog from '../../lib/views/open-commit-dialog';

describe('OpenCommitDialog', function() {
  let atomEnv, commandRegistry;
  let app, wrapper, didAccept, didCancel;

  beforeEach(function() {
    atomEnv = global.buildAtomEnvironment();
    commandRegistry = atomEnv.commands;

    didAccept = sinon.stub();
    didCancel = sinon.stub();

    app = (
      <OpenCommitDialog
        commandRegistry={commandRegistry}
        didAccept={didAccept}
        didCancel={didCancel}
      />
    );
    wrapper = mount(app);
  });

  afterEach(function() {
    atomEnv.destroy();
  });

  const setTextIn = function(selector, text) {
    wrapper.find(selector).getDOMNode().getModel().setText(text);
  };

  describe('entering a commit sha', function() {
    it("updates the commit sha automatically if it hasn't been modified", function() {
      setTextIn('.github-CommitSha atom-text-editor', 'asdf1234');

      assert.equal(wrapper.instance().getCommitSha(), 'asdf1234');
    });

    it('does update the sha if it was modified automatically', function() {
      setTextIn('.github-CommitSha atom-text-editor', 'asdf1234');
      assert.equal(wrapper.instance().getCommitSha(), 'asdf1234');

      setTextIn('.github-CommitSha atom-text-editor', 'zxcv5678');
      assert.equal(wrapper.instance().getCommitSha(), 'zxcv5678');
    });
  });

  describe('open button enablement and error state', function() {
    it('disables the open button with no commit sha', function() {
      setTextIn('.github-CommitSha atom-text-editor', '');
      wrapper.update();

      assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
      assert.isFalse(wrapper.find('.error').exists());
    });

    it('disables the open button with an invalid commit sha', function() {
      setTextIn('.github-CommitSha atom-text-editor', 'NOOOPE');
      wrapper.update();

      assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
      assert.strictEqual(wrapper.find('.error').text(), 'Not a valid git commit identifier');
    });

    it('enables the open button when commit sha box is populated with a valid sha', function() {
      setTextIn('.github-CommitSha atom-text-editor', '<PASSWORD>');
      wrapper.update();

      assert.isFalse(wrapper.find('button.icon-commit').prop('disabled'));
      assert.isFalse(wrapper.find('.error').exists());
    });
  });

  it('calls the acceptance callback', function() {
    setTextIn('.github-CommitSha atom-text-editor', '<PASSWORD>1<PASSWORD>');

    wrapper.find('button.icon-commit').simulate('click');

    assert.isTrue(didAccept.calledWith({sha: 'abcd1234'}));
    wrapper.unmount();
  });

  it('calls the cancellation callback', function() {
    wrapper.find('button.github-CancelButton').simulate('click');
    assert.isTrue(didCancel.called);
    wrapper.unmount();
  });
});<commit_msg>add test for non existent commit<commit_after>import React from 'react';
import {mount} from 'enzyme';
import {cloneRepository, buildRepository} from '../helpers';

import OpenCommitDialog from '../../lib/views/open-commit-dialog';

describe('OpenCommitDialog', async function() {
  let atomEnv, commandRegistry;
  let app, wrapper, didAccept, didCancel;
  let repository, workdirPath;


  beforeEach(async function() {
    atomEnv = global.buildAtomEnvironment();
    commandRegistry = atomEnv.commands;

    didAccept = sinon.stub();
    didCancel = sinon.stub();
    workdirPath = await cloneRepository('three-files');
    repository = await buildRepository(workdirPath);

    app = (
      <OpenCommitDialog
        commandRegistry={commandRegistry}
        didAccept={didAccept}
        didCancel={didCancel}
        repository={repository}
      />
    );
    wrapper = mount(app);
  });

  afterEach(function() {
    atomEnv.destroy();
  });

  const setTextIn = function(selector, text) {
    wrapper.find(selector).getDOMNode().getModel().setText(text);
  };

  describe('entering a commit sha', function() {
    it("updates the commit sha automatically if it hasn't been modified", function() {
      setTextIn('.github-CommitSha atom-text-editor', 'asdf1234');

      assert.equal(wrapper.instance().getCommitSha(), 'asdf1234');
    });

    it('does update the sha if it was modified automatically', function() {
      setTextIn('.github-CommitSha atom-text-editor', 'asdf1234');
      assert.equal(wrapper.instance().getCommitSha(), 'asdf1234');

      setTextIn('.github-CommitSha atom-text-editor', 'zxcv5678');
      assert.equal(wrapper.instance().getCommitSha(), 'zxcv5678');
    });
  });

  describe('open button enablement and error state', function() {
    it('disables the open button with no commit sha', function() {
      setTextIn('.github-CommitSha atom-text-editor', '');
      wrapper.update();

      assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
      assert.isFalse(wrapper.find('.error').exists());
    });

    it('disables the open button with an invalid commit sha', function() {
      setTextIn('.github-CommitSha atom-text-editor', 'NOOOPE');
      wrapper.update();

      assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
      assert.strictEqual(wrapper.find('.error').text(), 'Not a valid git commit identifier');
    });

    it('disables open button when commit does not exist in repo', async function() {
      setTextIn('.github-CommitSha atom-text-editor', '<PASSWORD>');
      wrapper.update();
      wrapper.find('button.icon-commit').simulate('click');

      await assert.async.strictEqual(wrapper.update().find('.error').text(), 'Commit with that sha does not exist in this repository');
      assert.isTrue(wrapper.find('button.icon-commit').prop('disabled'));
    });


    it('enables the open button when commit sha box is populated with a valid sha', function() {
      setTextIn('.github-CommitSha atom-text-editor', 'abcd1<PASSWORD>');
      wrapper.update();

      assert.isFalse(wrapper.find('button.icon-commit').prop('disabled'));
      assert.isFalse(wrapper.find('.error').exists());
    });
  });

  it('calls the acceptance callback', async function() {
    const commit = await repository.getLastCommit();
    setTextIn('.github-CommitSha atom-text-editor', commit.sha);

    wrapper.find('button.icon-commit').simulate('click');

    await assert.async.isTrue(didAccept.calledWith({sha: commit.sha}));
    wrapper.unmount();
  });

  it('calls the cancellation callback', function() {
    wrapper.find('button.github-CancelButton').simulate('click');
    assert.isTrue(didCancel.called);
    wrapper.unmount();
  });
});
{'fraction_non_alphanumeric': 0.16179775280898875, 'fraction_numerical': 0.008089887640449439, 'mean_word_length': 3.8658892128279883, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '509703', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1908, 'n_words': 398}