import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import getPagepageData from '../../tests/factories/pages/default.factory.js';
import { formatDate, analyseCasinos, getGamblers } from './statistics-counter.js';

let pageData;
let statsCounter;

beforeEach(() => {
  pageData = getPagepageData();
  statsCounter = pageData?.sections?.header?.modules?.find(
    (modules) => modules?.name === 'statistics_counter'
  );
});
describe('Show Info Grid Component', () => {
  test('formatDate()', () => {
    expect(formatDate(pageData.siteSchema.organization_founding_date)).toBe('2016');
    expect(formatDate('2024-05-01')).toBe('2024');
  });
  test('analyseCasinos()', () => {
    expect(analyseCasinos(statsCounter.stats)).toBe(
      statsCounter.stats.default * statsCounter.stats.game_review
    );
    expect(analyseCasinos({ default: 2, game_review: 2 })).toBe(4);
  });
  test('getGamblers()', () => {
    expect(getGamblers(statsCounter.stats)).toBe(37638);
    expect(getGamblers({ default: 1, operator_review: 2 })).toBe(2);
  });
});
afterEach(() => {
  cleanup();
});
