aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-02-21 16:32:16 +0000
committer杨宇千 <crupest@outlook.com>2019-02-21 16:32:16 +0000
commit9ae2a899eb53b8ee31710a5533cdf21b0f14dafd (patch)
tree8f22c966d15d928a5587385f38b5284f0691b2de /Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts
parent35f8562f1f1db36a42c53ce42c39db3d615deb0f (diff)
parent504d770e51a07ca7765de725979412b6dacdcf15 (diff)
downloadtimeline-9ae2a899eb53b8ee31710a5533cdf21b0f14dafd.tar.gz
timeline-9ae2a899eb53b8ee31710a5533cdf21b0f14dafd.tar.bz2
timeline-9ae2a899eb53b8ee31710a5533cdf21b0f14dafd.zip
Merged PR 3: Add unit test for front side.
Related work items: #1
Diffstat (limited to 'Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts')
-rw-r--r--Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts71
1 files changed, 69 insertions, 2 deletions
diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts b/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts
index 529ba8cc..7e88ca52 100644
--- a/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts
+++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.spec.ts
@@ -1,12 +1,79 @@
import { TestBed } from '@angular/core/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+
+import { TodoListService, WorkItem, AzureDevOpsAccessInfo, WiqlResult, WiqlWorkItemResult, WorkItemResult } from './todo-list.service';
-import { TodoListService } from './todo-list.service';
describe('TodoListServiceService', () => {
- beforeEach(() => TestBed.configureTestingModule({}));
+ beforeEach(() => TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule]
+ }));
it('should be created', () => {
+
+ const service: TodoListService = TestBed.get(TodoListService);
+ expect(service).toBeTruthy();
+ });
+
+ it('should work well', () => {
const service: TodoListService = TestBed.get(TodoListService);
expect(service).toBeTruthy();
+
+ const mockWorkItems: WorkItem[] = [{
+ id: 0,
+ title: 'Test work item 1',
+ closed: true
+ }, {
+ id: 1,
+ title: 'Test work item 2',
+ closed: false
+ }];
+
+ service.getWorkItemList().subscribe(data => {
+ expect(data).toEqual(mockWorkItems);
+ });
+
+ const httpController: HttpTestingController = TestBed.get(HttpTestingController);
+
+ const mockAccessInfo: AzureDevOpsAccessInfo = {
+ username: 'testusername',
+ personalAccessToken: 'testtoken',
+ organization: 'testorganization',
+ project: 'testproject'
+ };
+
+ httpController.expectOne('/api/TodoPage/AzureDevOpsAccessInfo').flush(mockAccessInfo);
+
+ const mockWiqlWorkItems: WiqlWorkItemResult[] = [{
+ id: 0,
+ url: `https://dev.azure.com/${mockAccessInfo.organization}/${mockAccessInfo.project}/_apis/wit/workItems/0`
+ }, {
+ id: 1,
+ url: `https://dev.azure.com/${mockAccessInfo.organization}/${mockAccessInfo.project}/_apis/wit/workItems/1`
+ }];
+
+ const authorizationHeader = 'Basic ' + btoa(mockAccessInfo.username + ':' + mockAccessInfo.personalAccessToken);
+
+ httpController.expectOne(req =>
+ req.url === `https://dev.azure.com/${mockAccessInfo.organization}/${mockAccessInfo.project}/_apis/wit/wiql?api-version=5.0` &&
+ req.headers.get('Authorization') === authorizationHeader
+ ).flush(<WiqlResult>{ workItems: mockWiqlWorkItems });
+
+ function mapWorkItemToResult(workItem: WorkItem): WorkItemResult {
+ return {
+ id: workItem.id,
+ fields: {
+ [TodoListService.titleFieldName]: workItem.title,
+ [TodoListService.stateFieldName]: (workItem.closed ? 'Closed' : 'Active')
+ }
+ };
+ }
+
+ for (let i = 0; i < mockWorkItems.length; i++) {
+ httpController.expectOne(req =>
+ req.url === mockWiqlWorkItems[i].url &&
+ req.headers.get('Authorization') === authorizationHeader
+ ).flush(mapWorkItemToResult(mockWorkItems[i]));
+ }
});
});