corpus.service.spec.ts 1.67 KB
Newer Older
1
import {TestBed} from '@angular/core/testing';
2

3 4 5 6 7 8 9 10 11
import {CorpusService} from './corpus.service';
import {IonicStorageModule} from '@ionic/storage';
import {RouterModule} from '@angular/router';
import {TranslateTestingModule} from './translate-testing/translate-testing.module';
import {APP_BASE_HREF} from '@angular/common';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {HttpClient} from '@angular/common/http';
import {HelperService} from './helper.service';
import MockMC from './models/mock';
12 13

describe('CorpusService', () => {
14 15 16
    let httpClient: HttpClient;
    let httpTestingController: HttpTestingController;
    let corpusService: CorpusService;
17
    beforeEach(async () => {
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
        TestBed.configureTestingModule({
            imports: [
                HttpClientTestingModule,
                IonicStorageModule.forRoot(),
                RouterModule.forRoot([]),
                TranslateTestingModule,
            ],
            providers: [
                {provide: APP_BASE_HREF, useValue: '/'},
            ],
        });
        httpClient = TestBed.get(HttpClient);
        httpTestingController = TestBed.get(HttpTestingController);
        corpusService = TestBed.get(CorpusService);
    });
33

34 35 36 37
    afterEach(() => {
    });

    it('should be created', () => {
38
        expect(corpusService).toBeTruthy();
39 40
    });

41
    it('should load corpora',  (done) => {
42
        spyOn(HelperService, 'makeGetRequest').and.returnValue(Promise.resolve(MockMC.apiResponseCorporaGet));
43 44 45 46
        corpusService.initCorpusService().then(() => {
            expect(HelperService.makeGetRequest).toHaveBeenCalled();
            done();
        });
47
    });
48
});