"use strict";

describe("morph", function() {
  var mockConfigurator = {
    configurationFor: function(name) {
      return {};
    },
    getRetrievers: function(name) {
      return {};
    },
    getConfAndDelegate: function(name, obj) {
      obj.attributes = {
        "pos" : {
          "long" : "Part of Speech",
          "short" : "pos",
          "values" : {
            "noun" : {
              "long" : "noun",
              "short" : "noun",
              "postag" : "n",
              "style" : {
                "color" : "black"
              }
            },
            "adj" : {
              "long" : "adjective",
              "short" : "adj",
              "postag" : "a",
              "style" : {
                "color" : "blue"
              }
            }
          }
        },
        "pers" : {
          "long" : "Person",
          "short" : "pers",
          "values" : {
            "1st" : {
              "long" : "first person",
              "short" : "1st",
              "postag" : "1"
            },
            "2nd" : {
              "long" : "second person",
              "short" : "2nd",
              "postag" : "2"
            }
          }
        }
      };
      obj.postagSchema = ['pos', 'pers'];
      obj.styledThrough = 'pos';
      obj.conf = {};
    }
  };

  var createTokens = function() {
    return {
      '01': {
        id: '01',
        string: 't1',
        morphology: {
          lemma: 'lemma1',
          postag: 'n-'
        }
      },
      '02': {
        id: '02',
        string: 't2',
        morphology: {
          lemma: 'lemma2',
          postag: 'a1'
        }
      }
    };
  };

  beforeEach(module("arethusa.core", function($provide) {
    $provide.value('configurator', mockConfigurator);
  }));

  beforeEach(module("arethusa.morph"));

  var morph;
  var state;
  beforeEach(inject(function(_morph_, _state_) {
    state = _state_;
    state.tokens = createTokens();
    morph = _morph_;
    morph.init();
  }));

  describe('this.postagToAttributes', function() {
    it('expands a postag to full key value pairs', function() {
      var form = { postag: 'a1' };
      var res  = { postag: 'a1', attributes: { pos: 'adj', pers: '1st' }};
      morph.postagToAttributes(form);
      expect(form).toEqual(res);
    });
  });
});

@@ -2172,23 +2172,34 @@
   = 
-%7B postag: 'a1',
+angular.extend(%7B%7D, form, %7B
  att
@@ -2235,16 +2235,17 @@
 '1st' %7D%7D
+)
 ;%0A      
@@ -2322,13 +2322,552 @@
 );%0A  %7D);
+%0A%0A  describe('this.attributesToPostag', function() %7B%0A    it('creates a postag string out of attributes', function() %7B%0A      var attrs = %7B pos: 'noun', pers: '2nd' %7D;%0A      var res = 'n2';%0A      var postag = morph.attributesToPostag(attrs);%0A      expect(postag).toEqual(res);%0A    %7D);%0A%0A    it('fills with - according to the postagSchema, when an attribute is undefined', function() %7B%0A      var attrs = %7B pers: '1st' %7D;%0A      var res = '-1';%0A      var postag = morph.attributesToPostag(attrs);%0A      expect(postag).toEqual(res);%0A    %7D);%0A  %7D);
 %0A%7D);%0A

Add spec for morph.attributesToPostag();