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

test/records/Field.js   A

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 86
Function Count 6

Duplication

Duplicated Lines 86
Ratio 100 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B Field.js ➔ describe(ꞌFieldꞌ) 83 83 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
});