import {
  currentPageForLoadingAfterDeleteAction,
  preparePathName,
} from './helpers';

describe('preparePathName must replace paramsUrlId with cardId', () => {
  test('current id = number and paramsUrlId = string', () => {
    expect(preparePathName('/assets/1', 1, '1')).toBe(`/assets/${1}`);
  });
  test('current id = number and paramsUrlId = string, but paramsUrlId not current id', () => {
    expect(preparePathName('/assets/WWW', 1, 'WWW')).toBe(`/assets/${1}`);
  });
  test('broken path without slash with current id and paramsUrlId = null', () => {
    expect(preparePathName('/assets', 1, null)).toBe(`/assets/${1}`);
  });
  test('broken path without slash with current id and paramsUrlId = null', () => {
    expect(preparePathName('/assets', 1, undefined)).toBe(`/assets/${1}`);
  });
  test('broken path without slash with current id and paramsUrlId', () => {
    expect(preparePathName('/assets', 1, null)).toBe(`/assets/${1}`);
  });
  test('current path and current id but paramsUrlId = null', () => {
    expect(preparePathName('/assets/2', 1, null)).not.toBe(`/assets/${1}`);
  });
});

describe('tests for current change page after delete action', () => {
  test('current page if table row count < 2', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 3,
        pageSize: 10,
        total: 31,
      },
      1,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).toBe(3);
  });
  test('current page if table row count < 1', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 3,
        pageSize: 10,
        total: 30,
      },
      1,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).toBe(3);
  });
  test('current page if table row count = 1', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 4,
        pageSize: 10,
        total: 30,
      },
      1,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).toBe(4);
  });
  test('current page if table row count > 1', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 4,
        pageSize: 10,
        total: 3123,
      },
      2,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).toBe(4);
  });
  test('not current page if table row count > 1', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 4,
        pageSize: 10,
        total: 3123,
      },
      2,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).not.toBe(5);
  });
  test('current page if table row count and pageSize === 25 > 1', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 4,
        pageSize: 25,
        total: 3123,
      },
      4,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).toBe(3);
  });
  test('dashboardItemLength equal selected item', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 4,
        pageSize: 25,
        total: 3123,
      },
      4,
      [1, 2, 3, 4],
      () => {},
    );
    expect(numberPage).toBe(3);
  });
  test('dashboardListLength not equal selected item', () => {
    const numberPage = currentPageForLoadingAfterDeleteAction(
      {
        current: 4,
        pageSize: 25,
        total: 3123,
      },
      4,
      [1, 2, 3, 4, 5],
      () => {},
    );
    expect(numberPage).not.toBe(3);
  });
});
