-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_book_player_page_generator.js
67 lines (56 loc) · 2.6 KB
/
test_book_player_page_generator.js
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
67
describe('BookPlayerPageGenerator()', function () {
var bppg, dlManager, dlManagerMock, chapterObjInstance, $test_div;
before(function () {
$test_div = $('<div></div>');
$test_div.appendTo('body');
dlManager = {
downloadBook: function (book_id, chapter_obj) {},
downloadChapter: function (book_obj) {}
};
dlManagerMock = sinon.mock(dlManager); // create wrapper object for dlManager
bookPlayerArgs = {
'bookDownloadManager': dlManager,
'selectors': {
'dlFullBook': '#downloadBook',
'dlChapter': '#downloadChapter',
'audioSource': '#audioSource',
}
};
bppg = new BookPlayerPageGenerator(bookPlayerArgs);
});
beforeEach(function () {
$test_div.empty();
$('<audio id="audioSource"></audio>').appendTo($test_div);
$('<button id="downloadChapter"></button>').appendTo($test_div);
$('<button id="downloadBook"></button>').appendTo($test_div);
});
beforeEach(function () {
chapterObjInstance = Object.create(CHAPTER_OBJECT); // prevents changes made to chapter obj from persisting between tests
});
describe('#generatePage()', function () {
it('generates download book and download chapter buttons that send messages to downloadManager object on click', function () {
bppg.generatePage({
book: BOOK_OBJECT,
chapter: chapterObjInstance
});
dlManagerMock.expects("downloadBook").once().withExactArgs(BOOK_OBJECT);
$('#downloadBook').trigger('click'); // should call dlManager's #downloadBook method
dlManagerMock.verify();
dlManagerMock.expects("downloadChapter").once().withExactArgs(BOOK_OBJECT.id, chapterObjInstance);
$('#downloadChapter').trigger('click');
dlManagerMock.verify();
});
it('sets the audio element\'s src property to the chapter audio url', function () {
bppg.generatePage({
book: BOOK_OBJECT,
chapter: chapterObjInstance
});
expect($('#audioSource').prop('src')).equal(chapterObjInstance.url);
});
/*it('updates chapter position property to match audio player position', function () {
bppg.generatePage({book: BOOK_OBJECT, chapter: chapterObjInstance});
$('#audioSource').currentTime = 10; // this doesn't work
expect(chapterObjInstance.position).equal('10'); // TODO research how to set audio src position
});*/
});
});