summaryrefslogtreecommitdiff
path: root/lib/epub.js/test/book.js
blob: 4575fb2ef0c3890a28aec1f0c7b52ce71fb18dba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Book from '../src/book';
import assert from 'assert';

describe('Book', function() {

	describe('Unarchived', function() {
		var book = new Book("/fixtures/alice/OPS/package.opf");
		it('should open a epub', async function() {
			await book.opened
			assert.equal(book.isOpen, true, "book is opened");
			assert.equal( book.url.toString(), "http://localhost:9876/fixtures/alice/OPS/package.opf", "book url is passed to new Book" );
		});
		it('should have a local coverUrl', async function() {
			assert.equal( await book.coverUrl(), "http://localhost:9876/fixtures/alice/OPS/images/cover_th.jpg", "cover url is available" );
		});
	});

	describe('Archived epub', function() {
		var book = new Book("/fixtures/alice.epub");

		it('should open a archived epub', async function() {
			await book.opened
			assert.equal(book.isOpen, true, "book is opened");
			assert(book.archive, "book is unarchived");
		});
		it('should have a blob coverUrl', async function() {
			let coverUrl = await book.coverUrl()
			assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" );
		});
	});

	describe('Archived epub in array buffer without options', function() {
		let book;

		before(async function() {
			const response = await fetch("/fixtures/alice.epub");
			const buffer = await response.arrayBuffer()
			book = new Book(buffer)
		})

		it('should open a archived epub', async function() {
			await book.opened
			assert.equal(book.isOpen, true, "book is opened");
			assert(book.archive, "book is unarchived");
		});

		it('should have a blob coverUrl', async function() {
			let coverUrl = await book.coverUrl()
			assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" );
		});
	});

	describe('Archived epub without cover', function() {
		var book = new Book("/fixtures/alice_without_cover.epub");

		it('should open a archived epub', async function() {
			await book.opened
			assert.equal(book.isOpen, true, "book is opened");
			assert(book.archive, "book is unarchived");
		});
		it('should have a empty coverUrl', async function() {
			let coverUrl = await book.coverUrl()
			assert.equal(coverUrl, null, "cover url should be null" );
		});
	});
});