/* eslint-disable prefer-arrow-callback */
const jaja = require('../src/jaja');
describe.skip('Jaja', function JajaTests() {
  // POLYFILLS
  describe('console', function console() {
    assert.isDefined(jaja.console);
    assert.isFunction(jaja.console.assert);
  });

  // ARRAY
  describe('ArrayHelper', function ArrayHelper() {
    describe('new', function newArrayHelper() {
      it('should be a new ArrayHelper object.', function test() {
        assert.equal(jaja.array.constructor.name, 'ArrayHelper');
      });
    });

    describe('sum', function sum() {
      it('should return the sum of the numbers in the array', function test() {
        assert.equal(jaja.array.sum([1, 2, 3, 4, 5]), 15);
      });
    });

    describe('getAllIndexes', function getAllIndexes() {
      it('should return all the indexes of the number 2', function test() {
        const myArray = [0, 2, 0, 0, 2, 2, 5, 48, 1, 2, 4, 6, 34, 5, 3, 2];
        const indexesOfNumber2 = jaja.array.getAllIndexes(myArray, 2);
        assert.deepEqual(indexesOfNumber2, [1, 4, 5, 9, 15]);
      });
      it('should return empty array', function test() {
        const myArray = [0, 1, 2, 5, 12, 500];
        const indexesOfNumber2 = jaja.array.getAllIndexes(myArray, 46);
        assert.equal(indexesOfNumber2.length, 0);
      });
    });

    describe('findByProperty', function findByProperty() {
      it('should return the first object containing a "name" property with the value "foo"', function test() {
        const myArray = [0, 2, 0, { name: 'bar' }, 2, 5, 65, 48, 8, 9, { name: 'foo', info: 'bat' }, 11, 12, { name: 'foo', info: 'snafu' }, 3, 2];
        const myFooObject = jaja.array.findByProperty(myArray, 'name', 'foo', true);
        assert.deepEqual(myFooObject, { name: 'foo', info: 'bat' });
      });

      it('should throw an error', function test() {
        const myArray = [0, 2, 0, { name: 'bar' }];
        assert.throws(
          () => { jaja.array.findByProperty(myArray, 'name', 'uhoh', false); },
          Error,
          'Couldn\'t find object with property'
        );
      });

      it('should NOT throw an error. Should return null', function test() {
        const myArray = [0, 2, 0, { name: 'bar' }];
        const myUhohObject = jaja.array.findByProperty(myArray, 'name', 'uhoh', true);
        assert.isNull(myUhohObject);
      });
    });
    describe('findAllByProperty', function findAllByProperty() {
      it('should return an array of all objects containing a "name" property with the value "foo"', function test() {
        const myArray = [0, 2, 0, { name: 'bar' }, 9, { name: 'foo', info: 'bat' }, 11, 12, { name: 'foo', info: 'snafu' }, 3, 2];
        const myFooArray = jaja.array.findAllByProperty(myArray, 'name', 'foo', true);
        assert.deepEqual(myFooArray, [{ name: 'foo', info: 'bat' }, { name: 'foo', info: 'snafu' }]);
      });
    });

    describe('remove', function remove() {
      it('should remove all instances of the number 5 from the array', function test() {
        const myArray = [1, 2, 3, 4, 5, 5, 5, 6, 10, 'foo', '5', 4];
        jaja.array.remove(myArray, 5);
        assert.deepEqual(myArray, [1, 2, 3, 4, 6, 10, 'foo', '5', 4]);
      });

      it('should remove all instances of variables from the array', function test() {
        const myArray = [1, 2, true, 4, 5, '12', 10, 'foo', '5', 4, true, 'foo'];
        jaja.array.remove(myArray, '5', 'foo', true);
        assert.deepEqual(myArray, [1, 2, 4, 5, '12', 10, 4]);
      });

      it('should remove nothing from the array', function test() {
        const myArray = [1, 2, true, 4, 5, '12', 10, 'foo', '5', 4, true, 'foo'];
        jaja.array.remove(myArray, 1000);
        assert.deepEqual(myArray, [1, 2, true, 4, 5, '12', 10, 'foo', '5', 4, true, 'foo']);
      });

      // TODO: Make this test pass. Requires rewrite of Jaja.array.remove.
      it.skip('should remove objects from the array', function test() {
        const myArray = [1, 2, { number: 3 }];
        jaja.array.remove(myArray, { number: 3 });
        assert.deepEqual(myArray, [1, 2]);
      });
    });
  });
});
