From 7d3aa7caabdc18712b6271e1e79e8656bd724890 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 16 Jul 2017 10:21:09 +0200 Subject: [PATCH] Help Service tests --- .../app/shared/services/help.service.spec.ts | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/Squidex/app/shared/services/help.service.spec.ts diff --git a/src/Squidex/app/shared/services/help.service.spec.ts b/src/Squidex/app/shared/services/help.service.spec.ts new file mode 100644 index 000000000..dfafe2939 --- /dev/null +++ b/src/Squidex/app/shared/services/help.service.spec.ts @@ -0,0 +1,82 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved + */ + +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { inject, TestBed } from '@angular/core/testing'; + +import { HelpService } from './../'; + +describe('AppClientsService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule + ], + providers: [ + HelpService + ] + }); + }); + + afterEach(inject([HttpTestingController], (httpMock: HttpTestingController) => { + httpMock.verify(); + })); + + it('should make get request to get help sections', + inject([HelpService, HttpTestingController], (helpService: HelpService, httpMock: HttpTestingController) => { + + let helpSections: string[] | null = null; + + helpService.getHelp('01-chapter/02-article').subscribe(result => { + helpSections = result; + }); + + const req = httpMock.expectOne('https://api.gitbook.com/book/squidex/squidex/contents/01-chapter/02-article.json'); + + expect(req.request.method).toEqual('GET'); + expect(req.request.headers.get('If-Match')).toBeNull(); + + req.flush({ + sections: [ + { + content: 'A test content with' + }, + { + content: 'A test content with a A Link' + }, + { + content: 'A test content with a Glossary Link' + } + ] + }); + + expect(helpSections).toEqual([ + 'A test content with', + 'A test content with a A Link', + 'A test content with a Glossary Link' + ]); + })); + + it('should return empty sections if get request fails', + inject([HelpService, HttpTestingController], (helpService: HelpService, httpMock: HttpTestingController) => { + + let helpSections: string[] | null = null; + + helpService.getHelp('01-chapter/02-article').subscribe(result => { + helpSections = result; + }); + + const req = httpMock.expectOne('https://api.gitbook.com/book/squidex/squidex/contents/01-chapter/02-article.json'); + + expect(req.request.method).toEqual('GET'); + expect(req.request.headers.get('If-Match')).toBeNull(); + + req.error({}); + + expect(helpSections).toEqual([]); + })); +}); \ No newline at end of file