From c4effd4f411a6ce07f7a98c30e9c8a3be1c79c9d Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 22:53:50 +0200 Subject: [PATCH 01/19] Correct ConverterRegistryService. --- src/app/app.component.spec.ts | 2 +- src/app/app.component.ts | 2 +- src/app/app.module.ts | 2 +- src/app/converter-registry.service.spec.ts | 15 ++++++++ ...rvice.ts => converter-registry.service.ts} | 36 ++++++++++--------- 5 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/app/converter-registry.service.spec.ts rename src/app/{converterregistry.service.ts => converter-registry.service.ts} (98%) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index a82fbf1..0454090 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -3,7 +3,7 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {FormsModule} from '@angular/forms'; import {InputComponentManagerService} from './inputcomponentmanager.service'; import {Step} from './step'; -import {ConverterRegistryService} from './converterregistry.service'; +import {ConverterRegistryService} from './converter-registry.service'; import {Converter} from './converter/converter'; describe('AppComponent', () => { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1ec7c84..45ad694 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {ConverterRegistryService} from './converterregistry.service'; +import {ConverterRegistryService} from './converter-registry.service'; import {InputComponentManagerService} from './inputcomponentmanager.service'; import {Step} from './step'; import {Converter} from './converter/converter'; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 7ef864d..88e730c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,7 @@ import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {AppComponent} from './app.component'; -import {ConverterRegistryService} from './converterregistry.service'; +import {ConverterRegistryService} from './converter-registry.service'; import {InputComponentManagerService} from './inputcomponentmanager.service'; import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; import {FormsModule} from '@angular/forms'; diff --git a/src/app/converter-registry.service.spec.ts b/src/app/converter-registry.service.spec.ts new file mode 100644 index 0000000..2b97a17 --- /dev/null +++ b/src/app/converter-registry.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { ConverterRegistryService } from './converter-registry.service'; + +describe('ConverterRegistryService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ConverterRegistryService] + }); + }); + + it('should be created', inject([ConverterRegistryService], (service: ConverterRegistryService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/converterregistry.service.ts b/src/app/converter-registry.service.ts similarity index 98% rename from src/app/converterregistry.service.ts rename to src/app/converter-registry.service.ts index 4d66673..4067b3d 100644 --- a/src/app/converterregistry.service.ts +++ b/src/app/converter-registry.service.ts @@ -1,27 +1,29 @@ -import {Injectable} from '@angular/core'; -import {Converter} from './converter/converter'; -import {Base64Encoder} from './converter/base64encoder'; import {Base64Decoder} from './converter/base64decoder'; -import {URIEncoder} from './converter/uriencoder'; -import {URIDecoder} from './converter/uridecoder'; -import {URIComponentEncoder} from './converter/uricomponentencoder'; -import {URIComponentDecoder} from './converter/uricomponentdecoder'; -import {HTMLEntitiesEncoder} from './converter/htmlentitiesencoder'; -import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; +import {Base64Encoder} from './converter/base64encoder'; +import {BinToDecConverter} from './converter/bintodecconverter'; +import {Converter} from './converter/converter'; +import {DecToBinConverter} from './converter/dectobinconverter'; import {DecToHexConverter} from './converter/dectohexconverter'; import {HexToDecConverter} from './converter/hextodecconverter'; -import {DecToBinConverter} from './converter/dectobinconverter'; -import {BinToDecConverter} from './converter/bintodecconverter'; +import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; +import {HTMLEntitiesEncoder} from './converter/htmlentitiesencoder'; +import {Injectable} from '@angular/core'; +import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; +import {PunycodeDecoder} from './converter/punycodedecoder'; +import {PunycodeEncoder} from './converter/punycodeencoder'; import {QuotedPrintableDecoder} from './converter/quotedprintabledecoder'; import {QuotedPrintableEncoder} from './converter/quotedprintableencoder'; -import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; -import {PunycodeEncoder} from './converter/punycodeencoder'; -import {PunycodeDecoder} from './converter/punycodedecoder'; -import {UTF8Encoder} from './converter/utf8encoder'; -import {UTF8Decoder} from './converter/utf8decoder'; import {ROT13Converter} from './converter/rot13converter'; +import {URIComponentDecoder} from './converter/uricomponentdecoder'; +import {URIComponentEncoder} from './converter/uricomponentencoder'; +import {URIDecoder} from './converter/uridecoder'; +import {URIEncoder} from './converter/uriencoder'; +import {UTF8Decoder} from './converter/utf8decoder'; +import {UTF8Encoder} from './converter/utf8encoder'; -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class ConverterRegistryService { private converters: Converter[] = []; -- 2.45.2 From 82c371956ba6e5608847713f12700214ceb6a1da Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 22:56:18 +0200 Subject: [PATCH 02/19] Corrent InputComponentManagerService. --- src/app/app.component.spec.ts | 2 +- src/app/app.component.ts | 2 +- src/app/app.module.ts | 2 +- src/app/input-component-manager.service.spec.ts | 15 +++++++++++++++ ...vice.ts => input-component-manager.service.ts} | 4 +++- 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/app/input-component-manager.service.spec.ts rename src/app/{inputcomponentmanager.service.ts => input-component-manager.service.ts} (95%) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 0454090..ab98f52 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,7 +1,7 @@ import {AppComponent} from './app.component'; import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {FormsModule} from '@angular/forms'; -import {InputComponentManagerService} from './inputcomponentmanager.service'; +import {InputComponentManagerService} from './input-component-manager.service'; import {Step} from './step'; import {ConverterRegistryService} from './converter-registry.service'; import {Converter} from './converter/converter'; diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 45ad694..820811b 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {ConverterRegistryService} from './converter-registry.service'; -import {InputComponentManagerService} from './inputcomponentmanager.service'; +import {InputComponentManagerService} from './input-component-manager.service'; import {Step} from './step'; import {Converter} from './converter/converter'; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 88e730c..efad288 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -2,7 +2,7 @@ import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {AppComponent} from './app.component'; import {ConverterRegistryService} from './converter-registry.service'; -import {InputComponentManagerService} from './inputcomponentmanager.service'; +import {InputComponentManagerService} from './input-component-manager.service'; import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; import {FormsModule} from '@angular/forms'; import {VersionComponent} from './version/version.component'; diff --git a/src/app/input-component-manager.service.spec.ts b/src/app/input-component-manager.service.spec.ts new file mode 100644 index 0000000..b15c3bc --- /dev/null +++ b/src/app/input-component-manager.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { InputComponentManagerService } from './input-component-manager.service'; + +describe('InputComponentManagerService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [InputComponentManagerService] + }); + }); + + it('should be created', inject([InputComponentManagerService], (service: InputComponentManagerService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/inputcomponentmanager.service.ts b/src/app/input-component-manager.service.ts similarity index 95% rename from src/app/inputcomponentmanager.service.ts rename to src/app/input-component-manager.service.ts index 136d1b6..45e8d02 100644 --- a/src/app/inputcomponentmanager.service.ts +++ b/src/app/input-component-manager.service.ts @@ -1,7 +1,9 @@ import {Injectable} from '@angular/core'; import {Step} from './step'; -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class InputComponentManagerService { private components: Step[] = []; -- 2.45.2 From 9e11ba9335616340b4f543116674ccf1489d69b7 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 23:00:13 +0200 Subject: [PATCH 03/19] Corrected NativeLibraryWrapperService. --- src/app/app.module.ts | 2 +- src/app/converter-registry.service.ts | 2 +- src/app/converter/punycodedecoder.ts | 2 +- src/app/converter/punycodeencoder.ts | 2 +- src/app/converter/quotedprintabledecoder.ts | 2 +- src/app/converter/quotedprintableencoder.ts | 2 +- src/app/converter/utf8decoder.ts | 2 +- src/app/converter/utf8encoder.ts | 2 +- .../native-library-wrapper.service.spec.ts | 15 ++++++++++ ...e.ts => native-library-wrapper.service.ts} | 29 +++++++++++++++---- src/app/punycode.ts | 4 --- src/app/quotedprintable.ts | 4 --- src/app/utf8.ts | 4 --- 13 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 src/app/native-library-wrapper.service.spec.ts rename src/app/{nativelibrarywrapper.service.ts => native-library-wrapper.service.ts} (59%) delete mode 100644 src/app/punycode.ts delete mode 100644 src/app/quotedprintable.ts delete mode 100644 src/app/utf8.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index efad288..5e40ab8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -3,7 +3,7 @@ import {NgModule} from '@angular/core'; import {AppComponent} from './app.component'; import {ConverterRegistryService} from './converter-registry.service'; import {InputComponentManagerService} from './input-component-manager.service'; -import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from './native-library-wrapper.service'; import {FormsModule} from '@angular/forms'; import {VersionComponent} from './version/version.component'; diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 4067b3d..84e013e 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -8,7 +8,7 @@ import {HexToDecConverter} from './converter/hextodecconverter'; import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; import {HTMLEntitiesEncoder} from './converter/htmlentitiesencoder'; import {Injectable} from '@angular/core'; -import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from './native-library-wrapper.service'; import {PunycodeDecoder} from './converter/punycodedecoder'; import {PunycodeEncoder} from './converter/punycodeencoder'; import {QuotedPrintableDecoder} from './converter/quotedprintabledecoder'; diff --git a/src/app/converter/punycodedecoder.ts b/src/app/converter/punycodedecoder.ts index 5f68ec6..c850e2b 100644 --- a/src/app/converter/punycodedecoder.ts +++ b/src/app/converter/punycodedecoder.ts @@ -1,5 +1,5 @@ import {Converter} from './converter'; -import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; export class PunycodeDecoder implements Converter { diff --git a/src/app/converter/punycodeencoder.ts b/src/app/converter/punycodeencoder.ts index ebf8b67..05523d6 100644 --- a/src/app/converter/punycodeencoder.ts +++ b/src/app/converter/punycodeencoder.ts @@ -1,5 +1,5 @@ import {Converter} from './converter'; -import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; export class PunycodeEncoder implements Converter { diff --git a/src/app/converter/quotedprintabledecoder.ts b/src/app/converter/quotedprintabledecoder.ts index 9c43014..d1992c5 100644 --- a/src/app/converter/quotedprintabledecoder.ts +++ b/src/app/converter/quotedprintabledecoder.ts @@ -1,5 +1,5 @@ import {Converter} from './converter'; -import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; export class QuotedPrintableDecoder implements Converter { diff --git a/src/app/converter/quotedprintableencoder.ts b/src/app/converter/quotedprintableencoder.ts index 17cbb32..b6d07b8 100644 --- a/src/app/converter/quotedprintableencoder.ts +++ b/src/app/converter/quotedprintableencoder.ts @@ -1,5 +1,5 @@ import {Converter} from './converter'; -import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; export class QuotedPrintableEncoder implements Converter { diff --git a/src/app/converter/utf8decoder.ts b/src/app/converter/utf8decoder.ts index 7f19a76..a17f502 100644 --- a/src/app/converter/utf8decoder.ts +++ b/src/app/converter/utf8decoder.ts @@ -1,5 +1,5 @@ import {Converter} from './converter'; -import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; export class UTF8Decoder implements Converter { diff --git a/src/app/converter/utf8encoder.ts b/src/app/converter/utf8encoder.ts index 7e911d4..9d47879 100644 --- a/src/app/converter/utf8encoder.ts +++ b/src/app/converter/utf8encoder.ts @@ -1,5 +1,5 @@ import {Converter} from './converter'; -import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service'; +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; export class UTF8Encoder implements Converter { diff --git a/src/app/native-library-wrapper.service.spec.ts b/src/app/native-library-wrapper.service.spec.ts new file mode 100644 index 0000000..35f2936 --- /dev/null +++ b/src/app/native-library-wrapper.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { NativeLibraryWrapperService } from './native-library-wrapper.service'; + +describe('NativeLibraryWrapperService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [NativeLibraryWrapperService] + }); + }); + + it('should be created', inject([NativeLibraryWrapperService], (service: NativeLibraryWrapperService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/nativelibrarywrapper.service.ts b/src/app/native-library-wrapper.service.ts similarity index 59% rename from src/app/nativelibrarywrapper.service.ts rename to src/app/native-library-wrapper.service.ts index f3ce6af..308a14f 100644 --- a/src/app/nativelibrarywrapper.service.ts +++ b/src/app/native-library-wrapper.service.ts @@ -1,12 +1,11 @@ import {Injectable} from '@angular/core'; -import {Punycode} from './punycode'; -import {Utf8} from './utf8'; -import {QuotedPrintable} from './quotedprintable'; -import * as NativeUtf8 from 'utf8'; -import * as NativeQuotedPrintable from 'quoted-printable'; import * as NativePunycode from 'punycode'; +import * as NativeQuotedPrintable from 'quoted-printable'; +import * as NativeUtf8 from 'utf8'; -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class NativeLibraryWrapperService { public utf8: Utf8; public quotedPrintable: QuotedPrintable; @@ -18,3 +17,21 @@ export class NativeLibraryWrapperService { this.punycode = NativePunycode; } } + +interface Punycode { + encode(input: string): string; + + decode(input: string): string; +} + +interface QuotedPrintable { + encode(input: string): string; + + decode(input: string): string; +} + +interface Utf8 { + encode(input: any): string; + + decode(input: string): any; +} diff --git a/src/app/punycode.ts b/src/app/punycode.ts deleted file mode 100644 index 1368326..0000000 --- a/src/app/punycode.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface Punycode { - encode(input: string): string; - decode(input: string): string; -} diff --git a/src/app/quotedprintable.ts b/src/app/quotedprintable.ts deleted file mode 100644 index 59bdfba..0000000 --- a/src/app/quotedprintable.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface QuotedPrintable { - encode(input: string): string; - decode(input: string): string; -} diff --git a/src/app/utf8.ts b/src/app/utf8.ts deleted file mode 100644 index 86706f5..0000000 --- a/src/app/utf8.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface Utf8 { - encode(input: any): string; - decode(input: string): any; -} -- 2.45.2 From 1b060644c3f5fdbc986db6b1bfcea1315c0caa01 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 23:22:15 +0200 Subject: [PATCH 04/19] Fix Base64{De,En}coder filenames and add tests. --- src/app/app.component.spec.ts | 3 ++- src/app/converter-registry.service.ts | 4 ++-- src/app/converter/base64-decoder.spec.ts | 13 +++++++++++++ .../{base64decoder.ts => base64-decoder.ts} | 0 src/app/converter/base64-encoder.spec.ts | 13 +++++++++++++ .../{base64encoder.ts => base64-encoder.ts} | 0 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/app/converter/base64-decoder.spec.ts rename src/app/converter/{base64decoder.ts => base64-decoder.ts} (100%) create mode 100644 src/app/converter/base64-encoder.spec.ts rename src/app/converter/{base64encoder.ts => base64-encoder.ts} (100%) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index ab98f52..adb0d4a 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -5,6 +5,7 @@ import {InputComponentManagerService} from './input-component-manager.service'; import {Step} from './step'; import {ConverterRegistryService} from './converter-registry.service'; import {Converter} from './converter/converter'; +import {VersionComponent} from './version/version.component'; describe('AppComponent', () => { let sut: AppComponent; @@ -30,7 +31,7 @@ describe('AppComponent', () => { beforeEach(async(() => { /*return */ TestBed.configureTestingModule({ - declarations: [AppComponent], + declarations: [AppComponent, VersionComponent], imports: [FormsModule], providers: [ {provide: InputComponentManagerService, useValue: inputComponentManagerServiceStub}, diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 84e013e..16520e7 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -1,5 +1,5 @@ -import {Base64Decoder} from './converter/base64decoder'; -import {Base64Encoder} from './converter/base64encoder'; +import {Base64Decoder} from './converter/base64-decoder'; +import {Base64Encoder} from './converter/base64-encoder'; import {BinToDecConverter} from './converter/bintodecconverter'; import {Converter} from './converter/converter'; import {DecToBinConverter} from './converter/dectobinconverter'; diff --git a/src/app/converter/base64-decoder.spec.ts b/src/app/converter/base64-decoder.spec.ts new file mode 100644 index 0000000..888d69d --- /dev/null +++ b/src/app/converter/base64-decoder.spec.ts @@ -0,0 +1,13 @@ +import {Base64Decoder} from './base64-decoder'; + +describe('Base64Decoder', () => { + it('should create an instance', () => { + expect(new Base64Decoder()).toBeTruthy(); + }); + it('should have the id "base64decode"', () => { + expect(new Base64Decoder().getId()).toEqual('base64decode'); + }); + it('should decode "SGVsbG8sIFdvcmxkIQ==" to "Hello, World!"', () => { + expect(new Base64Decoder().convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!'); + }); +}); diff --git a/src/app/converter/base64decoder.ts b/src/app/converter/base64-decoder.ts similarity index 100% rename from src/app/converter/base64decoder.ts rename to src/app/converter/base64-decoder.ts diff --git a/src/app/converter/base64-encoder.spec.ts b/src/app/converter/base64-encoder.spec.ts new file mode 100644 index 0000000..31c5b27 --- /dev/null +++ b/src/app/converter/base64-encoder.spec.ts @@ -0,0 +1,13 @@ +import {Base64Encoder} from './base64-encoder'; + +describe('Base64Encoder', () => { + it('should create an instance', () => { + expect(new Base64Encoder()).toBeTruthy(); + }); + it('should have the id "base64encode"', () => { + expect(new Base64Encoder().getId()).toEqual('base64encode'); + }); + it('should encode "Oh, guete Tag!" to "T2gsIGd1ZXRlIFRhZyE="', () => { + expect(new Base64Encoder().convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE='); + }); +}); diff --git a/src/app/converter/base64encoder.ts b/src/app/converter/base64-encoder.ts similarity index 100% rename from src/app/converter/base64encoder.ts rename to src/app/converter/base64-encoder.ts -- 2.45.2 From 0eb69a3064b6829341e1318dc462f38a93e9fa4b Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 23:35:14 +0200 Subject: [PATCH 05/19] Fixed BinToDecConverter file name and added more tests, also negative tests for the Base64 converters. --- src/app/converter-registry.service.ts | 2 +- src/app/converter/base64-decoder.spec.ts | 3 +++ src/app/converter/base64-encoder.spec.ts | 3 +++ src/app/converter/base64-encoder.ts | 2 +- src/app/converter/bin-to-dec-converter.spec.ts | 16 ++++++++++++++++ ...todecconverter.ts => bin-to-dec-converter.ts} | 0 6 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/bin-to-dec-converter.spec.ts rename src/app/converter/{bintodecconverter.ts => bin-to-dec-converter.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 16520e7..dc6699d 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -1,6 +1,6 @@ import {Base64Decoder} from './converter/base64-decoder'; import {Base64Encoder} from './converter/base64-encoder'; -import {BinToDecConverter} from './converter/bintodecconverter'; +import {BinToDecConverter} from './converter/bin-to-dec-converter'; import {Converter} from './converter/converter'; import {DecToBinConverter} from './converter/dectobinconverter'; import {DecToHexConverter} from './converter/dectohexconverter'; diff --git a/src/app/converter/base64-decoder.spec.ts b/src/app/converter/base64-decoder.spec.ts index 888d69d..0133e20 100644 --- a/src/app/converter/base64-decoder.spec.ts +++ b/src/app/converter/base64-decoder.spec.ts @@ -10,4 +10,7 @@ describe('Base64Decoder', () => { it('should decode "SGVsbG8sIFdvcmxkIQ==" to "Hello, World!"', () => { expect(new Base64Decoder().convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!'); }); + it('should raise an exception on invalid input', () => { + expect(() => new Base64Decoder().convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?'); + }); }); diff --git a/src/app/converter/base64-encoder.spec.ts b/src/app/converter/base64-encoder.spec.ts index 31c5b27..889912e 100644 --- a/src/app/converter/base64-encoder.spec.ts +++ b/src/app/converter/base64-encoder.spec.ts @@ -10,4 +10,7 @@ describe('Base64Encoder', () => { it('should encode "Oh, guete Tag!" to "T2gsIGd1ZXRlIFRhZyE="', () => { expect(new Base64Encoder().convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE='); }); + it('should raise an exception on invalid input', () => { + expect(() => new Base64Encoder().convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./); + }); }); diff --git a/src/app/converter/base64-encoder.ts b/src/app/converter/base64-encoder.ts index c9e3513..6853180 100644 --- a/src/app/converter/base64-encoder.ts +++ b/src/app/converter/base64-encoder.ts @@ -14,7 +14,7 @@ export class Base64Encoder implements Converter { return btoa(input); } catch (exception) { console.error(exception); - throw new Error('Ouch! Looks like you\'ve got a UTF-8 character there. Too bad, this is not supported yet. ' + throw new Error('Ouch! Looks like you\'ve got a character outside of the Latin1 range there. Too bad, this is not supported yet. ' + 'We\'re working on it and hope to be ready soon! Why don\'t you ' + 'enjoy some kittens meanwhile?'); } diff --git a/src/app/converter/bin-to-dec-converter.spec.ts b/src/app/converter/bin-to-dec-converter.spec.ts new file mode 100644 index 0000000..04dabd0 --- /dev/null +++ b/src/app/converter/bin-to-dec-converter.spec.ts @@ -0,0 +1,16 @@ +import {BinToDecConverter} from './bin-to-dec-converter'; + +describe('BinToDecConverter', () => { + it('should create an instance', () => { + expect(new BinToDecConverter()).toBeTruthy(); + }); + it('should have the id "base64encode"', () => { + expect(new BinToDecConverter().getId()).toEqual('bintodec'); + }); + it('should convert "11011" to "27"', () => { + expect(new BinToDecConverter().convert('11011')).toEqual('27'); + }); + it('should raise an exception on invalid input', () => { + expect(() => new BinToDecConverter().convert('foo bar')).toThrowError('The input seems not to be a valid binary number.'); + }); +}); diff --git a/src/app/converter/bintodecconverter.ts b/src/app/converter/bin-to-dec-converter.ts similarity index 100% rename from src/app/converter/bintodecconverter.ts rename to src/app/converter/bin-to-dec-converter.ts -- 2.45.2 From 83292b14c267242d37552f0e4c248e686de1159a Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 23:38:22 +0200 Subject: [PATCH 06/19] Fixed DectoBinConverter file name and added tests. --- src/app/converter-registry.service.ts | 2 +- src/app/converter/dec-to-bin-converter.spec.ts | 16 ++++++++++++++++ ...tobinconverter.ts => dec-to-bin-converter.ts} | 0 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/app/converter/dec-to-bin-converter.spec.ts rename src/app/converter/{dectobinconverter.ts => dec-to-bin-converter.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index dc6699d..b4bef71 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -2,7 +2,7 @@ import {Base64Decoder} from './converter/base64-decoder'; import {Base64Encoder} from './converter/base64-encoder'; import {BinToDecConverter} from './converter/bin-to-dec-converter'; import {Converter} from './converter/converter'; -import {DecToBinConverter} from './converter/dectobinconverter'; +import {DecToBinConverter} from './converter/dec-to-bin-converter'; import {DecToHexConverter} from './converter/dectohexconverter'; import {HexToDecConverter} from './converter/hextodecconverter'; import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; diff --git a/src/app/converter/dec-to-bin-converter.spec.ts b/src/app/converter/dec-to-bin-converter.spec.ts new file mode 100644 index 0000000..0305779 --- /dev/null +++ b/src/app/converter/dec-to-bin-converter.spec.ts @@ -0,0 +1,16 @@ +import {DecToBinConverter} from './dec-to-bin-converter'; + +describe('DecToBinConverter', () => { + it('should create an instance', () => { + expect(new DecToBinConverter()).toBeTruthy(); + }); + it('should have the id "base64encode"', () => { + expect(new DecToBinConverter().getId()).toEqual('dectobin'); + }); + it('should convert "22" to "10110"', () => { + expect(new DecToBinConverter().convert('22')).toEqual('10110'); + }); + it('should raise an exception on invalid input', () => { + expect(() => new DecToBinConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.'); + }); +}); diff --git a/src/app/converter/dectobinconverter.ts b/src/app/converter/dec-to-bin-converter.ts similarity index 100% rename from src/app/converter/dectobinconverter.ts rename to src/app/converter/dec-to-bin-converter.ts -- 2.45.2 From e8f5d12fda245dc344af0070d35519138c6fc9b0 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 23:40:47 +0200 Subject: [PATCH 07/19] Fixed DecToHexConverter filename, added test and fixed other tests. --- src/app/converter-registry.service.ts | 2 +- src/app/converter/bin-to-dec-converter.spec.ts | 2 +- src/app/converter/dec-to-bin-converter.spec.ts | 2 +- src/app/converter/dec-to-hex-converter.spec.ts | 16 ++++++++++++++++ ...tohexconverter.ts => dec-to-hex-converter.ts} | 0 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/app/converter/dec-to-hex-converter.spec.ts rename src/app/converter/{dectohexconverter.ts => dec-to-hex-converter.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index b4bef71..4df04c0 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -3,7 +3,7 @@ import {Base64Encoder} from './converter/base64-encoder'; import {BinToDecConverter} from './converter/bin-to-dec-converter'; import {Converter} from './converter/converter'; import {DecToBinConverter} from './converter/dec-to-bin-converter'; -import {DecToHexConverter} from './converter/dectohexconverter'; +import {DecToHexConverter} from './converter/dec-to-hex-converter'; import {HexToDecConverter} from './converter/hextodecconverter'; import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; import {HTMLEntitiesEncoder} from './converter/htmlentitiesencoder'; diff --git a/src/app/converter/bin-to-dec-converter.spec.ts b/src/app/converter/bin-to-dec-converter.spec.ts index 04dabd0..cf65375 100644 --- a/src/app/converter/bin-to-dec-converter.spec.ts +++ b/src/app/converter/bin-to-dec-converter.spec.ts @@ -4,7 +4,7 @@ describe('BinToDecConverter', () => { it('should create an instance', () => { expect(new BinToDecConverter()).toBeTruthy(); }); - it('should have the id "base64encode"', () => { + it('should have the id "bintodec"', () => { expect(new BinToDecConverter().getId()).toEqual('bintodec'); }); it('should convert "11011" to "27"', () => { diff --git a/src/app/converter/dec-to-bin-converter.spec.ts b/src/app/converter/dec-to-bin-converter.spec.ts index 0305779..e32fa18 100644 --- a/src/app/converter/dec-to-bin-converter.spec.ts +++ b/src/app/converter/dec-to-bin-converter.spec.ts @@ -4,7 +4,7 @@ describe('DecToBinConverter', () => { it('should create an instance', () => { expect(new DecToBinConverter()).toBeTruthy(); }); - it('should have the id "base64encode"', () => { + it('should have the id "dectobin"', () => { expect(new DecToBinConverter().getId()).toEqual('dectobin'); }); it('should convert "22" to "10110"', () => { diff --git a/src/app/converter/dec-to-hex-converter.spec.ts b/src/app/converter/dec-to-hex-converter.spec.ts new file mode 100644 index 0000000..152612f --- /dev/null +++ b/src/app/converter/dec-to-hex-converter.spec.ts @@ -0,0 +1,16 @@ +import {DecToHexConverter} from './dec-to-hex-converter'; + +describe('DecToHexConverter', () => { + it('should create an instance', () => { + expect(new DecToHexConverter()).toBeTruthy(); + }); + it('should have the id "dectohex"', () => { + expect(new DecToHexConverter().getId()).toEqual('dectohex'); + }); + it('should convert "22" to "16"', () => { + expect(new DecToHexConverter().convert('22')).toEqual('16'); + }); + it('should raise an exception on invalid input', () => { + expect(() => new DecToHexConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.'); + }); +}); diff --git a/src/app/converter/dectohexconverter.ts b/src/app/converter/dec-to-hex-converter.ts similarity index 100% rename from src/app/converter/dectohexconverter.ts rename to src/app/converter/dec-to-hex-converter.ts -- 2.45.2 From 8280e0be94b12ffaca562f44a87266061a0856ae Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 23:59:52 +0200 Subject: [PATCH 08/19] Fixed HexToDecConverter file name and added tests; made conversion from binary and hexadecimal to decimal stricter. --- src/app/converter-registry.service.ts | 2 +- src/app/converter/bin-to-dec-converter.spec.ts | 2 +- src/app/converter/bin-to-dec-converter.ts | 2 +- src/app/converter/hex-to-dec-converter.spec.ts | 16 ++++++++++++++++ ...todecconverter.ts => hex-to-dec-converter.ts} | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/app/converter/hex-to-dec-converter.spec.ts rename src/app/converter/{hextodecconverter.ts => hex-to-dec-converter.ts} (85%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 4df04c0..dd6e19d 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -4,7 +4,7 @@ import {BinToDecConverter} from './converter/bin-to-dec-converter'; import {Converter} from './converter/converter'; import {DecToBinConverter} from './converter/dec-to-bin-converter'; import {DecToHexConverter} from './converter/dec-to-hex-converter'; -import {HexToDecConverter} from './converter/hextodecconverter'; +import {HexToDecConverter} from './converter/hex-to-dec-converter'; import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; import {HTMLEntitiesEncoder} from './converter/htmlentitiesencoder'; import {Injectable} from '@angular/core'; diff --git a/src/app/converter/bin-to-dec-converter.spec.ts b/src/app/converter/bin-to-dec-converter.spec.ts index cf65375..a67bbb0 100644 --- a/src/app/converter/bin-to-dec-converter.spec.ts +++ b/src/app/converter/bin-to-dec-converter.spec.ts @@ -11,6 +11,6 @@ describe('BinToDecConverter', () => { expect(new BinToDecConverter().convert('11011')).toEqual('27'); }); it('should raise an exception on invalid input', () => { - expect(() => new BinToDecConverter().convert('foo bar')).toThrowError('The input seems not to be a valid binary number.'); + expect(() => new BinToDecConverter().convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.'); }); }); diff --git a/src/app/converter/bin-to-dec-converter.ts b/src/app/converter/bin-to-dec-converter.ts index 3315882..fe95bff 100644 --- a/src/app/converter/bin-to-dec-converter.ts +++ b/src/app/converter/bin-to-dec-converter.ts @@ -11,7 +11,7 @@ export class BinToDecConverter implements Converter { convert(input: string): string { const n: number = parseInt(input, 2); - if (isNaN(n)) { + if (isNaN(n) || !input.trim().match(/^([01]+)$/)) { throw new Error('The input seems not to be a valid binary number.'); } return n.toString(10); diff --git a/src/app/converter/hex-to-dec-converter.spec.ts b/src/app/converter/hex-to-dec-converter.spec.ts new file mode 100644 index 0000000..f01c833 --- /dev/null +++ b/src/app/converter/hex-to-dec-converter.spec.ts @@ -0,0 +1,16 @@ +import {HexToDecConverter} from './hex-to-dec-converter'; + +describe('HexToDecConverter', () => { + it('should create an instance', () => { + expect(new HexToDecConverter()).toBeTruthy(); + }); + it('should have the id "hextodec"', () => { + expect(new HexToDecConverter().getId()).toEqual('hextodec'); + }); + it('should convert "ab" to "171"', () => { + expect(new HexToDecConverter().convert('ab')).toEqual('171'); + }); + it('should raise an exception on invalid input', () => { + expect(() => new HexToDecConverter().convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.'); + }); +}); diff --git a/src/app/converter/hextodecconverter.ts b/src/app/converter/hex-to-dec-converter.ts similarity index 85% rename from src/app/converter/hextodecconverter.ts rename to src/app/converter/hex-to-dec-converter.ts index 4b78345..7ac803e 100644 --- a/src/app/converter/hextodecconverter.ts +++ b/src/app/converter/hex-to-dec-converter.ts @@ -11,7 +11,7 @@ export class HexToDecConverter implements Converter { convert(input: string): string { const n: number = parseInt(input, 16); - if (isNaN(n)) { + if (isNaN(n) || !input.trim().match(/^((0x|0X)?[0-9a-fA-F]+)$/)) { throw new Error('The input seems not to be a valid hexadecimal number.'); } return n.toString(10); -- 2.45.2 From f46604b523176f7c3f22cd510eac9bcc01010461 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:08:37 +0200 Subject: [PATCH 09/19] Fixed HTMLEntities{De,En}coder file names and added tests. --- src/app/converter-registry.service.ts | 4 ++-- src/app/converter/htmlentities-decoder.spec.ts | 14 ++++++++++++++ ...lentitiesdecoder.ts => htmlentities-decoder.ts} | 0 src/app/converter/htmlentities-encoder.spec.ts | 14 ++++++++++++++ ...lentitiesencoder.ts => htmlentities-encoder.ts} | 0 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/htmlentities-decoder.spec.ts rename src/app/converter/{htmlentitiesdecoder.ts => htmlentities-decoder.ts} (100%) create mode 100644 src/app/converter/htmlentities-encoder.spec.ts rename src/app/converter/{htmlentitiesencoder.ts => htmlentities-encoder.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index dd6e19d..f99639f 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -5,8 +5,8 @@ import {Converter} from './converter/converter'; import {DecToBinConverter} from './converter/dec-to-bin-converter'; import {DecToHexConverter} from './converter/dec-to-hex-converter'; import {HexToDecConverter} from './converter/hex-to-dec-converter'; -import {HTMLEntitiesDecoder} from './converter/htmlentitiesdecoder'; -import {HTMLEntitiesEncoder} from './converter/htmlentitiesencoder'; +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'; diff --git a/src/app/converter/htmlentities-decoder.spec.ts b/src/app/converter/htmlentities-decoder.spec.ts new file mode 100644 index 0000000..08136ea --- /dev/null +++ b/src/app/converter/htmlentities-decoder.spec.ts @@ -0,0 +1,14 @@ +import {HTMLEntitiesDecoder} from './htmlentities-decoder'; + +describe('HTMLEntitiesDecoder', () => { + it('should create an instance', () => { + expect(new HTMLEntitiesDecoder()).toBeTruthy(); + }); + it('should have the id "decodehtmlentities"', () => { + expect(new HTMLEntitiesDecoder().getId()).toEqual('decodehtmlentities'); + }); + it('should decode "<span>"Hi" & "Lo"</span>" to ""Hi" & "Lo""', () => { + expect(new HTMLEntitiesDecoder().convert('<span>"Hi" & "Lo"</span>')) + .toEqual('"Hi" & "Lo"'); + }); +}); diff --git a/src/app/converter/htmlentitiesdecoder.ts b/src/app/converter/htmlentities-decoder.ts similarity index 100% rename from src/app/converter/htmlentitiesdecoder.ts rename to src/app/converter/htmlentities-decoder.ts diff --git a/src/app/converter/htmlentities-encoder.spec.ts b/src/app/converter/htmlentities-encoder.spec.ts new file mode 100644 index 0000000..5c6aa09 --- /dev/null +++ b/src/app/converter/htmlentities-encoder.spec.ts @@ -0,0 +1,14 @@ +import {HTMLEntitiesEncoder} from './htmlentities-encoder'; + +describe('HTMLEntitiesEncoder', () => { + it('should create an instance', () => { + expect(new HTMLEntitiesEncoder()).toBeTruthy(); + }); + it('should have the id "encodehtmlentities"', () => { + expect(new HTMLEntitiesEncoder().getId()).toEqual('encodehtmlentities'); + }); + it('should encode ""Hi" & "Lo"" to "<span>"Hi" & "Lo"</span>"', () => { + expect(new HTMLEntitiesEncoder().convert('"Hi" & "Lo"')) + .toEqual('<span>"Hi" & "Lo"</span>'); + }); +}); diff --git a/src/app/converter/htmlentitiesencoder.ts b/src/app/converter/htmlentities-encoder.ts similarity index 100% rename from src/app/converter/htmlentitiesencoder.ts rename to src/app/converter/htmlentities-encoder.ts -- 2.45.2 From 5841195cdab823a867b0ba3c00df9a154788cdcd Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:26:35 +0200 Subject: [PATCH 10/19] Fixed named for Punycode{De,En}coder and added tests. --- src/app/converter-registry.service.ts | 4 +-- src/app/converter/punycode-decoder.spec.ts | 27 +++++++++++++++++++ ...punycodedecoder.ts => punycode-decoder.ts} | 0 src/app/converter/punycode-encoder.spec.ts | 27 +++++++++++++++++++ ...punycodeencoder.ts => punycode-encoder.ts} | 0 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/punycode-decoder.spec.ts rename src/app/converter/{punycodedecoder.ts => punycode-decoder.ts} (100%) create mode 100644 src/app/converter/punycode-encoder.spec.ts rename src/app/converter/{punycodeencoder.ts => punycode-encoder.ts} (100%) 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 -- 2.45.2 From bdf15d277e515729678394d40cbfbdd3028583a4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:34:41 +0200 Subject: [PATCH 11/19] Declare "sut" (= subject under test) variable in all tests. --- src/app/converter/base64-decoder.spec.ts | 15 +++++++++++---- src/app/converter/base64-encoder.spec.ts | 15 +++++++++++---- src/app/converter/bin-to-dec-converter.spec.ts | 15 +++++++++++---- src/app/converter/dec-to-bin-converter.spec.ts | 15 +++++++++++---- src/app/converter/dec-to-hex-converter.spec.ts | 15 +++++++++++---- src/app/converter/hex-to-dec-converter.spec.ts | 15 +++++++++++---- src/app/converter/htmlentities-decoder.spec.ts | 12 +++++++++--- src/app/converter/htmlentities-encoder.spec.ts | 12 +++++++++--- src/app/converter/punycode-decoder.spec.ts | 12 +++++++++--- src/app/converter/punycode-encoder.spec.ts | 12 +++++++++--- 10 files changed, 102 insertions(+), 36 deletions(-) diff --git a/src/app/converter/base64-decoder.spec.ts b/src/app/converter/base64-decoder.spec.ts index 0133e20..1e144c7 100644 --- a/src/app/converter/base64-decoder.spec.ts +++ b/src/app/converter/base64-decoder.spec.ts @@ -1,16 +1,23 @@ import {Base64Decoder} from './base64-decoder'; describe('Base64Decoder', () => { + let sut: Base64Decoder; + + beforeEach(() => sut = new Base64Decoder()); + it('should create an instance', () => { - expect(new Base64Decoder()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "base64decode"', () => { - expect(new Base64Decoder().getId()).toEqual('base64decode'); + expect(sut.getId()).toEqual('base64decode'); }); + it('should decode "SGVsbG8sIFdvcmxkIQ==" to "Hello, World!"', () => { - expect(new Base64Decoder().convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!'); + expect(sut.convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!'); }); + it('should raise an exception on invalid input', () => { - expect(() => new Base64Decoder().convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?'); + expect(() => sut.convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?'); }); }); diff --git a/src/app/converter/base64-encoder.spec.ts b/src/app/converter/base64-encoder.spec.ts index 889912e..a8a17aa 100644 --- a/src/app/converter/base64-encoder.spec.ts +++ b/src/app/converter/base64-encoder.spec.ts @@ -1,16 +1,23 @@ import {Base64Encoder} from './base64-encoder'; describe('Base64Encoder', () => { + let sut: Base64Encoder; + + beforeEach(() => sut = new Base64Encoder()); + it('should create an instance', () => { - expect(new Base64Encoder()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "base64encode"', () => { - expect(new Base64Encoder().getId()).toEqual('base64encode'); + expect(sut.getId()).toEqual('base64encode'); }); + it('should encode "Oh, guete Tag!" to "T2gsIGd1ZXRlIFRhZyE="', () => { - expect(new Base64Encoder().convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE='); + expect(sut.convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE='); }); + it('should raise an exception on invalid input', () => { - expect(() => new Base64Encoder().convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./); + expect(() => sut.convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./); }); }); diff --git a/src/app/converter/bin-to-dec-converter.spec.ts b/src/app/converter/bin-to-dec-converter.spec.ts index a67bbb0..7629672 100644 --- a/src/app/converter/bin-to-dec-converter.spec.ts +++ b/src/app/converter/bin-to-dec-converter.spec.ts @@ -1,16 +1,23 @@ import {BinToDecConverter} from './bin-to-dec-converter'; describe('BinToDecConverter', () => { + let sut: BinToDecConverter; + + beforeEach(() => sut = new BinToDecConverter()); + it('should create an instance', () => { - expect(new BinToDecConverter()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "bintodec"', () => { - expect(new BinToDecConverter().getId()).toEqual('bintodec'); + expect(sut.getId()).toEqual('bintodec'); }); + it('should convert "11011" to "27"', () => { - expect(new BinToDecConverter().convert('11011')).toEqual('27'); + expect(sut.convert('11011')).toEqual('27'); }); + it('should raise an exception on invalid input', () => { - expect(() => new BinToDecConverter().convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.'); + expect(() => sut.convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.'); }); }); diff --git a/src/app/converter/dec-to-bin-converter.spec.ts b/src/app/converter/dec-to-bin-converter.spec.ts index e32fa18..9022275 100644 --- a/src/app/converter/dec-to-bin-converter.spec.ts +++ b/src/app/converter/dec-to-bin-converter.spec.ts @@ -1,16 +1,23 @@ import {DecToBinConverter} from './dec-to-bin-converter'; describe('DecToBinConverter', () => { + let sut: DecToBinConverter; + + beforeEach(() => sut = new DecToBinConverter()); + it('should create an instance', () => { - expect(new DecToBinConverter()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "dectobin"', () => { - expect(new DecToBinConverter().getId()).toEqual('dectobin'); + expect(sut.getId()).toEqual('dectobin'); }); + it('should convert "22" to "10110"', () => { - expect(new DecToBinConverter().convert('22')).toEqual('10110'); + expect(sut.convert('22')).toEqual('10110'); }); + it('should raise an exception on invalid input', () => { - expect(() => new DecToBinConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.'); + expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid integer.'); }); }); diff --git a/src/app/converter/dec-to-hex-converter.spec.ts b/src/app/converter/dec-to-hex-converter.spec.ts index 152612f..90e344b 100644 --- a/src/app/converter/dec-to-hex-converter.spec.ts +++ b/src/app/converter/dec-to-hex-converter.spec.ts @@ -1,16 +1,23 @@ import {DecToHexConverter} from './dec-to-hex-converter'; describe('DecToHexConverter', () => { + let sut: DecToHexConverter; + + beforeEach(() => sut = new DecToHexConverter()); + it('should create an instance', () => { - expect(new DecToHexConverter()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "dectohex"', () => { - expect(new DecToHexConverter().getId()).toEqual('dectohex'); + expect(sut.getId()).toEqual('dectohex'); }); + it('should convert "22" to "16"', () => { - expect(new DecToHexConverter().convert('22')).toEqual('16'); + expect(sut.convert('22')).toEqual('16'); }); + it('should raise an exception on invalid input', () => { - expect(() => new DecToHexConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.'); + expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid integer.'); }); }); diff --git a/src/app/converter/hex-to-dec-converter.spec.ts b/src/app/converter/hex-to-dec-converter.spec.ts index f01c833..4fc3f15 100644 --- a/src/app/converter/hex-to-dec-converter.spec.ts +++ b/src/app/converter/hex-to-dec-converter.spec.ts @@ -1,16 +1,23 @@ import {HexToDecConverter} from './hex-to-dec-converter'; describe('HexToDecConverter', () => { + let sut: HexToDecConverter; + + beforeEach(() => sut = new HexToDecConverter()); + it('should create an instance', () => { - expect(new HexToDecConverter()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "hextodec"', () => { - expect(new HexToDecConverter().getId()).toEqual('hextodec'); + expect(sut.getId()).toEqual('hextodec'); }); + it('should convert "ab" to "171"', () => { - expect(new HexToDecConverter().convert('ab')).toEqual('171'); + expect(sut.convert('ab')).toEqual('171'); }); + it('should raise an exception on invalid input', () => { - expect(() => new HexToDecConverter().convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.'); + expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.'); }); }); diff --git a/src/app/converter/htmlentities-decoder.spec.ts b/src/app/converter/htmlentities-decoder.spec.ts index 08136ea..9130639 100644 --- a/src/app/converter/htmlentities-decoder.spec.ts +++ b/src/app/converter/htmlentities-decoder.spec.ts @@ -1,14 +1,20 @@ import {HTMLEntitiesDecoder} from './htmlentities-decoder'; describe('HTMLEntitiesDecoder', () => { + let sut: HTMLEntitiesDecoder; + + beforeEach(() => sut = new HTMLEntitiesDecoder()); + it('should create an instance', () => { - expect(new HTMLEntitiesDecoder()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "decodehtmlentities"', () => { - expect(new HTMLEntitiesDecoder().getId()).toEqual('decodehtmlentities'); + expect(sut.getId()).toEqual('decodehtmlentities'); }); + it('should decode "<span>"Hi" & "Lo"</span>" to ""Hi" & "Lo""', () => { - expect(new HTMLEntitiesDecoder().convert('<span>"Hi" & "Lo"</span>')) + expect(sut.convert('<span>"Hi" & "Lo"</span>')) .toEqual('"Hi" & "Lo"'); }); }); diff --git a/src/app/converter/htmlentities-encoder.spec.ts b/src/app/converter/htmlentities-encoder.spec.ts index 5c6aa09..94319fa 100644 --- a/src/app/converter/htmlentities-encoder.spec.ts +++ b/src/app/converter/htmlentities-encoder.spec.ts @@ -1,14 +1,20 @@ import {HTMLEntitiesEncoder} from './htmlentities-encoder'; describe('HTMLEntitiesEncoder', () => { + let sut: HTMLEntitiesEncoder; + + beforeEach(() => sut = new HTMLEntitiesEncoder()); + it('should create an instance', () => { - expect(new HTMLEntitiesEncoder()).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "encodehtmlentities"', () => { - expect(new HTMLEntitiesEncoder().getId()).toEqual('encodehtmlentities'); + expect(sut.getId()).toEqual('encodehtmlentities'); }); + it('should encode ""Hi" & "Lo"" to "<span>"Hi" & "Lo"</span>"', () => { - expect(new HTMLEntitiesEncoder().convert('"Hi" & "Lo"')) + expect(sut.convert('"Hi" & "Lo"')) .toEqual('<span>"Hi" & "Lo"</span>'); }); }); diff --git a/src/app/converter/punycode-decoder.spec.ts b/src/app/converter/punycode-decoder.spec.ts index 12c21e9..ab3e8d3 100644 --- a/src/app/converter/punycode-decoder.spec.ts +++ b/src/app/converter/punycode-decoder.spec.ts @@ -4,23 +4,29 @@ import createSpyObj = jasmine.createSpyObj; import Spy = jasmine.Spy; describe('PunycodeDecoder', () => { + let sut: PunycodeDecoder; let nativeWrapperSpy: Partial; let decodeSpy: Spy; + beforeEach(() => { nativeWrapperSpy = {punycode: createSpyObj(['decode'])}; decodeSpy = nativeWrapperSpy.punycode.decode as Spy; + sut = new PunycodeDecoder((nativeWrapperSpy as NativeLibraryWrapperService)); }); + it('should create an instance', () => { - expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "decodepunycode"', () => { - expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('decodepunycode'); + expect(sut.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); + const result: string = sut.convert(testInput); expect(result).toEqual(expectedOutput); expect(decodeSpy).toHaveBeenCalledWith(testInput); }); diff --git a/src/app/converter/punycode-encoder.spec.ts b/src/app/converter/punycode-encoder.spec.ts index 9da3d8a..8c872b0 100644 --- a/src/app/converter/punycode-encoder.spec.ts +++ b/src/app/converter/punycode-encoder.spec.ts @@ -4,23 +4,29 @@ import createSpyObj = jasmine.createSpyObj; import Spy = jasmine.Spy; describe('PunycodeEncoder', () => { + let sut: PunycodeEncoder; let nativeWrapperSpy: Partial; let encodeSpy: Spy; + beforeEach(() => { nativeWrapperSpy = {punycode: createSpyObj(['encode'])}; encodeSpy = nativeWrapperSpy.punycode.encode as Spy; + sut = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService); }); + it('should create an instance', () => { - expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy(); + expect(sut).toBeTruthy(); }); + it('should have the id "encodepunycode"', () => { - expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('encodepunycode'); + expect(sut.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); + const result: string = sut.convert(testInput); expect(result).toEqual(expectedOutput); expect(encodeSpy).toHaveBeenCalledWith(testInput); }); -- 2.45.2 From 0a6a397e2979fa018c5485302b5acb922d60e4fe Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:38:42 +0200 Subject: [PATCH 12/19] 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 -- 2.45.2 From fee46220444a37eff6ddc2a9086ac9c7e3aae6b6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:44:24 +0200 Subject: [PATCH 13/19] Fixed ROT13Converter file name, changed its ID and added tests. --- src/app/converter-registry.service.ts | 2 +- src/app/converter/rot13-converter.spec.ts | 24 +++++++++++++++++++ .../{rot13converter.ts => rot13-converter.ts} | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/rot13-converter.spec.ts rename src/app/converter/{rot13converter.ts => rot13-converter.ts} (96%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index a4721c6..d6f6714 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -13,7 +13,7 @@ import {PunycodeDecoder} from './converter/punycode-decoder'; import {PunycodeEncoder} from './converter/punycode-encoder'; import {QuotedPrintableDecoder} from './converter/quoted-printable-decoder'; import {QuotedPrintableEncoder} from './converter/quoted-printable-encoder'; -import {ROT13Converter} from './converter/rot13converter'; +import {ROT13Converter} from './converter/rot13-converter'; import {URIComponentDecoder} from './converter/uricomponentdecoder'; import {URIComponentEncoder} from './converter/uricomponentencoder'; import {URIDecoder} from './converter/uridecoder'; diff --git a/src/app/converter/rot13-converter.spec.ts b/src/app/converter/rot13-converter.spec.ts new file mode 100644 index 0000000..76e472d --- /dev/null +++ b/src/app/converter/rot13-converter.spec.ts @@ -0,0 +1,24 @@ +import {ROT13Converter} from './rot13-converter'; + +describe('ROT13Converter', () => { + let sut: ROT13Converter; + + beforeEach(() => sut = new ROT13Converter()); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "rot13"', () => { + expect(sut.getId()).toEqual('rot13'); + }); + + it('should encode "Hello, World!" to "Uryyb, Jbeyq!"', () => { + expect(sut.convert('Hello, World!')).toEqual('Uryyb, Jbeyq!'); + }); + + it('should return the original input after being applied twice', () => { + const input = 'Ok, so this string is just a bunch of letters. And numbers: 1, 2, 3. Ans others: /&%. Kthxbye!'; + expect(sut.convert(sut.convert(input))).toEqual(input); + }); +}); diff --git a/src/app/converter/rot13converter.ts b/src/app/converter/rot13-converter.ts similarity index 96% rename from src/app/converter/rot13converter.ts rename to src/app/converter/rot13-converter.ts index ed51b5d..0bc9df5 100644 --- a/src/app/converter/rot13converter.ts +++ b/src/app/converter/rot13-converter.ts @@ -6,7 +6,7 @@ export class ROT13Converter implements Converter { } getId(): string { - return 'rot13convert'; + return 'rot13'; } convert(input: string): string { -- 2.45.2 From 626b3b46558713ebe2328193b764e92288f9e4c3 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:53:52 +0200 Subject: [PATCH 14/19] Fixed URIComponent{De,En}coder file names and added tests. --- src/app/converter-registry.service.ts | 4 ++-- .../converter/uricomponent-decoder.spec.ts | 21 +++++++++++++++++++ ...nentdecoder.ts => uricomponent-decoder.ts} | 0 .../converter/uricomponent-encoder.spec.ts | 21 +++++++++++++++++++ ...nentencoder.ts => uricomponent-encoder.ts} | 0 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/uricomponent-decoder.spec.ts rename src/app/converter/{uricomponentdecoder.ts => uricomponent-decoder.ts} (100%) create mode 100644 src/app/converter/uricomponent-encoder.spec.ts rename src/app/converter/{uricomponentencoder.ts => uricomponent-encoder.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index d6f6714..56e488d 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -14,8 +14,8 @@ import {PunycodeEncoder} from './converter/punycode-encoder'; import {QuotedPrintableDecoder} from './converter/quoted-printable-decoder'; import {QuotedPrintableEncoder} from './converter/quoted-printable-encoder'; import {ROT13Converter} from './converter/rot13-converter'; -import {URIComponentDecoder} from './converter/uricomponentdecoder'; -import {URIComponentEncoder} from './converter/uricomponentencoder'; +import {URIComponentDecoder} from './converter/uricomponent-decoder'; +import {URIComponentEncoder} from './converter/uricomponent-encoder'; import {URIDecoder} from './converter/uridecoder'; import {URIEncoder} from './converter/uriencoder'; import {UTF8Decoder} from './converter/utf8decoder'; diff --git a/src/app/converter/uricomponent-decoder.spec.ts b/src/app/converter/uricomponent-decoder.spec.ts new file mode 100644 index 0000000..b24ee94 --- /dev/null +++ b/src/app/converter/uricomponent-decoder.spec.ts @@ -0,0 +1,21 @@ +import {URIComponentDecoder} from './uricomponent-decoder'; + +describe('URIComponentDecoder', () => { + let sut: URIComponentDecoder; + + beforeEach(() => sut = new URIComponentDecoder()); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "uricomponentdecode"', () => { + expect(sut.getId()).toEqual('uricomponentdecode'); + }); + + it('should decode "http%3A%2F%2Fm%C3%A4nu%3Agh%C3%ABim%40host%3Aport%2Fhi.there%3Foh%3Dwell%23ya" ' + + 'to "http://mänu:ghëim@host:port/hi.there?oh=well#ya"', () => { + expect(sut.convert('http%3A%2F%2Fm%C3%A4nu%3Agh%C3%ABim%40host%3Aport%2Fhi.there%3Foh%3Dwell%23ya')) + .toEqual('http://mänu:ghëim@host:port/hi.there?oh=well#ya'); + }); +}); diff --git a/src/app/converter/uricomponentdecoder.ts b/src/app/converter/uricomponent-decoder.ts similarity index 100% rename from src/app/converter/uricomponentdecoder.ts rename to src/app/converter/uricomponent-decoder.ts diff --git a/src/app/converter/uricomponent-encoder.spec.ts b/src/app/converter/uricomponent-encoder.spec.ts new file mode 100644 index 0000000..8aa582d --- /dev/null +++ b/src/app/converter/uricomponent-encoder.spec.ts @@ -0,0 +1,21 @@ +import {URIComponentEncoder} from './uricomponent-encoder'; + +describe('URIComponentEncoder', () => { + let sut: URIComponentEncoder; + + beforeEach(() => sut = new URIComponentEncoder()); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "uricomponentencode"', () => { + expect(sut.getId()).toEqual('uricomponentencode'); + }); + + it('should encode "http://mänu:ghëim@host:port/hi.there?oh=well#ya" ' + + 'to "http%3A%2F%2Fm%C3%A4nu%3Agh%C3%ABim%40host%3Aport%2Fhi.there%3Foh%3Dwell%23ya"', () => { + expect(sut.convert('http://mänu:ghëim@host:port/hi.there?oh=well#ya')) + .toEqual('http%3A%2F%2Fm%C3%A4nu%3Agh%C3%ABim%40host%3Aport%2Fhi.there%3Foh%3Dwell%23ya'); + }); +}); diff --git a/src/app/converter/uricomponentencoder.ts b/src/app/converter/uricomponent-encoder.ts similarity index 100% rename from src/app/converter/uricomponentencoder.ts rename to src/app/converter/uricomponent-encoder.ts -- 2.45.2 From d1dde13befcb4d460013f1b413716d8081fa7d7d Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 00:58:41 +0200 Subject: [PATCH 15/19] Added tests for URI{De,En}coder. --- src/app/converter/uridecoder.spec.ts | 21 +++++++++++++++++++++ src/app/converter/uriencoder.spec.ts | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/app/converter/uridecoder.spec.ts create mode 100644 src/app/converter/uriencoder.spec.ts diff --git a/src/app/converter/uridecoder.spec.ts b/src/app/converter/uridecoder.spec.ts new file mode 100644 index 0000000..7e45297 --- /dev/null +++ b/src/app/converter/uridecoder.spec.ts @@ -0,0 +1,21 @@ +import {URIDecoder} from './uridecoder'; + +describe('URIDecoder', () => { + let sut: URIDecoder; + + beforeEach(() => sut = new URIDecoder()); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "uridecode"', () => { + expect(sut.getId()).toEqual('uridecode'); + }); + + it('should decode "http://m%C3%A4nu:gh%C3%ABim@host:port/hi.there?oh=well#ya" ' + + 'to "http://mänu:ghëim@host:port/hi.there?oh=well#ya"', () => { + expect(sut.convert('http://m%C3%A4nu:gh%C3%ABim@host:port/hi.there?oh=well#ya')) + .toEqual('http://mänu:ghëim@host:port/hi.there?oh=well#ya'); + }); +}); diff --git a/src/app/converter/uriencoder.spec.ts b/src/app/converter/uriencoder.spec.ts new file mode 100644 index 0000000..52f0a20 --- /dev/null +++ b/src/app/converter/uriencoder.spec.ts @@ -0,0 +1,21 @@ +import {URIEncoder} from './uriencoder'; + +describe('URIEncoder', () => { + let sut: URIEncoder; + + beforeEach(() => sut = new URIEncoder()); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "uriencode"', () => { + expect(sut.getId()).toEqual('uriencode'); + }); + + it('should encode "http://mänu:ghëim@host:port/hi.there?oh=well#ya" ' + + 'to "http://m%C3%A4nu:gh%C3%ABim@host:port/hi.there?oh=well#ya"', () => { + expect(sut.convert('http://mänu:ghëim@host:port/hi.there?oh=well#ya')) + .toEqual('http://m%C3%A4nu:gh%C3%ABim@host:port/hi.there?oh=well#ya'); + }); +}); -- 2.45.2 From 31c60f12a773c74421738c0fe2ebaf1a312b76d4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 01:01:50 +0200 Subject: [PATCH 16/19] Fixed UTF8{De,En}coder file names and added tests. --- src/app/converter-registry.service.ts | 4 +-- src/app/converter/utf8-decoder.spec.ts | 33 +++++++++++++++++++ .../{utf8decoder.ts => utf8-decoder.ts} | 0 src/app/converter/utf8-encoder.spec.ts | 33 +++++++++++++++++++ .../{utf8encoder.ts => utf8-encoder.ts} | 0 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/app/converter/utf8-decoder.spec.ts rename src/app/converter/{utf8decoder.ts => utf8-decoder.ts} (100%) create mode 100644 src/app/converter/utf8-encoder.spec.ts rename src/app/converter/{utf8encoder.ts => utf8-encoder.ts} (100%) diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 56e488d..d84733b 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -18,8 +18,8 @@ import {URIComponentDecoder} from './converter/uricomponent-decoder'; import {URIComponentEncoder} from './converter/uricomponent-encoder'; import {URIDecoder} from './converter/uridecoder'; import {URIEncoder} from './converter/uriencoder'; -import {UTF8Decoder} from './converter/utf8decoder'; -import {UTF8Encoder} from './converter/utf8encoder'; +import {UTF8Decoder} from './converter/utf8-decoder'; +import {UTF8Encoder} from './converter/utf8-encoder'; @Injectable({ providedIn: 'root' diff --git a/src/app/converter/utf8-decoder.spec.ts b/src/app/converter/utf8-decoder.spec.ts new file mode 100644 index 0000000..7eaf5c2 --- /dev/null +++ b/src/app/converter/utf8-decoder.spec.ts @@ -0,0 +1,33 @@ +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import {UTF8Decoder} from './utf8-decoder'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('UTF8Decoder', () => { + let sut: UTF8Decoder; + let nativeWrapperSpy: Partial; + let decodeSpy: Spy; + + beforeEach(() => { + nativeWrapperSpy = {utf8: createSpyObj(['decode'])}; + decodeSpy = nativeWrapperSpy.utf8.decode as Spy; + sut = new UTF8Decoder((nativeWrapperSpy as NativeLibraryWrapperService)); + }); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "decodeutf8"', () => { + expect(sut.getId()).toEqual('decodeutf8'); + }); + + it('should call through to the native UTF-8 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/utf8decoder.ts b/src/app/converter/utf8-decoder.ts similarity index 100% rename from src/app/converter/utf8decoder.ts rename to src/app/converter/utf8-decoder.ts diff --git a/src/app/converter/utf8-encoder.spec.ts b/src/app/converter/utf8-encoder.spec.ts new file mode 100644 index 0000000..334a26b --- /dev/null +++ b/src/app/converter/utf8-encoder.spec.ts @@ -0,0 +1,33 @@ +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import {UTF8Encoder} from './utf8-encoder'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('UTF8Encoder', () => { + let sut: UTF8Encoder; + let nativeWrapperSpy: Partial; + let encodeSpy: Spy; + + beforeEach(() => { + nativeWrapperSpy = {utf8: createSpyObj(['encode'])}; + encodeSpy = nativeWrapperSpy.utf8.encode as Spy; + sut = new UTF8Encoder(nativeWrapperSpy as NativeLibraryWrapperService); + }); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "encodeutf8"', () => { + expect(sut.getId()).toEqual('encodeutf8'); + }); + + it('should call through to the native UTF-8 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/utf8encoder.ts b/src/app/converter/utf8-encoder.ts similarity index 100% rename from src/app/converter/utf8encoder.ts rename to src/app/converter/utf8-encoder.ts -- 2.45.2 From a0590cc0db9276d6608ef4be0e8b5b7c5959fb5d Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 01:07:03 +0200 Subject: [PATCH 17/19] Added tests for the version component. --- src/app/version/version.component.spec.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/app/version/version.component.spec.ts b/src/app/version/version.component.spec.ts index fcd0475..fb1ae45 100644 --- a/src/app/version/version.component.spec.ts +++ b/src/app/version/version.component.spec.ts @@ -1,6 +1,7 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; -import { VersionComponent } from './version.component'; +import {VersionComponent} from './version.component'; +import {environment} from '../../environments/environment'; describe('VersionComponent', () => { let component: VersionComponent; @@ -8,9 +9,9 @@ describe('VersionComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ VersionComponent ] + declarations: [VersionComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { @@ -22,4 +23,14 @@ describe('VersionComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should contain the correct version', () => { + // when executing the test, we're always running with the dev environment + expect(component.VERSION).toEqual(`${environment.appVersion} (development build)`); + }); + + it('should have the correct value for the "production" property', () => { + // when executing the test, we're always running with the dev environment + expect(component.PROD).toBeFalsy(); + }); }); -- 2.45.2 From 77c4d5831d8fde7b6b53c45c67ce1df7e37251b3 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 01:20:41 +0200 Subject: [PATCH 18/19] Assert that each converter has a display name. --- src/app/converter/base64-decoder.spec.ts | 4 ++++ src/app/converter/base64-encoder.spec.ts | 4 ++++ src/app/converter/bin-to-dec-converter.spec.ts | 4 ++++ src/app/converter/dec-to-bin-converter.spec.ts | 4 ++++ src/app/converter/dec-to-hex-converter.spec.ts | 4 ++++ src/app/converter/hex-to-dec-converter.spec.ts | 4 ++++ src/app/converter/htmlentities-decoder.spec.ts | 4 ++++ src/app/converter/htmlentities-encoder.spec.ts | 4 ++++ src/app/converter/punycode-decoder.spec.ts | 4 ++++ src/app/converter/punycode-encoder.spec.ts | 4 ++++ src/app/converter/quoted-printable-decoder.spec.ts | 4 ++++ src/app/converter/quoted-printable-encoder.spec.ts | 4 ++++ src/app/converter/rot13-converter.spec.ts | 4 ++++ src/app/converter/uricomponent-decoder.spec.ts | 4 ++++ src/app/converter/uricomponent-encoder.spec.ts | 4 ++++ src/app/converter/uridecoder.spec.ts | 4 ++++ src/app/converter/uriencoder.spec.ts | 4 ++++ src/app/converter/utf8-decoder.spec.ts | 4 ++++ src/app/converter/utf8-encoder.spec.ts | 4 ++++ 19 files changed, 76 insertions(+) diff --git a/src/app/converter/base64-decoder.spec.ts b/src/app/converter/base64-decoder.spec.ts index 1e144c7..5e6aefa 100644 --- a/src/app/converter/base64-decoder.spec.ts +++ b/src/app/converter/base64-decoder.spec.ts @@ -9,6 +9,10 @@ describe('Base64Decoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "base64decode"', () => { expect(sut.getId()).toEqual('base64decode'); }); diff --git a/src/app/converter/base64-encoder.spec.ts b/src/app/converter/base64-encoder.spec.ts index a8a17aa..99e486a 100644 --- a/src/app/converter/base64-encoder.spec.ts +++ b/src/app/converter/base64-encoder.spec.ts @@ -9,6 +9,10 @@ describe('Base64Encoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "base64encode"', () => { expect(sut.getId()).toEqual('base64encode'); }); diff --git a/src/app/converter/bin-to-dec-converter.spec.ts b/src/app/converter/bin-to-dec-converter.spec.ts index 7629672..1439482 100644 --- a/src/app/converter/bin-to-dec-converter.spec.ts +++ b/src/app/converter/bin-to-dec-converter.spec.ts @@ -9,6 +9,10 @@ describe('BinToDecConverter', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "bintodec"', () => { expect(sut.getId()).toEqual('bintodec'); }); diff --git a/src/app/converter/dec-to-bin-converter.spec.ts b/src/app/converter/dec-to-bin-converter.spec.ts index 9022275..0b9a971 100644 --- a/src/app/converter/dec-to-bin-converter.spec.ts +++ b/src/app/converter/dec-to-bin-converter.spec.ts @@ -9,6 +9,10 @@ describe('DecToBinConverter', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "dectobin"', () => { expect(sut.getId()).toEqual('dectobin'); }); diff --git a/src/app/converter/dec-to-hex-converter.spec.ts b/src/app/converter/dec-to-hex-converter.spec.ts index 90e344b..4eecac4 100644 --- a/src/app/converter/dec-to-hex-converter.spec.ts +++ b/src/app/converter/dec-to-hex-converter.spec.ts @@ -9,6 +9,10 @@ describe('DecToHexConverter', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "dectohex"', () => { expect(sut.getId()).toEqual('dectohex'); }); diff --git a/src/app/converter/hex-to-dec-converter.spec.ts b/src/app/converter/hex-to-dec-converter.spec.ts index 4fc3f15..07003ed 100644 --- a/src/app/converter/hex-to-dec-converter.spec.ts +++ b/src/app/converter/hex-to-dec-converter.spec.ts @@ -9,6 +9,10 @@ describe('HexToDecConverter', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "hextodec"', () => { expect(sut.getId()).toEqual('hextodec'); }); diff --git a/src/app/converter/htmlentities-decoder.spec.ts b/src/app/converter/htmlentities-decoder.spec.ts index 9130639..a1555ad 100644 --- a/src/app/converter/htmlentities-decoder.spec.ts +++ b/src/app/converter/htmlentities-decoder.spec.ts @@ -9,6 +9,10 @@ describe('HTMLEntitiesDecoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "decodehtmlentities"', () => { expect(sut.getId()).toEqual('decodehtmlentities'); }); diff --git a/src/app/converter/htmlentities-encoder.spec.ts b/src/app/converter/htmlentities-encoder.spec.ts index 94319fa..1408d0d 100644 --- a/src/app/converter/htmlentities-encoder.spec.ts +++ b/src/app/converter/htmlentities-encoder.spec.ts @@ -9,6 +9,10 @@ describe('HTMLEntitiesEncoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "encodehtmlentities"', () => { expect(sut.getId()).toEqual('encodehtmlentities'); }); diff --git a/src/app/converter/punycode-decoder.spec.ts b/src/app/converter/punycode-decoder.spec.ts index ab3e8d3..3895c3e 100644 --- a/src/app/converter/punycode-decoder.spec.ts +++ b/src/app/converter/punycode-decoder.spec.ts @@ -18,6 +18,10 @@ describe('PunycodeDecoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "decodepunycode"', () => { expect(sut.getId()).toEqual('decodepunycode'); }); diff --git a/src/app/converter/punycode-encoder.spec.ts b/src/app/converter/punycode-encoder.spec.ts index 8c872b0..1bd8669 100644 --- a/src/app/converter/punycode-encoder.spec.ts +++ b/src/app/converter/punycode-encoder.spec.ts @@ -18,6 +18,10 @@ describe('PunycodeEncoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "encodepunycode"', () => { expect(sut.getId()).toEqual('encodepunycode'); }); diff --git a/src/app/converter/quoted-printable-decoder.spec.ts b/src/app/converter/quoted-printable-decoder.spec.ts index 15f8266..a74cb50 100644 --- a/src/app/converter/quoted-printable-decoder.spec.ts +++ b/src/app/converter/quoted-printable-decoder.spec.ts @@ -18,6 +18,10 @@ describe('QuotedPrintableDecoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "decodequotedprintable"', () => { expect(sut.getId()).toEqual('decodequotedprintable'); }); diff --git a/src/app/converter/quoted-printable-encoder.spec.ts b/src/app/converter/quoted-printable-encoder.spec.ts index cf4b3ca..da4191f 100644 --- a/src/app/converter/quoted-printable-encoder.spec.ts +++ b/src/app/converter/quoted-printable-encoder.spec.ts @@ -18,6 +18,10 @@ describe('QuotedPrintableEncoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "encodequotedprintable"', () => { expect(sut.getId()).toEqual('encodequotedprintable'); }); diff --git a/src/app/converter/rot13-converter.spec.ts b/src/app/converter/rot13-converter.spec.ts index 76e472d..dc4bd47 100644 --- a/src/app/converter/rot13-converter.spec.ts +++ b/src/app/converter/rot13-converter.spec.ts @@ -9,6 +9,10 @@ describe('ROT13Converter', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "rot13"', () => { expect(sut.getId()).toEqual('rot13'); }); diff --git a/src/app/converter/uricomponent-decoder.spec.ts b/src/app/converter/uricomponent-decoder.spec.ts index b24ee94..9125d74 100644 --- a/src/app/converter/uricomponent-decoder.spec.ts +++ b/src/app/converter/uricomponent-decoder.spec.ts @@ -9,6 +9,10 @@ describe('URIComponentDecoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "uricomponentdecode"', () => { expect(sut.getId()).toEqual('uricomponentdecode'); }); diff --git a/src/app/converter/uricomponent-encoder.spec.ts b/src/app/converter/uricomponent-encoder.spec.ts index 8aa582d..832f0fa 100644 --- a/src/app/converter/uricomponent-encoder.spec.ts +++ b/src/app/converter/uricomponent-encoder.spec.ts @@ -9,6 +9,10 @@ describe('URIComponentEncoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "uricomponentencode"', () => { expect(sut.getId()).toEqual('uricomponentencode'); }); diff --git a/src/app/converter/uridecoder.spec.ts b/src/app/converter/uridecoder.spec.ts index 7e45297..158862c 100644 --- a/src/app/converter/uridecoder.spec.ts +++ b/src/app/converter/uridecoder.spec.ts @@ -9,6 +9,10 @@ describe('URIDecoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "uridecode"', () => { expect(sut.getId()).toEqual('uridecode'); }); diff --git a/src/app/converter/uriencoder.spec.ts b/src/app/converter/uriencoder.spec.ts index 52f0a20..dbbbaec 100644 --- a/src/app/converter/uriencoder.spec.ts +++ b/src/app/converter/uriencoder.spec.ts @@ -9,6 +9,10 @@ describe('URIEncoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "uriencode"', () => { expect(sut.getId()).toEqual('uriencode'); }); diff --git a/src/app/converter/utf8-decoder.spec.ts b/src/app/converter/utf8-decoder.spec.ts index 7eaf5c2..919092e 100644 --- a/src/app/converter/utf8-decoder.spec.ts +++ b/src/app/converter/utf8-decoder.spec.ts @@ -18,6 +18,10 @@ describe('UTF8Decoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "decodeutf8"', () => { expect(sut.getId()).toEqual('decodeutf8'); }); diff --git a/src/app/converter/utf8-encoder.spec.ts b/src/app/converter/utf8-encoder.spec.ts index 334a26b..4e92288 100644 --- a/src/app/converter/utf8-encoder.spec.ts +++ b/src/app/converter/utf8-encoder.spec.ts @@ -18,6 +18,10 @@ describe('UTF8Encoder', () => { expect(sut).toBeTruthy(); }); + it('should have a display name', () => { + expect(sut.getDisplayname()).toBeTruthy(); + }); + it('should have the id "encodeutf8"', () => { expect(sut.getId()).toEqual('encodeutf8'); }); -- 2.45.2 From e7bdbfa8491b8f365caa19338dc699b19d122a91 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sat, 1 Sep 2018 01:21:06 +0200 Subject: [PATCH 19/19] Use spy objects. --- src/app/app.component.spec.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index adb0d4a..36d8222 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -4,32 +4,22 @@ import {FormsModule} from '@angular/forms'; import {InputComponentManagerService} from './input-component-manager.service'; import {Step} from './step'; import {ConverterRegistryService} from './converter-registry.service'; -import {Converter} from './converter/converter'; import {VersionComponent} from './version/version.component'; +import createSpyObj = jasmine.createSpyObj; describe('AppComponent', () => { let sut: AppComponent; let fixture: ComponentFixture; const firstStep: Step = new Step(0); - const inputComponentManagerServiceStub = { - getFirst: () => { - return firstStep; - } - }; + const inputComponentManagerServiceStub = createSpyObj(['getFirst']); + inputComponentManagerServiceStub.getFirst.and.returnValue(firstStep); - const converterRegistryServiceStub = { - getAllConverters: (): Converter[] => { - return []; - }, - - getConverter: (id: string): Converter => { - return undefined; - } - }; + const converterRegistryServiceStub = createSpyObj(['getAllConverters', 'getConverter']); + converterRegistryServiceStub.getAllConverters.and.returnValue([]); + converterRegistryServiceStub.getConverter.and.returnValue(undefined); beforeEach(async(() => { - /*return */ TestBed.configureTestingModule({ declarations: [AppComponent, VersionComponent], imports: [FormsModule], -- 2.45.2