import React from 'src/React'

describe('createElement', function () {
    it('type', () => {
        var el = React.createElement('p', null, 'aaa')
        expect(el.type).toBe('p')
        expect(el.vtype).toBe(1)
        expect(el.props.children).toA('string')
        expect(el.props.children.length).toBe(3)
    })
    it('children', () => {
        var el = React.createElement('p', null, 'aaa', 'bbb', 'ccc')
        expect(el.props.children).toBe('aaabbbccc')

        el = React.createElement('p', null, null)
        expect(el.props.children.length).toBe(0)
        el = React.createElement('div',{key:'xxx'})
        
        expect(el.key).toBe('xxx')

        el = React.createElement('p', null, [])
        expect(el.props.children.length).toBe(0)


        el = React.createElement('p', {children: ["aaa","bbb"]})
        expect(el.props.children.length).toBe(6)

        el = React.createElement('p', null)
        expect(el.props.children.length).toBe(0)
    })
     it('Children.only', () => {
        var el = React.createElement('p', null, 'aaa', 'bbb', 'ccc')
        var a = React.Children.only(el)
        expect(a.type).toBe('p')
        expect(a.props.children).toBe('aaabbbccc'))

        el = React.createElement('p', null, null)
        expect(el.props.children.length).toBe(0)

        el = React.createElement('p', null, [])
        expect(el.props.children.length).toBe(0)
        expect(el.vtype).toBe(1)
        el = React.createElement('p', {children: ["aaa","bbb"]})
        expect(el.props.children.length).toBe(1)

        el = React.createElement('p', null)
        expect(el.props.children.length).toBe(0)
    })

    it('flatChildren', () => {
        var el = React.createElement('p', null, 'aaa', false, 'ccc')
        console.log(el)
        expect(el.props.children).toEqual( 'aaaccc' )

        var el = React.createElement('p', null, 'aaa', true, 'ccc')
        expect(el.props.children).toEqual( 'aaaccc' )
        

        var el = React.createElement('p', null, 'aaa', 111, 'ccc')
        expect(el.props.children).toEqual( 'aaa111ccc' )
        
        var el = React.createElement('p', null, 'aaa', '', 'ccc')
        expect(el.props.children).toEqual( 'aaaccc' )
        
     
        var el = React.createElement('p', null, 'aaa', 'ccc', '')
        expect(el.props.children).toEqual( 'aaaccc' )
        
         

        var el = React.createElement('p', null, 'aaa', '', 'ccc')
        expect(el.props.children).toEqual( 'aaaccc' )
        

        var el = React.createElement('p', null, 111, 222, 333)
        expect(el.props.children).toEqual( '111222333' )
        

        var el = React.createElement('p', null, 111, 'ddd', 333)
        expect(el.props.children).toEqual( '111ddd333' )
        


    })
    it('class render', () => {
        class A extends React.Component {
            render() {
                return <div id = "aaa" / >
            }
        }
        var el = React.createElement(A, {})
        expect(el.vtype).toBe(2)
        el = React.createElement(function(){}, {})
        expect(el.vtype).toBe(4)
        var obj = (new A()).render()
        expect(obj.props.children).toEqual([])
        expect(obj.props.id).toBe('aaa')
        expect(obj.props).toEqual({
            id: 'aaa',
            children: []
        })
        expect(obj.type).toEqual('div')
        expect(obj.key == null).toBe(true)
        expect(typeof obj._owner).toBe('object')




    })
})