/*global require,describe,module,beforeEach,inject,it,expect*/

define(function (require) {
    'use strict';

    var View = require('ng-admin/Main/component/service/config/view/View'),
        Action = require('ng-admin/Main/component/service/config/Action'),
        Field = require('ng-admin/Main/component/service/config/Field'),
        Entity = require('ng-admin/Main/component/service/config/Entity'),
        ReferenceMany = require('ng-admin/Main/component/service/config/ReferenceMany'),
        Reference = require('ng-admin/Main/component/service/config/Reference');

    describe("Service: View config", function () {

        it('should returns it\'s name.', function () {
            var view = new View('view-abx');

            expect(view.name()).toEqual('view-abx');
        });

        it('should returns a title and description from a function.', function () {
            var view = new View();
            view.title(function () {
                return 'my-title';
            });
            view.description(function () {
                return 'my desc';
            });

            expect(view.getTitle()).toEqual('my-title');
            expect(view.getDescription()).toEqual('my desc');
        });

        it('should add a return field types.', function () {
            var view = new View();
            var refMany = new ReferenceMany('refMany');
            var ref = new Reference('myRef');

            var field = new Field('body');

            view.addField(ref).addField(refMany).addField(field);

            expect(view.getFieldsOfType('ReferenceMany')['refMany'].name()).toEqual('refMany');
            expect(view.getReferences()['refMany'].name()).toEqual('refMany');
            expect(view.getReferences()['myRef'].name()).toEqual('myRef');
            expect(view.getFields()['body'].order()).toEqual(2);
        });

        it('should add actions.', function () {
            var view = new View();
            view.addAction(new Action('doSomething'));

            expect(view.getActions()['doSomething'].order()).toEqual(0);
        });

        it('should returns the identifier.', function () {
            var view = new View();
            view
                .addField(new Field('post_id').identifier(true))
                .addField(new Field('name').identifier(false));

            expect(view.identifier().name()).toEqual('post_id');
        });

        it('should map some raw entities', function () {
            var view = new View();
            view
                .addField(new Field('post_id').identifier(true))
                .addField(new Field('title'))
                .setEntity(new Entity());

            var entries = view.mapEntries([
                { post_id: 1, title: 'Hello', published: true},
                { post_id: 2, title: 'World', published: false},
                { post_id: 3, title: 'How to use ng-admin', published: false}
            ]);

            expect(entries.length).toEqual(3);
            expect(entries[0].identifierValue).toEqual(1);
            expect(entries[1].values.title).toEqual('World');
            expect(entries[1].values.published).toEqual(false);
        });

        it('should map some one entity when the identifier in not in the view', function () {
            var view = new View(),
                field = new Field('title'),
                entity = new Entity('posts');

            view
                .addField(field)
                .setEntity(entity);

            entity
                .identifier(new Field('post_id'));

            var entry = view.mapEntry({ post_id: 1, title: 'Hello', published: true});
            expect(entry.identifierValue).toEqual(1);
            expect(entry.values.title).toEqual('Hello');
        });

    });
});

@@ -847,24 +847,8 @@
 tion
- from a function
 .', 
@@ -923,163 +923,59 @@
 tle(
-function () %7B%0A                return 'my-title';%0A            %7D);%0A            view.description(function () %7B%0A                return 'my desc';%0A            %7D
+'my-title');%0A            view.description('my desc'
 );%0A%0A
@@ -1002,12 +1002,9 @@
 iew.
-getT
+t
 itle
@@ -1056,12 +1056,9 @@
 iew.
-getD
+d
 escr

Fix test