import { mulSplit, noop, sleep } from '../../../lib/shard'

describe('mulSplit function', () => {
  beforeAll(() => {
    jest.useFakeTimers()
  })
  it('should return a new array', () => {
    expect(mulSplit('a,b,c', ',')).toEqual(['a', 'b', 'c'])
  })

  it('return ["a", "b,c"] when cutting once', () => {
    expect(mulSplit('a,b,c', ',', 1)).toEqual(['a', 'b,c'])
  })

  it('return ["a", "b","c"] when cutting twice', () => {
    expect(mulSplit('a,b,c', ',', 2)).toEqual(['a', 'b', 'c'])
  })

  it('return ["a", "b","c"] when cutting three', () => {
    expect(mulSplit('a,b,c', ',', 3)).toEqual(['a', 'b', 'c'])
  })
})

describe('noop function', () => {
  expect(noop()).toBeUndefined()
})

describe('sleep function', () => {
  it('should be called only once when ', async () => {
    const fn = jest.fn()
    const act = sleep(500)
    act.then(fn)
    expect(fn).not.toBeCalled()
    jest.runAllTimers()
    await act
    expect(fn).toBeCalled()
  })
})
