Fixed QuotedPrintable{De,En}coder file names and added tests.

This commit is contained in:
Manuel Friedli 2018-09-01 00:38:42 +02:00
parent bdf15d277e
commit 0a6a397e29
5 changed files with 68 additions and 2 deletions

View File

@ -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';

View File

@ -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<NativeLibraryWrapperService>;
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);
});
});

View File

@ -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<NativeLibraryWrapperService>;
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);
});
});