diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index f99639f..55dbf4e 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -9,8 +9,8 @@ import {HTMLEntitiesDecoder} from './converter/htmlentities-decoder'; import {HTMLEntitiesEncoder} from './converter/htmlentities-encoder'; import {Injectable} from '@angular/core'; import {NativeLibraryWrapperService} from './native-library-wrapper.service'; -import {PunycodeDecoder} from './converter/punycodedecoder'; -import {PunycodeEncoder} from './converter/punycodeencoder'; +import {PunycodeDecoder} from './converter/punycode-decoder'; +import {PunycodeEncoder} from './converter/punycode-encoder'; import {QuotedPrintableDecoder} from './converter/quotedprintabledecoder'; import {QuotedPrintableEncoder} from './converter/quotedprintableencoder'; import {ROT13Converter} from './converter/rot13converter'; diff --git a/src/app/converter/punycode-decoder.spec.ts b/src/app/converter/punycode-decoder.spec.ts new file mode 100644 index 0000000..12c21e9 --- /dev/null +++ b/src/app/converter/punycode-decoder.spec.ts @@ -0,0 +1,27 @@ +import {PunycodeDecoder} from './punycode-decoder'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('PunycodeDecoder', () => { + let nativeWrapperSpy: Partial; + let decodeSpy: Spy; + beforeEach(() => { + nativeWrapperSpy = {punycode: createSpyObj(['decode'])}; + decodeSpy = nativeWrapperSpy.punycode.decode as Spy; + }); + it('should create an instance', () => { + expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy(); + }); + it('should have the id "decodepunycode"', () => { + expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('decodepunycode'); + }); + it('should call through to the native punycode decoder', () => { + const testInput = 'My input'; + const expectedOutput = 'It worked'; + decodeSpy.and.returnValue(expectedOutput); + const result: string = new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput); + expect(result).toEqual(expectedOutput); + expect(decodeSpy).toHaveBeenCalledWith(testInput); + }); +}); diff --git a/src/app/converter/punycodedecoder.ts b/src/app/converter/punycode-decoder.ts similarity index 100% rename from src/app/converter/punycodedecoder.ts rename to src/app/converter/punycode-decoder.ts diff --git a/src/app/converter/punycode-encoder.spec.ts b/src/app/converter/punycode-encoder.spec.ts new file mode 100644 index 0000000..9da3d8a --- /dev/null +++ b/src/app/converter/punycode-encoder.spec.ts @@ -0,0 +1,27 @@ +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; + 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); + }); +}); diff --git a/src/app/converter/punycodeencoder.ts b/src/app/converter/punycode-encoder.ts similarity index 100% rename from src/app/converter/punycodeencoder.ts rename to src/app/converter/punycode-encoder.ts