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

Field.js ➔ ... ➔ it(ꞌBuildꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 23
loc 23
rs 9.0856
1 View Code Duplication
var assert = require('chai').assert,
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    GedcomX = require('../../');
3
4
describe('Field', function(){
5
  
6
  it('Create plain', function(){
7
    assert.instanceOf(new GedcomX.Field(), GedcomX.Field, 'An instance of Field is not returned when calling the constructor with new.');
8
    assert.instanceOf(GedcomX.Field(), GedcomX.Field, 'An instance of Field is not returned when calling the constructor without new.');
9
  });
10
  
11
  it('Create with JSON', function(){
12
    var field = GedcomX.Field({
13
      id: 'nameField',
14
      type: 'http://gedcomx.org/Name',
15
      values: [
16
        {
17
          type: 'type',
18
          labelId: 'labelId',
19
          text: 'Text',
20
          confidence: 'http://gedcomx.org/High',
21
          datatype: 'data type',
22
          resource: '#resource'
23
        }
24
      ]
25
    });
26
    assert.equal(field.getId(), 'nameField');
27
    assert.equal(field.getType(), 'http://gedcomx.org/Name');
28
    assert.equal(field.getValues().length, 1);
29
    var fieldValue = field.getValues()[0];
30
    assert.equal(fieldValue.getType(), 'type');
31
    assert.equal(fieldValue.getLabelId(), 'labelId');
32
    assert.equal(fieldValue.getText(), 'Text');
33
    assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High');
34
    assert.equal(fieldValue.getDataType(), 'data type');
35
    assert.equal(fieldValue.getResource(), '#resource');
36
  });
37
  
38
  it('Build', function(){
39
    var field = GedcomX.Field()
40
      .setId('nameField')
41
      .setType('http://gedcomx.org/Name')
42
      .addValue({
43
        type: 'type',
44
        labelId: 'labelId',
45
        text: 'Text',
46
        confidence: 'http://gedcomx.org/High',
47
        datatype: 'data type',
48
        resource: '#resource'
49
      });
50
    assert.equal(field.getId(), 'nameField');
51
    assert.equal(field.getType(), 'http://gedcomx.org/Name');
52
    assert.equal(field.getValues().length, 1);
53
    var fieldValue = field.getValues()[0];
54
    assert.equal(fieldValue.getType(), 'type');
55
    assert.equal(fieldValue.getLabelId(), 'labelId');
56
    assert.equal(fieldValue.getText(), 'Text');
57
    assert.equal(fieldValue.getConfidence(), 'http://gedcomx.org/High');
58
    assert.equal(fieldValue.getDataType(), 'data type');
59
    assert.equal(fieldValue.getResource(), '#resource');
60
  });
61
  
62
  it('toJSON', function(){
63
    var data = {
64
      id: 'nameField',
65
      type: 'http://gedcomx.org/Name',
66
      values: [
67
        {
68
          type: 'type',
69
          labelId: 'labelId',
70
          text: 'Text',
71
          confidence: 'http://gedcomx.org/High',
72
          datatype: 'data type',
73
          resource: '#resource'
74
        }
75
      ]
76
    }, field = GedcomX.Field(data);
77
    assert.deepEqual(field.toJSON(), data);
78
  });
79
  
80
  it('constructor does not copy instances', function(){
81
    var obj1 = GedcomX.Field();
82
    var obj2 = GedcomX.Field(obj1);
83
    assert.strictEqual(obj1, obj2);
84
  });
85
  
86
});