<commit_before>"use strict";

var assert= require('assert')

describe('Zotero editing view', function () {
  var ZoteroItemView = require('../views/edit_zotero')
    , testData

  testData = {
    itemType: 'book',
    title: 'Living My Life',
    creators: [{ creatorType: 'author', firstName: 'Emma', lastName: 'Goldman' }],
    date: '1931'
  }

  it('should produce the same data that it was asked to render', function (done) {
    var view = new ZoteroItemView({ zoteroData: testData });

    view.on('updatedZoteroData', function (data) {
      assert.deepEqual(data, testData);
      done();
    });

    view.$('.zotero-entry').first().trigger('input');
  });

});<commit_msg>Use sinon.FakeXMLHttpRequest to test AJAX<commit_after>"use strict";

var assert = require('assert')
  , sinon = require('sinon')

global.sinon = sinon;
require('sinon-event');
require('sinon-fakexhr');

describe('Zotero editing view', function () {
  var ZoteroItemView = require('../views/edit_zotero')
    , requests = []
    , testData
    , xhr

  testData = {
    itemType: 'book',
    title: 'Living My Life',
    creators: [{ creatorType: 'author', firstName: 'Emma', lastName: 'Goldman' }],
    date: '1931'
  }

  before(function () {
    xhr = sinon.useFakeXMLHttpRequest();
    xhr.onCreate = function (xhr1) {
      requests.push(xhr1);
    }
  });

  it('should produce the same data that it was asked to render', function (done) {
    var view = new ZoteroItemView({ zoteroData: testData });

    requests.pop().respond(
      200, {"Content-type": "application/json"}, 
      JSON.stringify([{ creatorType: 'author', localized: 'Author' }]));

    view.on('updatedZoteroData', function (data) {
      assert.deepEqual(data, testData);
      done();
    });

    view.$('.zotero-entry').first().trigger('input');
  });

  after(function () {
    xhr.restore();
  });
});
{'fraction_non_alphanumeric': 0.17228464419475656, 'fraction_numerical': 0.006955591225254147, 'mean_word_length': 3.5060240963855422, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, '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': '5727137', 'n_tokens_mistral': 636, 'n_tokens_neox': 611, 'n_words': 140}