import { validUsername, isExternal, validEmail, validCode, validPwd } from '@/utils/validate.js'

describe('Utils:validate', () => {
  it('validUsername', () => {
    expect(validUsername('admin')).toBe(true)
    expect(validUsername('editor')).toBe(true)
    expect(validUsername('xxxx')).toBe(false)
  })
  it('isExternal', () => {
    expect(isExternal('https://www.xichain.com.cn')).toBe(true)
    expect(isExternal('http://www.xichain.com.cn')).toBe(true)
    expect(isExternal('www.xichain.com.cn')).toBe(false)
    expect(isExternal('/index')).toBe(false)
    expect(isExternal('./index')).toBe(false)
    expect(isExternal('index')).toBe(false)
  })
  it('validEmail', () => {
    expect(validEmail('2345637@qq.com')).toBe(true)
    expect(validEmail('237542356')).toBe(false)
    expect(validEmail('world')).toBe(false)
  })
  it('validCode', () => {
    expect(validCode('123456')).toBe(true)
    expect(validCode('12345')).toBe(false)
    expect(validCode('1234567')).toBe(false)
    expect(validCode('com321')).toBe(false)
    expect(validCode('hellos')).toBe(false)
  })
  it('validPwd', () => {
    expect(validPwd('hellos')).toBe(true)
    expect(validPwd('z12345')).toBe(true)
    expect(validPwd('z12345678912345678')).toBe(true)
    expect(validPwd('z_12345')).toBe(true)
    expect(validPwd('z34ewr6_1234')).toBe(true)
    expect(validPwd('z1234')).toBe(false)
    expect(validPwd('237com')).toBe(false)
    expect(validPwd('237542356')).toBe(false)
  })
})
