converter/src/app/converter/quoted-printable-encoder.sp...

38 lines
1.3 KiB
TypeScript

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 a display name', () => {
expect(sut.getDisplayname()).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);
});
});