import {NativeLibraryWrapperService} from '../native-library-wrapper.service';
import {PunycodeEncoder} from './punycode-encoder';
import createSpyObj = jasmine.createSpyObj;
import Spy = jasmine.Spy;

describe('PunycodeEncoder', () => {
  let nativeWrapperSpy: Partial<NativeLibraryWrapperService>;
  let encodeSpy: Spy;
  beforeEach(() => {
    nativeWrapperSpy = {punycode: createSpyObj(['encode'])};
    encodeSpy = nativeWrapperSpy.punycode.encode as Spy;
  });
  it('should create an instance', () => {
    expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
  });
  it('should have the id "encodepunycode"', () => {
    expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('encodepunycode');
  });
  it('should call through to the native punycode encoder', () => {
    const testInput = 'My input';
    const expectedOutput = 'It worked';
    encodeSpy.and.returnValue(expectedOutput);
    const result: string = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
    expect(result).toEqual(expectedOutput);
    expect(encodeSpy).toHaveBeenCalledWith(testInput);
  });
});