Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

test/records/FieldDescriptor.js   A

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 76
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 76
rs 10
wmc 6
mnd 0
bc 6
fnc 6
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A FieldDescriptor.js ➔ describe(ꞌFieldDescriptorꞌ) 0 73 1
1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('FieldDescriptor', function(){
5
  
6
  it('Create plain', function(){
7
    assert.instanceOf(new GedcomX.FieldDescriptor(), GedcomX.FieldDescriptor, 'An instance of FieldDescriptor is not returned when calling the constructor with new.');
8
    assert.instanceOf(GedcomX.FieldDescriptor(), GedcomX.FieldDescriptor, 'An instance of FieldDescriptor is not returned when calling the constructor without new.');
9
  });
10
  
11
  it('Create with JSON', function(){
12
    var fd = GedcomX.FieldDescriptor({
13
      originalLabel: 'Name',
14
      descriptions: [
15
        { lang: 'en-US', value: 'Full Name' }
16
      ],
17
      values: [{
18
        optional: true,
19
        type: 'http://gedcomx.org/Original',
20
        labelId: 'name',
21
        displayLabels: [
22
          { lang: 'en-US', value: 'Name' }
23
        ]
24
      }]
25
    });
26
    assert.equal(fd.getOriginalLabel(), 'Name');
27
    assert.equal(fd.getDescriptions().length, 1);
28
    assert.equal(fd.getDescriptions()[0].getLang(), 'en-US');
29
    assert.equal(fd.getDescriptions()[0].getValue(), 'Full Name');
30
    assert.equal(fd.getValues().length, 1);
31
  });
32
  
33
  it('Build', function(){
34
    var fd = GedcomX.FieldDescriptor()
35
      .setOriginalLabel('Name')
36
      .addDescription({ lang: 'en-US', value: 'Full Name' })
37
      .addValue({
38
        optional: true,
39
        type: 'http://gedcomx.org/Original',
40
        labelId: 'name',
41
        displayLabels: [
42
          { lang: 'en-US', value: 'Name' }
43
        ]
44
      });
45
    assert.equal(fd.getOriginalLabel(), 'Name');
46
    assert.equal(fd.getDescriptions().length, 1);
47
    assert.equal(fd.getDescriptions()[0].getLang(), 'en-US');
48
    assert.equal(fd.getDescriptions()[0].getValue(), 'Full Name');
49
    assert.equal(fd.getValues().length, 1);
50
  });
51
  
52
  it('toJSON', function(){
53
    var data = {
54
      originalLabel: 'Name',
55
      descriptions: [
56
        { lang: 'en-US', value: 'Full Name' }
57
      ],
58
      values: [{
59
        optional: true,
60
        type: 'http://gedcomx.org/Original',
61
        labelId: 'name',
62
        displayLabels: [
63
          { lang: 'en-US', value: 'Name' }
64
        ]
65
      }]
66
    }, fvd = GedcomX.FieldDescriptor(data);
67
    assert.deepEqual(fvd.toJSON(), data);
68
  });
69
  
70
  it('constructor does not copy instances', function(){
71
    var obj1 = GedcomX.FieldDescriptor();
72
    var obj2 = GedcomX.FieldDescriptor(obj1);
73
    assert.strictEqual(obj1, obj2);
74
  });
75
  
76
});