import React from 'react'
import { mount } from 'enzyme'
import { CheckIcon as StyledCheckIcon } from '../icon/checkIcon'
import { CircleIcon as StyledCircleIcon } from '../icon/circleIcon'
import { Loader, LoaderLayoutMode } from './Loader'
jest.useFakeTimers()
describe('Loader', () => {
it('Should have a custom className', () => {
const customClassName = 'custom-loader'
const wrapper = mount()
expect(wrapper.hasClass(customClassName)).toBe(true)
})
it('Should have a custom size', () => {
const size = 100
const wrapper = mount()
expect(wrapper.find(StyledCircleIcon).prop('size')).toBe(size)
})
it('Should be fullscreen by default', () => {
const wrapper = mount()
expect(wrapper.find('.kirk-loader--fullScreen').exists()).toBe(true)
})
it('Should be inline when using the prop', () => {
const wrapper = mount()
expect(wrapper.find('.kirk-loader--inline').exists()).toBe(true)
})
it('Should use custom loading announcements', () => {
const wrapper = mount()
expect(wrapper.text()).toBe('localized custom loading')
})
it('Should use custom loaded announcements', () => {
const wrapper = mount()
expect(wrapper.text()).toBe('localized custom loaded')
})
it('Should override layoutMode when inline prop is set', () => {
const wrapper = mount()
expect(wrapper.find('.kirk-loader--inline').exists()).toBe(true)
})
it('Should use correctly inline layout mode', () => {
const wrapper = mount()
expect(wrapper.find('.kirk-loader--inline').exists()).toBe(true)
})
it('Should use correctly block layout mode', () => {
const wrapper = mount()
expect(wrapper.find('.kirk-loader--block').exists()).toBe(true)
})
it('Should use correctly fullscreen layout mode', () => {
const wrapper = mount()
expect(wrapper.find('.kirk-loader--fullScreen').exists()).toBe(true)
})
it('Should show the done icon', () => {
const wrapper = mount()
expect(wrapper.find(StyledCheckIcon).exists()).toBe(true)
})
it('Should fire the callback event when done', () => {
const callback = jest.fn()
const wrapper = mount()
wrapper.setProps({ done: true })
expect(callback).not.toBeCalled()
jest.advanceTimersByTime(1500)
expect(callback).toBeCalled()
})
})