dynamicbible/DynamicBibleIonic/src/bible-service.spec.ts

69 lines
2.4 KiB
TypeScript
Raw Normal View History

import { getTestBed, TestBed, inject } from '@angular/core/testing';
import { XHRBackend, BaseRequestOptions, HttpModule, Http, } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { BibleService } from './bible-service';
import { Reference } from './Reference';
describe('Bible Service', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
BibleService,
{
provide: Http,
useFactory: function (backend, defaultOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
MockBackend,
BaseRequestOptions
]
});
});
it('Should get the verse: Gen 1:1', () => {
let svc: BibleService = getTestBed().get(BibleService);
let ref = new Reference("Gen 1:1").Section;
var r = svc.getResult(ref);
expect(r.msg).toBe(':)');
expect(r.ref).toBe('Genesis 1:1');
expect(r.status).toBe(0);
expect(r.testament).toBe("old");
expect(r.cs.length).toBe(1);
expect(r.cs[0].vss.length).toBe(1);
expect(r.cs[0].vss[0].w.length).toBe(9);
expect(r.cs[0].vss[0].w[0].t).toBe("In the");
});
it('Should get the passage: Gen 1:1-9', () => {
let svc: BibleService = getTestBed().get(BibleService);
let ref = new Reference("Gen 1:1-9").Section;
var r = svc.getResult(ref);
expect(r.msg).toBe(':)');
expect(r.ref).toBe('Genesis 1:1 - 9');
expect(r.status).toBe(0);
expect(r.testament).toBe("old");
expect(r.cs.length).toBe(1);
expect(r.cs[0].vss.length).toBe(9);
expect(r.cs[0].vss[0].w.length).toBe(9);
expect(r.cs[0].vss[0].w[0].t).toBe("In the");
});
it('Should return an error status', () => {
let svc: BibleService = getTestBed().get(BibleService);
let ref = new Reference("Gen 100:1").Section;
var r = svc.getResult(ref);
expect(r.msg).toBe('Unable to retrieve bible passage Genesis 100:1.');
expect(r.ref).toBe("Genesis 100:1");
expect(r.status).toBe(-1);
expect(r.testament).toBe('');
});
});