Skip to content

Commit c6daa96

Browse files
committed
test(book-static-data): add test for sync static bookdata service
1 parent 833f968 commit c6daa96

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/app/book/shared/book-static-data.service.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TestBed, inject } from '@angular/core/testing';
22

33
import { BookStaticDataService } from './book-static-data.service';
4+
import { Book } from './book';
45

56
describe('BookStaticDataService', () => {
67
beforeEach(() => {
@@ -12,4 +13,60 @@ describe('BookStaticDataService', () => {
1213
it('should be created', inject([BookStaticDataService], (service: BookStaticDataService) => {
1314
expect(service).toBeTruthy();
1415
}));
16+
17+
describe('getBooks()', () => {
18+
it('should return the complete array of data', inject([BookStaticDataService], (service: BookStaticDataService) => {
19+
expect(service.getBooks()).toBe(service.staticBookData);
20+
}));
21+
});
22+
23+
describe('getBook(isbn)', () => {
24+
it('should return the first elemnt of data', inject([BookStaticDataService], (service: BookStaticDataService) => {
25+
expect(service.getBook(123)).toBe(service.staticBookData[0]);
26+
}));
27+
});
28+
29+
describe('getBook(book)', () => {
30+
it('should return the book argument itself', inject([BookStaticDataService], (service: BookStaticDataService) => {
31+
const book: Book = service.staticBookData[0];
32+
expect(service.updateBook(book)).toBe(book);
33+
}));
34+
});
35+
36+
37+
describe('createBook(book)', () => {
38+
it('should return the book argument itself', inject([BookStaticDataService], (service: BookStaticDataService) => {
39+
const book: Book = {
40+
'title': 'The New Design Patterns',
41+
'subtitle': 'Elements of Reusable Object-Oriented Software',
42+
'isbn': '978-0-20163-361-0',
43+
'abstract': 'Capturing a wealth of experience about the design of object-oriented software, four top-notch designers present a catalog of simple and succinct solutions to commonly occurring design problems. Previously undocumented, these 23 patterns allow designers to create more flexible, elegant, and ultimately reusable designs without having to rediscover the design solutions themselves.',
44+
'numPages': 395,
45+
'author': 'Erich Gamma / Richard Helm / Ralph E. Johnson / John Vlissides',
46+
'publisher': {
47+
'name': 'Addison-Wesley',
48+
'url': 'http://www.addison-wesley.de/'
49+
}
50+
};
51+
expect(service.createBook(book)).toBe(book);
52+
}));
53+
54+
it('should add the new book to the dataset', inject([BookStaticDataService], (service: BookStaticDataService) => {
55+
const book: Book = {
56+
'title': 'The New Design Patterns',
57+
'subtitle': 'Elements of Reusable Object-Oriented Software',
58+
'isbn': '978-0-20163-361-0',
59+
'abstract': 'Capturing a wealth of experience about the design of object-oriented software, four top-notch designers present a catalog of simple and succinct solutions to commonly occurring design problems. Previously undocumented, these 23 patterns allow designers to create more flexible, elegant, and ultimately reusable designs without having to rediscover the design solutions themselves.',
60+
'numPages': 395,
61+
'author': 'Erich Gamma / Richard Helm / Ralph E. Johnson / John Vlissides',
62+
'publisher': {
63+
'name': 'Addison-Wesley',
64+
'url': 'http://www.addison-wesley.de/'
65+
}
66+
};
67+
service.createBook(book)
68+
expect(service.staticBookData.length).toBe(4);
69+
}));
70+
});
71+
1572
});

0 commit comments

Comments
 (0)