<commit_before>describe('An ajax save module', function() {
  "use strict";

  var ajaxSave,
      element;

  beforeEach(function() {

    element = $('<form action="some/url">\
      <div class="js-status-message"></div>\
      <div id="edition_test_input">\
        <input type="text" name="test" value="prefilled value">\
      </div>\
      <div id="edition_another_input">\
        <input type="text" name="another" value="another value">\
      </div>\
      <input class="js-no-ajax" type="text" name="fake-file-input">\
      <input class="js-no-ajax" type="checkbox" name="remove-file-checkbox" value="1">\
      <input type="submit" class="js-save" value="Save">\
    </form>');

    $('body').append(element);
    ajaxSave = new GOVUKAdmin.Modules.AjaxSave();
    ajaxSave.start(element);
  });

  afterEach(function() {
    element.remove();
  });

  describe('when keying command+s', function() {
    beforeEach(function() {
      spyOn($, 'ajax');
    });

    it('attempts to save', function() {
      Mousetrap.trigger('command+s');
      expect($.ajax).toHaveBeenCalled();
    });

    describe('and save button is not visible', function() {
      it('does not save', function() {
        element.find('.js-save').hide();
        Mousetrap.trigger('command+s');
        expect($.ajax).not.toHaveBeenCalled();
      });
    });

    describe('and save button is disabled', function() {
      it('does not save', function() {<commit_msg>Add callback Spy to spec to prevent form submit<commit_after>describe('An ajax save module', function() {
  "use strict";

  var ajaxSave,
      element;

  beforeEach(function() {

    element = $('<form action="some/url">\
      <div class="js-status-message"></div>\
      <div id="edition_test_input">\
        <input type="text" name="test" value="prefilled value">\
      </div>\
      <div id="edition_another_input">\
        <input type="text" name="another" value="another value">\
      </div>\
      <input class="js-no-ajax" type="text" name="fake-file-input">\
      <input class="js-no-ajax" type="checkbox" name="remove-file-checkbox" value="1">\
      <input type="submit" class="js-save" value="Save">\
    </form>');

    $('body').append(element);
    ajaxSave = new GOVUKAdmin.Modules.AjaxSave();
    ajaxSave.start(element);

    var submitCallbackSpy = jasmine.createSpy('some/url').and.returnValue(false);
    element.submit(submitCallbackSpy);

  });

  afterEach(function() {
    element.remove();
  });

  describe('when keying command+s', function() {
    beforeEach(function() {
      spyOn($, 'ajax');
    });

    it('attempts to save', function() {
      Mousetrap.trigger('command+s');
      expect($.ajax).toHaveBeenCalled();
    });

    describe('and save button is not visible', function() {
      it('does not save', function() {
        element.find('.js-save').hide();
        Mousetrap.trigger('command+s');
        expect($.ajax).not.toHaveBeenCalled();
      });
    });

    describe('and save button is disabled', function() {
      it('does not save', function() {
{'fraction_non_alphanumeric': 0.188050930460333, 'fraction_numerical': 0.000652954619653934, 'mean_word_length': 3.1461434370771313, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '5512277', 'n_tokens_mistral': 982, 'n_tokens_neox': 949, 'n_words': 192}