import { AsyncTable } from './async-table';

const AppTestMock = {
  httpClient: {
    get: () => {},
  },
  htmlHelpers: {
    parseResponse: () => {},
  },
  utilRegistry: {
    initAll: () => {},
  },
};

describe('AsyncTable', () => {

  let asyncTable;

  beforeEach(() => {
    const element = document.createElement('div');
    const scrollTable = document.createElement('div');
    const table = document.createElement('table');
    table.id = 'ident';
    scrollTable.classList.add('scrolltable');
    scrollTable.appendChild(table);
    element.appendChild(scrollTable);
    asyncTable = new AsyncTable(element, AppTestMock);
  });

  it('should create', () => {
    expect(asyncTable).toBeTruthy();
  });

  it('should throw if element does not contain a .scrolltable', () => {
    const element = document.createElement('div');
    expect(() => {
      new AsyncTable(element, AppTestMock);
    }).toThrow();
  });

  it('should throw if element does not contain a table', () => {
    const element = document.createElement('div');
    expect(() => {
      new AsyncTable(element, AppTestMock);
    }).toThrow();
  });

  it('should throw if called without an element', () => {
    expect(() => {
      new AsyncTable();
    }).toThrow();
  });
});
