/*
 * Copyright (C) 2020 Robert Bosch GmbH Copyright (C) 2020 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

// tslint:disable:no-magic-numbers

import { NoValuePipe } from './no-value.pipe';

describe('NoValuePipe', () => {
  let pipe: NoValuePipe;
  const noValueSymbol = 'na';

  beforeEach(() => {
    pipe = new NoValuePipe(noValueSymbol);
  });

  [
    {
      value: null,
      expected: noValueSymbol,
    },
    {
      value: undefined,
      expected: noValueSymbol,
    },
    {
      value: '',
      expected: noValueSymbol,
    },
    {
      value: [],
      expected: noValueSymbol,
    },
    {
      value: NaN,
      expected: noValueSymbol,
    },
    {
      value: 0,
      expected: 0,
    },
    {
      value: 'string',
      expected: 'string',
    },
    {
      value: true,
      expected: true,
    },
    {
      value: new Date(2019, 8, 2),
      expected: new Date(2019, 8, 2),
    },
    {
      value: [1, 2],
      expected: [1, 2],
    },
    {
      value: { object: true },
      expected: { object: true },
    },
  ].forEach((elem) => {
    it(`should transform ${JSON.stringify(elem.value)}`, () => {
      expect(pipe.transform(elem.value)).toEqual(elem.expected);
    });
  });

  it('should overwrite default value', () => {
    const customSymbol = 'x';
    expect(pipe.transform(NaN, customSymbol)).not.toBe(noValueSymbol);
    expect(pipe.transform(NaN, customSymbol)).toBe(customSymbol);
  });

  it('should overwrite with an empty string as symbol', () => {
    const customSymbol = '';
    expect(pipe.transform(NaN, customSymbol)).not.toBe(noValueSymbol);
    expect(pipe.transform(NaN, customSymbol)).toBe(customSymbol);
  });
});
