it('should apply given map to each choices.', function () {
                var ref = new Reference('human_id'),
                    human = new Entity('human');

                human
                    .identifier(new Field('id'))
                    .editionView()
                        .addField(new Field('id').identifier(true));

                ref
                    .targetField(new Field('name').map(function (value, entry) {
                        return entry.name + '(' + entry.gender + ')';
                    }))
                    .targetEntity(human);

                ref.setEntries([
                    { id: 1, human_id: 1, name: 'Suna', gender: 'F'},
                    { id: 2, human_id: 2, name: 'Boby', gender: 'M'},
                    { id: 3, human_id: 1, name: 'Mizute', gender: 'M'}
                ]);

                expect(ref.type()).toEqual('Reference');
                expect(ref.choices()).toEqual([
                    { value: 1, label: 'Suna(F)'},
                    { value: 2, label: 'Boby(M)'},
                    { value: 3, label: 'Mizute(M)'}
                ]);
            });
            it('should retrieve choices.', function () {
                var ref = new Reference('human_id'),
                    human = new Entity('human');

                human
                    .identifier(new Field('id'))
                    .editionView()
                        .addField(new Field('id').identifier(true));

                ref
                    .targetField(new Field('name'))
                    .targetEntity(human);

                ref.setEntries([
                    { id: 1, human_id: 1, name: 'Suna'},
                    { id: 2, human_id: 2, name: 'Boby'},
                    { id: 3, human_id: 1, name: 'Mizute'}
                ]);

                expect(ref.type()).toEqual('Reference');
                expect(ref.choices()).toEqual([
                    { value: 1, label: 'Suna'},
                    { value: 2, label: 'Boby'},
                    { value: 3, label: 'Mizute'}
                ]);
            });
            it('should retrieve choices by id.', function () {
                var ref = new Reference('human_id'),
                    human = new Entity('human');

                human
                    .identifier(new Field('id'))
                    .editionView()
                        .addField(new Field('id').identifier(true));

                ref
                    .targetField(new Field('name'))
                    .targetEntity(human);

                ref.setEntries([
                    { id: 1, human_id: 1, name: 'Suna'},
                    { id: 2, human_id: 2, name: 'Boby'},
                    { id: 3, human_id: 1, name: 'Mizute'}
                ]);

                var choices = ref.getChoicesById();
                expect(ref.type()).toEqual('Reference');
                expect(choices[1]).toEqual('Suna');
                expect(choices[2]).toEqual('Boby');
                expect(choices[3]).toEqual('Mizute');
            });
Example #4
0
            it('should retrieve sortField', function () {
                var ref = new Reference('human_id'),
                    human = new Entity('human');

                ref.setEntries([
                    { id: 1, human_id: 1, name: 'Suna'},
                    { id: 2, human_id: 2, name: 'Boby'},
                    { id: 3, human_id: 1, name: 'Mizute'}
                ]);

                ref
                    .targetEntity(human)
                    .targetField(new Field('name'));

                human
                    .identifier(new Field('id'))
                    .editionView()
                      .addField(new Field('id').identifier(true));

                expect(ref.getSortFieldName()).toEqual('myView.name');
            });
        beforeEach(function () {
            config = function () {
                return {
                    baseApiUrl: angular.noop
                };
            };

            catEntity = new Entity('cat');
            humanEntity = new Entity('human');
            catView = catEntity.listView()
                .addField(new Field('id').identifier(true))
                .addField(new Field('name').type('text'))
                .addField(new Reference('human_id').targetEntity(humanEntity).targetField(new Field('firstName')));

            humanEntity.identifier(new Field('id'));

            rawCats = [{
                "id": 1,
                "human_id": 1,
                "name": "Mizoute",
                "summary": "A Cat"
            }, {
                "id": 2,
                "human_id": 1,
                "name": "Suna",
                "summary": "A little Cat"
            }];

            rawHumans = [{
                "id": 1,
                "firstName": "Daph"
            }, {
                "id": 2,
                "firstName": "Manu"
            }, {
                "id": 3,
                "firstName": "Daniel"
            }];
        });