<commit_before>var assert = require('chai').assert;
var sinon = require('sinon');
var localStorage = require('../../store/localStorage');

describe("storage/localStorage()", function() {
    var mockLocalStorage = {
        setItem: function (data, done) { },
        getItem: function (done) { },
        removeItem: function (done) { }
    }, mock;

    beforeEach(function() {
        mock = sinon.mock(mockLocalStorage)
    });

    it("is enabled", function() {
        var storage = localStorage(null, mockLocalStorage);

        assert.isTrue(storage.enabled());
    });

    it("is not enabled", function() {
        var storage = localStorage();

        assert.isFalse(storage.enabled());
    });

    it("adds data", function() {
        mock.expects('setItem').once();

        var storage = localStorage(null, mockLocalStorage);

        storage.add(null, function() { return []; });

        mock.verify();
    });

    it("removes data", function() {
        mock.expects('setItem').once();

        var storage = localStorage(null, mockLocalStorage);

        storage.remove(null, function() { return []; });

        mock.verify();
    });

    it("loads data", function() {
        mock.expects('getItem').once().returns('["test"]');

        var storage = localStorage(null, mockLocalStorage);

        var data = storage.load();

        assert.isArray(data);
        assert.deepEqual(data, ['test']);

        mock.verify();
    });

    it("loads invalid data", function() {
        mock.expects('getItem').once().returns('foo');

        var storage = localStorage(null, mockLocalStorage);

        storage.load();

        mock.verify();
    });

    it("loads when storage throws", function() {
        mock.expects('getItem').once().throws('foo');
<commit_msg>Test localstorage with real item<commit_after>var assert = require('chai').assert;
var sinon = require('sinon');
var localStorage = require('../../store/localStorage');
var createItem = typeof window !== 'undefined' ? window.carty.item : require('../../item');

describe("storage/localStorage()", function() {
    var mockLocalStorage = {
        setItem: function (data, done) { },
        getItem: function (done) { },
        removeItem: function (done) { }
    }, mock;

    beforeEach(function() {
        mock = sinon.mock(mockLocalStorage)
    });

    it("is enabled", function() {
        var storage = localStorage(null, mockLocalStorage);

        assert.isTrue(storage.enabled());
    });

    it("is not enabled", function() {
        var storage = localStorage();

        assert.isFalse(storage.enabled());
    });

    it("adds data", function() {
        mock.expects('setItem').once();

        var storage = localStorage(null, mockLocalStorage);

        storage.add(null, function() { return [createItem('Item')]; });

        mock.verify();
    });

    it("removes data", function() {
        mock.expects('setItem').once();

        var storage = localStorage(null, mockLocalStorage);

        storage.remove(null, function() { return [createItem('Item')]; });

        mock.verify();
    });

    it("loads data", function() {
        mock.expects('getItem').once().returns('["test"]');

        var storage = localStorage(null, mockLocalStorage);

        var data = storage.load();

        assert.isArray(data);
        assert.deepEqual(data, ['test']);

        mock.verify();
    });

    it("loads invalid data", function() {
        mock.expects('getItem').once().returns('foo');

        var storage = localStorage(null, mockLocalStorage);

        storage.load();

        mock.verify();
    });

    it("loads when storage throws", function() {
        mock.expects('getItem').once().throws('foo');

{'fraction_non_alphanumeric': 0.17397149771443937, 'fraction_numerical': 0.0, 'mean_word_length': 2.7349397590361444, 'pattern_counts': {'":': 0, '<': 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': '4309833', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1013, 'n_words': 211}