import { mount } from 'enzyme';
import React from 'react';
import { LegalName } from 'web-foundation';

describe('LegalName', function() {
    it('should correctly display the name', function() {
        const name = new LegalName.Model();

        name.fill({
            first: ' beans',
            last: ''
        });

        expect(name.displayName()).to.equal('beans');

        name.fill({
            first: '',
            last: 'beans '
        });

        expect(name.displayName()).to.equal('beans');

        name.fill({
            first: ' beans',
            last: ' McGee '
        });

        expect(name.displayName()).to.equal('beans McGee');
    });
});

describe('<LegalName />', function() {
    it('should initialize all nice like', function() {
        const wrapper = mount(
            <LegalName.View />
        );

        expect(wrapper.find('label')).to.have.length(1);
        expect(wrapper.find('label').text()).to.equal('Legal Name');
        expect(wrapper.find('input')).to.have.length(2);
    });

    it('should not have label if passed null', function() {
        const wrapper = mount(<LegalName.View label={ null } />);

        expect(wrapper.find('label')).to.have.length(0);
    });

    it('should propagate the model', function() {
        const model = new LegalName.Model({
                first: 'beans',
                last: 'mcGee'
            }),
            wrapper = mount(
                <LegalName.View model={ model } />
            ),
            node = wrapper.instance().node;

        expect(node.getElementsByTagName('input')[0].value)
            .to.equal('beans');
        expect(node.getElementsByTagName('input')[1].value)
            .to.equal('mcGee');
    });
});
