import { singleToplistData } from 'gatsby-core-theme/tests/factories/modules/toplist.factory';
import {
  capitalize,
  anchorLink,
  leftTrim,
  truncateString,
  getTwitterUsername,
  getLaunchDate,
  transformMetaTitle,
  getDate,
} from './strings';

describe('String helper component', () => {
  test('A letter to be uppercase', () => {
    expect(capitalize('capitalize')).toBe('Capitalize');
  });

  test("The whitespace from the link should be replaced with '-'", () => {
    expect(anchorLink('anchor tag')).toBe('anchor-tag');
  });
  test('If space on the left, trim the left, else trim multiple space in between', () => {
    expect(leftTrim(' trim left')).toBe('trim left');
    expect(leftTrim('trim multiple spaces')).toBe('trim multiple spaces');
  });
  test('Truncate the string based on the given number', () => {
    expect(truncateString('gzim', 2)).toBe('gz...');
  });
  test('If it is a space between the string cut it and truncate', () => {
    expect(truncateString('cut the string', 6)).toBe('cut...');
  });
  test('If the string is smaller than the number just return the string', () => {
    expect(truncateString('cut', 6)).toBe('cut');
  });
  test('Twitter helper', () => {
    expect(getTwitterUsername('https://twitter.com/LebronJames')).toBe('LebronJames');
  });
  test('Launch Date', () => {
    expect(getLaunchDate('2022-03-05')).toBe('2022');
  });
  test('Meta title data automatic', () => {
    const today = new Date();

    expect(
      transformMetaTitle(
        singleToplistData.items[0].items[0],
        '[OPERATOR_REVIEW_META_TITLE]',
        'operator'
      )
    ).toBe(`Slotum ${today.getFullYear()} 90% Bonus + 50 free spins`);
  });
  test('Meta title operator', () => {
    expect(transformMetaTitle(singleToplistData.items[0].items[0], 'Casino', 'operator')).toBe(
      'Casino'
    );
  });
  test('Meta title other types', () => {
    expect(transformMetaTitle(singleToplistData.items[0].items[0], 'Page', 'page')).toBe('Page');
  });

  test('Get date', () => {
    expect(getDate()).toBeTruthy();
  });
});
