/* globals expect */
describe('Button 3.3.7', () => {
  const descriptor = '/EAMD.ucp/Components/com/twitter/Bootstrap/Button/3.3.7/Button.component.xml';
  let Button, b1, b2, testDiv;

  it('should create a testDiv and get a Class ', async () => {
    testDiv = document.createElement('div');
    testDiv.classList.add('hidden');
    // testDiv.style.display='none';
    document.body.appendChild(testDiv);
    Button = await ONCE.dropSupport.loadDescriptor(descriptor);
  });

  it('testDiv element should be a div and Buttom class should exists', done => {
    expect(testDiv).to.be.an.instanceof(HTMLElement);
    expect(Button).to.be.an.instanceof(Function);
    done();
  });
  it('should create first instance of Button and add it into testDiv', done => {
    b1 = Button.getInstance().init();
    b1.name = 'button1';
    expect(b1).to.be.an('object');
    expect(b1).to.be.an.instanceof(Button);
    expect(b1).has.hasOwnProperty('name');
    expect(b1.name).to.be.equal('button1');

    b1.name = 'button1a';
    expect(b1.name).to.be.equal('button1a');

    expect(b1).has.hasOwnProperty('setButtonText');
    expect(b1.setButtonText).to.be.an.instanceof(Function);
    b1.setButtonText('this is the button1');

    expect(b1).has.hasOwnProperty('properties');
    expect(b1.properties).has.hasOwnProperty('text');
    expect(b1.properties.text).to.be.an('string');
    expect(b1.properties.text).to.be.equal('this is the button1');
    expect(b1).has.hasOwnProperty('setButtonType');
    expect(b1.setButtonType).to.be.an.instanceof(Function);
    b1.setButtonType('btn-primary');

    b1.defaultView.append(testDiv);
    // b1.itemView.append();

    done();
  });

  it('should create second instance of Button', done => {
    b2 = Button.getInstance().init();
    b2.name = 'button2';
    expect(b2).to.be.an('object');
    expect(b2).to.be.an.instanceof(Button);
    expect(b2).has.hasOwnProperty('name');
    expect(b2.name).to.be.equal('button2');
    b2.setButtonType('btn-success');
    b2.defaultView.append(testDiv);
    done();
  });

  it('should remove instances of Button and check testDiv for empty', done => {
    b1.defaultView.remove();
    b2.defaultView.remove();

    const views = UcpComponentSupport.getAllUcpViews();
    expect(views).to.be.an.instanceof(Array);
    expect(testDiv.innerHTML).to.be.empty;
    done();
  });

  after(done => {
    testDiv.remove();
    done();
  });

});
