2017-09-25 13:07:52 +02:00
|
|
|
import { TestBed, inject } from '@angular/core/testing';
|
|
|
|
|
2018-03-30 12:01:59 +02:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
|
|
|
import { HttpServer } from './http-server.service';
|
|
|
|
import { Server } from '../models/server';
|
|
|
|
import { getTestServer } from './testing';
|
2017-09-25 13:07:52 +02:00
|
|
|
import { SymbolService } from './symbol.service';
|
2018-06-27 10:29:12 +02:00
|
|
|
import { Symbol } from '../cartography/models/symbol';
|
2018-07-03 11:34:37 +02:00
|
|
|
import { AppTestingModule } from "../testing/app-testing/app-testing.module";
|
2018-03-30 12:01:59 +02:00
|
|
|
|
2017-09-25 13:07:52 +02:00
|
|
|
|
|
|
|
describe('SymbolService', () => {
|
2018-03-30 12:01:59 +02:00
|
|
|
let httpClient: HttpClient;
|
|
|
|
let httpTestingController: HttpTestingController;
|
|
|
|
let httpServer: HttpServer;
|
|
|
|
let service: SymbolService;
|
|
|
|
let server: Server;
|
|
|
|
|
2017-09-25 13:07:52 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({
|
2018-03-30 12:01:59 +02:00
|
|
|
imports: [
|
2018-07-03 11:34:37 +02:00
|
|
|
HttpClientTestingModule,
|
|
|
|
AppTestingModule
|
2018-03-30 12:01:59 +02:00
|
|
|
],
|
|
|
|
providers: [
|
|
|
|
HttpServer,
|
|
|
|
SymbolService
|
|
|
|
]
|
2017-09-25 13:07:52 +02:00
|
|
|
});
|
2018-03-30 12:01:59 +02:00
|
|
|
|
|
|
|
httpClient = TestBed.get(HttpClient);
|
|
|
|
httpTestingController = TestBed.get(HttpTestingController);
|
|
|
|
httpServer = TestBed.get(HttpServer);
|
|
|
|
service = TestBed.get(SymbolService);
|
|
|
|
server = getTestServer();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
httpTestingController.verify();
|
2017-09-25 13:07:52 +02:00
|
|
|
});
|
|
|
|
|
2018-03-30 12:01:59 +02:00
|
|
|
it('should be created', inject([SymbolService], (service: SymbolService) => {
|
|
|
|
expect(service).toBeTruthy();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should list symbols', inject([SymbolService], (service: SymbolService) => {
|
|
|
|
service.list(server).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/symbols');
|
|
|
|
expect(req.request.method).toEqual("GET");
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should get raw symbol', inject([SymbolService], (service: SymbolService) => {
|
|
|
|
service.raw(server, ':my/tested.png').subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/symbols/:my/tested.png/raw');
|
|
|
|
expect(req.request.method).toEqual("GET");
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should load symbols', inject([SymbolService], (service: SymbolService) => {
|
|
|
|
service.load(server).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/symbols');
|
|
|
|
|
|
|
|
req.flush([{ 'symbol_id': 'myid' }]);
|
|
|
|
|
|
|
|
const raw = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/symbols/myid/raw');
|
|
|
|
raw.flush('myraw');
|
|
|
|
|
|
|
|
service.symbols.subscribe(symbols => {
|
|
|
|
expect(symbols.length).toEqual(1);
|
|
|
|
expect(symbols[0].symbol_id).toEqual('myid');
|
|
|
|
expect(symbols[0].raw).toEqual('myraw');
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should get symbols', inject([SymbolService], (service: SymbolService) => {
|
|
|
|
const symbol = new Symbol();
|
|
|
|
symbol.symbol_id = "myid";
|
|
|
|
service.symbols.next([symbol]);
|
|
|
|
|
|
|
|
expect(service.get("myid").symbol_id).toEqual("myid");
|
|
|
|
}));
|
2017-09-25 13:07:52 +02:00
|
|
|
});
|