/*
 * General specifications GridGallery
 * 1- creates a grid using elements that will be in different heights and widths
 * 2- will enable gallery view on click to an element of the grid (dialog)
 * 3- the dialog will trigger custom events to control data in dialog
 * 4- nav of items in grid (disable/enable) depending on initialization
 */

describe('GridGallery', function(){
  var x, options = { lightBox: true };
  var container;
  document.body.className = 'grid-gallery__example';

  beforeEach(function() {
    var wrapper = document.createElement('div');
    wrapper.className = 'container';


    container = document.createElement('div');
    container.className = 'grid-gallery';

    for (var i = 0; i < 5; i++) {
      var element = document.createElement('div');
      var p = document.createElement('p');
      p.textContent = 'lorem nav of items in grid (disable/enable) depending on initialization';
      element.className = 'grid-gallery__item grid-gallery__dummy';
      element.appendChild(p);
      container.appendChild(element);
    }

    wrapper.appendChild(container);
    document.body.appendChild(wrapper);

  });

  afterEach(function(){
    var oldContainer = document.querySelector('.container');
    oldContainer.parentNode.removeChild(oldContainer);
  });

  describe('GridGallery initialization', function(){

    it('Global must have the GridGallery as a property', function() {
      x = new GridGallery(container, options);
     expect(GridGallery).not.toBeUndefined();
    });

    it('should manipulate the default options to the created instance', function() {
      var div = document.createElement('div');
      var childs = document.createElement('div');
      childs.className = 'grid-gallery__item';
      div.appendChild(childs);
      var y = new GridGallery( div, {});
      expect(y.options).toEqual({'lightBox': false});
    });

    it('should extend the default options and icludes the new one', function() {
      x = new GridGallery(container, options);
      expect(x.options).toEqual({'lightBox': true});
    });

    it('should store the container as a property', function() {
      x = new GridGallery(container, options);
      expect(x.element).toEqual(container);
    });

    it('should have method init', function() {
      x = new GridGallery(container, options);
      expect(x.init).toBeDefined();
      expect(typeof x.init).toBe('function');
    });
  })

  describe('init() method', function() {
    it('should update the element and its childrens', function(){
      x = new GridGallery(container, options)
      expect(document.querySelector('.grid-gallery').offsetHeight).not.toBeLessThan(200);
      expect(document.querySelector('.grid-gallery__item').dataset.grid).toBe('true');
    });

    it('should update children positions', function() {
      var items;
      x = new GridGallery(container, options);

      items = document.body.querySelectorAll('.grid-gallery__item');
      for(var i = 0; i < items.length; i++) {
        expect(items[i].style.left).not.toBe('');
      }
    });
  });
});

@@ -3066,13 +3066,558 @@
 );%0A  %7D);
+%0A%0A  describe('Private Methods', function() %7B%0A    it('private _extend should be defined', function()%7B%0A      x = new GridGallery(container, options);%0A      expect(x.__test__.extend).toBeDefined();%0A    %7D);%0A%0A    it('private _extend should return an object after adding another one%5C's properties' , function()%7B%0A      x = new GridGallery(container, options);%0A      var obj1 = %7B%7D, obj2 = %7Bx: true%7D;%0A      expect(x.__test__.extend(obj1, obj2)).toEqual(obj2);%0A      obj2.y = 'hello';%0A      expect(x.__test__.extend(%7B%7D, obj2)).toEqual(obj2);%0A    %7D);%0A  %7D);
 %0A%7D);%0A

test for _extend method