import { newSpecPage } from '@stencil/core/testing';
import { BsChartTable } from '../bs-chart-table';
import { faker } from '@faker-js/faker';
import { queryByText } from '@testing-library/dom';
import { getMockData } from '../../../utils/chartHelpers';
const title = faker.random.words();
const { datasets, datapointLabels } = getMockData(faker);
describe('bs-chart-table', () => {
  let page;
  let comp;
  let table;
  let titleRow;
  let columnLabels;
  let dataRows;
  beforeEach(async () => {
    page = await newSpecPage({
      components: [BsChartTable],
      html: `<bs-chart-table table-title="${title}"></bs-chart-table>`,
    });
    comp = page.root;
    comp.data = datasets;
    comp.dataIdxLabels = datapointLabels;
    table = comp.shadowRoot.firstElementChild;
    await page.waitForChanges();
    const headRows = table.querySelectorAll('thead tr');
    titleRow = headRows[0];
    columnLabels = headRows[1];
    dataRows = table.querySelectorAll('tbody tr');
  });
  it('renders title', async () => {
    expect(table.getAttribute('summary')).toBe(title);
    expect(queryByText(table, title)).toBeTruthy();
    expect(titleRow.querySelector('th').getAttribute('colspan')).toBe(`${datapointLabels.length + 1}`);
  });
  it('renders the correct number of rows', async () => {
    expect(dataRows.length).toBe(datasets.length);
  });
  it('renders the correct number of columns', async () => {
    const columns = columnLabels.querySelectorAll('th');
    expect(columns.length).toBe(datapointLabels.length + 1);
  });
  it('renders the dataset column with correct content', async () => {
    dataRows.forEach((row, i) => {
      const rowHeader = row.querySelector('th');
      const expectedLabel = datasets[i].label;
      expect(queryByText(rowHeader, expectedLabel)).toBeTruthy();
    });
  });
  it('renders each dataset row with correct data', async () => {
    dataRows.forEach((row, datasetIdx) => {
      const rowData = row.querySelectorAll('td');
      rowData.forEach((cell, datapointIdx) => {
        const expectedData = datasets[datasetIdx].data[datapointIdx];
        expect(queryByText(cell, expectedData)).toBeTruthy();
      });
    });
  });
});
//# sourceMappingURL=bs-chart-table.spec.js.map
