/*
 * Copyright (c) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { TablePage } from '../../support/table.po';

describe('Table Container', () => {
  let page: TablePage;

  beforeEach(() => {
    page = new TablePage();
    page.navigateTo();
  });

  describe('Site', () => {
    it('should contain title', () => {
      cy.get('h2', { timeout: 10000 }).should('contain', 'Table');
    });
  });

  describe('when table has content', () => {
    it('should display the table', () => {
      expect(page.getTable().should('be.visible'));
    });

    it('should hide the empty table area', () => {
      expect(page.getEmptyTableArea().should('not.exist'));
    });

    it('should have rows', () => {
      page.getRows().should('have.length.gt', 0);
    });
  });

  describe('when table is empty', () => {
    beforeEach(() => {
      // wait for table to load
      // eslint-disable-next-line cypress/no-unnecessary-waiting
      cy.wait(4000);
      page.getContentToggle().click();
    });

    it('should show empty table area', () => {
      expect(page.getEmptyTableArea().should('be.visible'));
    });

    afterEach(() => {
      page.getContentToggle().click();
    });
  });

  describe('when table is column striped', () => {
    beforeEach(() => {
      page.getContentToggleStripes().click();
    });

    it('should show column stripes', () => {
      expect(page.getTable().should('have.class', 'table-striped-columns'));
    });

    afterEach(() => {
      page.getContentToggleStripes().click();
    });
  });

  describe('when table is default', () => {
    it('should show row stripes', () => {
      expect(page.getTable().should('not.have.class', 'table-striped-columns'));
    });
  });
});
