From 0a6a397e2979fa018c5485302b5acb922d60e4fe Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:38:42 +0200 Subject: [PATCH] Fixed QuotedPrintable{De,En}coder file names and added tests. --- src/app/converter-registry.service.ts | 4 +-- .../quoted-printable-decoder.spec.ts | 33 +++++++++++++++++++ ...decoder.ts => quoted-printable-decoder.ts} | 0 .../quoted-printable-encoder.spec.ts | 33 +++++++++++++++++++ ...encoder.ts => quoted-printable-encoder.ts} | 0 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/quoted-printable-decoder.spec.ts rename src/app/converter/{quotedprintabledecoder.ts => quoted-printable-decoder.ts} (100%) create mode 100644 src/app/converter/quoted-printable-encoder.spec.ts rename src/app/converter/{quotedprintableencoder.ts => quoted-printable-encoder.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 55dbf4e..a4721c6 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -11,8 +11,8 @@ import {Injectable} from '@angular/core'; import {NativeLibraryWrapperService} from './native-library-wrapper.service'; import {PunycodeDecoder} from './converter/punycode-decoder'; import {PunycodeEncoder} from './converter/punycode-encoder'; -import {QuotedPrintableDecoder} from './converter/quotedprintabledecoder'; -import {QuotedPrintableEncoder} from './converter/quotedprintableencoder'; +import {QuotedPrintableDecoder} from './converter/quoted-printable-decoder'; +import {QuotedPrintableEncoder} from './converter/quoted-printable-encoder'; import {ROT13Converter} from './converter/rot13converter'; import {URIComponentDecoder} from './converter/uricomponentdecoder'; import {URIComponentEncoder} from './converter/uricomponentencoder'; diff --git a/src/app/converter/quoted-printable-decoder.spec.ts b/src/app/converter/quoted-printable-decoder.spec.ts new file mode 100644 index 0000000..15f8266 --- /dev/null +++ b/src/app/converter/quoted-printable-decoder.spec.ts @@ -0,0 +1,33 @@ +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import {QuotedPrintableDecoder} from './quoted-printable-decoder'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('QuotedPrintableDecoder', () => { + let sut: QuotedPrintableDecoder; + let nativeWrapperSpy: Partial; + let decodeSpy: Spy; + + beforeEach(() => { + nativeWrapperSpy = {quotedPrintable: createSpyObj(['decode'])}; + decodeSpy = nativeWrapperSpy.quotedPrintable.decode as Spy; + sut = new QuotedPrintableDecoder((nativeWrapperSpy as NativeLibraryWrapperService)); + }); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "decodequotedprintable"', () => { + expect(sut.getId()).toEqual('decodequotedprintable'); + }); + + it('should call through to the native quoted printable decoder', () => { + const testInput = 'My input'; + const expectedOutput = 'It worked'; + decodeSpy.and.returnValue(expectedOutput); + const result: string = sut.convert(testInput); + expect(result).toEqual(expectedOutput); + expect(decodeSpy).toHaveBeenCalledWith(testInput); + }); +}); diff --git a/src/app/converter/quotedprintabledecoder.ts b/src/app/converter/quoted-printable-decoder.ts similarity index 100% rename from src/app/converter/quotedprintabledecoder.ts rename to src/app/converter/quoted-printable-decoder.ts diff --git a/src/app/converter/quoted-printable-encoder.spec.ts b/src/app/converter/quoted-printable-encoder.spec.ts new file mode 100644 index 0000000..cf4b3ca --- /dev/null +++ b/src/app/converter/quoted-printable-encoder.spec.ts @@ -0,0 +1,33 @@ +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import {QuotedPrintableEncoder} from './quoted-printable-encoder'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('QuotedPrintableEncoder', () => { + let sut: QuotedPrintableEncoder; + let nativeWrapperSpy: Partial; + let encodeSpy: Spy; + + beforeEach(() => { + nativeWrapperSpy = {quotedPrintable: createSpyObj(['encode'])}; + encodeSpy = nativeWrapperSpy.quotedPrintable.encode as Spy; + sut = new QuotedPrintableEncoder(nativeWrapperSpy as NativeLibraryWrapperService); + }); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "encodequotedprintable"', () => { + expect(sut.getId()).toEqual('encodequotedprintable'); + }); + + it('should call through to the native quoted printable encoder', () => { + const testInput = 'My input'; + const expectedOutput = 'It worked'; + encodeSpy.and.returnValue(expectedOutput); + const result: string = sut.convert(testInput); + expect(result).toEqual(expectedOutput); + expect(encodeSpy).toHaveBeenCalledWith(testInput); + }); +}); diff --git a/src/app/converter/quotedprintableencoder.ts b/src/app/converter/quoted-printable-encoder.ts similarity index 100% rename from src/app/converter/quotedprintableencoder.ts rename to src/app/converter/quoted-printable-encoder.ts