import { BindingEngine, createBindingContext } from 'mframejs';



describe('BindingEngine.setValue', () => {

    // TODO: write better descriptios

    it('set simple value on empty #1', () => {
        const obj: any = createBindingContext({});
        BindingEngine.setValue(obj, 'name', 'per1');
        expect(obj.$context.name).toBe('per1');
    });


    it('set simple value on empty #2', () => {
        const obj: any = createBindingContext({});
        BindingEngine.setValue(obj, 'person.name', 'per2');
        expect(obj.$context.person.name).toBe('per2');
    });


    it('set simple value on empty #3', () => {
        const obj: any = createBindingContext({});
        BindingEngine.setValue(obj, 'group.person.name', 'per3');
        expect(obj.$context.group.person.name).toBe('per3');
    });


    it('set simple value on empty #4', () => {
        const obj = createBindingContext({});
        BindingEngine.setValue(obj, 'group.person.name', 'per4');
        expect(obj.$context.group.person.name).toBe('per4');
    });


    it('set simple value on empty #5', () => {
        const obj = createBindingContext({
            group: {
                otherPerson2: {
                    name: 'Awesome'
                }
            }
        });

        BindingEngine.setValue(obj, 'group.otherPerson1.name', 'per4');
        expect(obj.$context.group.otherPerson1.name).toBe('per4');
        expect(obj.$context.group.otherPerson2.name).toBe('Awesome');
    });


    it('set simple value on empty #6', () => {
        const obj = createBindingContext({
            group: {
                otherPerson2: {
                    name: 'Awesome'
                }
            }
        });
        BindingEngine.setValue(obj, 'group.otherPerson2.lastname', 'man');
        expect(obj.$context.group.otherPerson2.name).toBe('Awesome');
        expect(obj.$context.group.otherPerson2.lastname).toBe('man');
    });


    it('set simple value on empty #7', () => {
        const obj = createBindingContext({
            group: {
                otherPerson2: {
                    name: 'Awesome'
                }
            }
        });
        BindingEngine.setValue(obj, 'group.otherPerson2.name', 'man');
        BindingEngine.setValue(obj, 'group.otherPerson2.lastname', 'Awesome');
        expect(obj.$context.group.otherPerson2.name).toBe('man');
        expect(obj.$context.group.otherPerson2.lastname).toBe('Awesome');
    });



    it('set simple value on empty #8', () => {
        const obj = createBindingContext({
            group: {
                otherPerson2: {
                    name: 'Awesome'
                }
            }
        });
        BindingEngine.setValue(obj, 'group.otherPerson2', { it: 'test' });
        BindingEngine.setValue(obj, 'group.otherPerson2.lastname', 'Awesome');
        expect(obj.$context.group.otherPerson2.it).toBe('test');
        expect(obj.$context.group.otherPerson2.name).toBe(undefined);
        expect(obj.$context.group.otherPerson2.lastname).toBe('Awesome');
    });


    // add more



});
