All files / platform/core/src/DICOMWeb getName.test.js

0% Statements 0/27
100% Branches 0/0
0% Functions 0/6
0% Lines 0/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                                                                                   
import getName from './getName';
 
describe('getName', () => {
  it('should return a default value if element is null or undefined', () => {
    const defaultValue = 'DEFAULT_NAME';
    const nullElement = null;
    const undefinedElement = undefined;
 
    expect(getName(nullElement, defaultValue)).toEqual(defaultValue);
    expect(getName(undefinedElement, defaultValue)).toEqual(defaultValue);
  });
 
  it('should return a default value if element.Value is null, undefined or not present', () => {
    const defaultValue = 'DEFAULT_NAME';
    const nullElement = {
      id: 0,
      Value: null,
    };
    const undefinedElement = {
      id: 0,
      Value: undefined,
    };
    const noValuePresentElement = {
      id: 0,
    };
 
    expect(getName(nullElement, defaultValue)).toEqual(defaultValue);
    expect(getName(undefinedElement, defaultValue)).toEqual(defaultValue);
    expect(getName(noValuePresentElement, defaultValue)).toEqual(defaultValue);
  });
 
  it('should return A for element when Alphabetic is [A, B, C, D]', () => {
    const returnValue = 'A';
    const element = {
      Value: [{ Alphabetic: 'A' }, { Alphabetic: 'B' }, { Alphabetic: 'C' }, { Alphabetic: 'D' }],
    };
    expect(getName(element, null)).toEqual(returnValue);
  });
 
  it('should return FIRST for element when Alphabetic is [FIRST, SECOND]', () => {
    const returnValue = 'FIRST';
    const element = {
      Value: [{ Alphabetic: 'FIRST' }, { Alphabetic: 'SECOND' }],
    };
    expect(getName(element, null)).toEqual(returnValue);
  });
 
  it('should return element.value[0] for element with not Alphabetic and when there is at least on element.Value', () => {
    const returnValue = {
      anyOtherProperty: 'FIRST',
    };
    const element = {
      Value: [{ anyOtherProperty: 'FIRST' }, { Alphabetic: 'SECOND' }],
    };
    expect(getName(element, null)).toEqual(returnValue);
  });
});