{"size": 1804, "ext": "js", "max_stars_repo_path": "test/src/Tag/Tag.spec.js", "max_stars_repo_name": "DanielchenN/shineout", "max_stars_repo_stars_event_min_datetime": "2018-09-02T10:52:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T07:30:22.000Z", "max_issues_repo_path": "test/src/Tag/Tag.spec.js", "max_issues_repo_name": "PatricioPeng/shineout", "max_issues_repo_issues_event_min_datetime": "2018-09-14T09:38:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T06:03:50.000Z", "max_forks_repo_path": "test/src/Tag/Tag.spec.js", "max_forks_repo_name": "PatricioPeng/shineout", "max_forks_repo_forks_event_min_datetime": "2018-09-10T14:32:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T07:43:55.000Z"}
{"max_stars_count": 780, "max_issues_count": 128, "max_forks_count": 145, "avg_line_length": 30.5762711864, "max_line_length": 75, "alphanum_fraction": 0.5958980044}
import { mount } from 'enzyme'
import React from 'react'
import { Tag } from 'shineout'

/* global SO_PREFIX */
describe('Tag[onClose]', () => {
  test('should show close btn while onClose', () => {
    const wrapper = mount(<Tag onClose>Hello</Tag>)
    expect(wrapper.find(`.${SO_PREFIX}-tag-close-icon`)).toHaveLength(1)
  })
  test('should not render close default', () => {
    const wrapper = mount(<Tag>Hello</Tag>)
    expect(wrapper.find(`.${SO_PREFIX}-tag-close-icon`)).toHaveLength(0)
  })
  test('should call onClose while func', () => {
    const mockFn = jest.fn()
    const wrapper = mount(<Tag onClose={mockFn}>Hello</Tag>)
    wrapper.find(`div.${SO_PREFIX}-tag-close-icon`).simulate('click')
    expect(mockFn).toBeCalled()
  })
  test('should render loading when onClose promise', () => {
    jest.useFakeTimers()
    const mockFn = jest.fn()
    const wrapper = mount(
      <Tag
        onClose={() =>
          new Promise(resolve => {
            setTimeout(() => {
              mockFn()
              resolve(true)
            }, 3000)
          })
        }
      >
        Hello
      </Tag>
    )
    expect(wrapper.find(`.${SO_PREFIX}-tag-close-icon`)).toHaveLength(1)
    wrapper.find(`div.${SO_PREFIX}-tag-close-icon`).simulate('click')
    expect(wrapper.find(`.${SO_PREFIX}-tag-close-loading`)).toHaveLength(1)
    jest.runAllTimers()
    expect(mockFn).toBeCalled()
  })
})

describe('Tag[Disabled]', () => {
  test('should render disabled className', () => {
    const wrapper = mount(<Tag disabled>Disabled</Tag>)
    expect(wrapper.find(`.${SO_PREFIX}-tag-disabled`)).toHaveLength(1)
  })
})

describe('Tag[Input]', () => {
  test('should render input', () => {
    const wrapper = mount(<Tag.Input />)
    expect(wrapper.find('label input')).toHaveLength(1)
  })
})
