@internetarchive/bookreader 5.0.0-7-multiple-files → 5.0.0-70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/.eslintrc.js +17 -15
  2. package/.github/workflows/node.js.yml +78 -6
  3. package/.github/workflows/npm-publish.yml +6 -20
  4. package/.testcaferc.js +10 -0
  5. package/BookReader/BookReader.css +416 -1365
  6. package/BookReader/BookReader.js +2 -21564
  7. package/BookReader/BookReader.js.LICENSE.txt +20 -20
  8. package/BookReader/BookReader.js.map +1 -1
  9. package/BookReader/ia-bookreader-bundle.js +1509 -0
  10. package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +19 -0
  11. package/BookReader/ia-bookreader-bundle.js.map +1 -0
  12. package/BookReader/icons/1up.svg +1 -12
  13. package/BookReader/icons/2up.svg +1 -15
  14. package/BookReader/icons/advance.svg +3 -26
  15. package/BookReader/icons/chevron-right.svg +1 -1
  16. package/BookReader/icons/close-circle-dark.svg +1 -0
  17. package/BookReader/icons/close-circle.svg +1 -1
  18. package/BookReader/icons/fullscreen.svg +1 -17
  19. package/BookReader/icons/fullscreen_exit.svg +1 -17
  20. package/BookReader/icons/hamburger.svg +1 -15
  21. package/BookReader/icons/left-arrow.svg +1 -12
  22. package/BookReader/icons/magnify-minus.svg +1 -16
  23. package/BookReader/icons/magnify-plus.svg +1 -17
  24. package/BookReader/icons/magnify.svg +1 -15
  25. package/BookReader/icons/pause.svg +1 -23
  26. package/BookReader/icons/play.svg +1 -22
  27. package/BookReader/icons/playback-speed.svg +1 -34
  28. package/BookReader/icons/read-aloud.svg +1 -22
  29. package/BookReader/icons/review.svg +3 -22
  30. package/BookReader/icons/thumbnails.svg +1 -17
  31. package/BookReader/icons/voice.svg +1 -0
  32. package/BookReader/icons/volume-full.svg +1 -22
  33. package/BookReader/images/BRicons.svg +5 -94
  34. package/BookReader/images/books_graphic.svg +1 -177
  35. package/BookReader/images/icon_book.svg +1 -12
  36. package/BookReader/images/icon_bookmark.svg +1 -12
  37. package/BookReader/images/icon_gear.svg +1 -14
  38. package/BookReader/images/icon_hamburger.svg +1 -20
  39. package/BookReader/images/icon_home.svg +1 -21
  40. package/BookReader/images/icon_info.svg +1 -11
  41. package/BookReader/images/icon_one_page.svg +1 -8
  42. package/BookReader/images/icon_pause.svg +1 -1
  43. package/BookReader/images/icon_play.svg +1 -1
  44. package/BookReader/images/icon_playback-rate.svg +1 -15
  45. package/BookReader/images/icon_search_button.svg +1 -8
  46. package/BookReader/images/icon_share.svg +1 -9
  47. package/BookReader/images/icon_skip-ahead.svg +1 -6
  48. package/BookReader/images/icon_skip-back.svg +2 -13
  49. package/BookReader/images/icon_speaker.svg +1 -18
  50. package/BookReader/images/icon_speaker_open.svg +1 -10
  51. package/BookReader/images/icon_thumbnails.svg +1 -12
  52. package/BookReader/images/icon_toc.svg +1 -5
  53. package/BookReader/images/icon_two_pages.svg +1 -9
  54. package/BookReader/images/marker_chap-off.svg +1 -11
  55. package/BookReader/images/marker_chap-on.svg +1 -11
  56. package/BookReader/images/marker_srch-on.svg +1 -11
  57. package/BookReader/jquery-3.js +2 -0
  58. package/BookReader/jquery-3.js.LICENSE.txt +24 -0
  59. package/BookReader/plugins/plugin.archive_analytics.js +1 -172
  60. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  61. package/BookReader/plugins/plugin.autoplay.js +1 -165
  62. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  63. package/BookReader/plugins/plugin.chapters.js +22 -301
  64. package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +1 -0
  65. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  66. package/BookReader/plugins/plugin.iframe.js +1 -74
  67. package/BookReader/plugins/plugin.iframe.js.map +1 -1
  68. package/BookReader/plugins/plugin.resume.js +1 -368
  69. package/BookReader/plugins/plugin.resume.js.map +1 -1
  70. package/BookReader/plugins/plugin.search.js +2 -1420
  71. package/BookReader/plugins/plugin.search.js.LICENSE.txt +1 -0
  72. package/BookReader/plugins/plugin.search.js.map +1 -1
  73. package/BookReader/plugins/plugin.text_selection.js +2 -1080
  74. package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +1 -0
  75. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  76. package/BookReader/plugins/plugin.tts.js +2 -9193
  77. package/BookReader/plugins/plugin.tts.js.LICENSE.txt +2 -0
  78. package/BookReader/plugins/plugin.tts.js.map +1 -1
  79. package/BookReader/plugins/plugin.url.js +1 -269
  80. package/BookReader/plugins/plugin.url.js.map +1 -1
  81. package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -379
  82. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  83. package/BookReader/webcomponents-bundle.js +3 -0
  84. package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
  85. package/BookReader/webcomponents-bundle.js.map +1 -0
  86. package/BookReaderDemo/BookReaderDemo.css +16 -19
  87. package/BookReaderDemo/BookReaderJSAdvanced.js +0 -3
  88. package/BookReaderDemo/BookReaderJSAutoplay.js +4 -1
  89. package/BookReaderDemo/BookReaderJSSimple.js +1 -0
  90. package/BookReaderDemo/IADemoBr.js +147 -0
  91. package/BookReaderDemo/demo-advanced.html +2 -2
  92. package/BookReaderDemo/demo-autoplay.html +2 -3
  93. package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
  94. package/BookReaderDemo/demo-fullscreen-mobile.html +3 -5
  95. package/BookReaderDemo/demo-fullscreen.html +2 -4
  96. package/BookReaderDemo/demo-iiif.html +2 -1
  97. package/BookReaderDemo/demo-iiif.js +0 -1
  98. package/BookReaderDemo/demo-internetarchive.html +213 -17
  99. package/BookReaderDemo/demo-multiple.html +2 -1
  100. package/BookReaderDemo/demo-preview-pages.html +2 -1
  101. package/BookReaderDemo/demo-simple.html +2 -1
  102. package/BookReaderDemo/demo-vendor-fullscreen.html +2 -4
  103. package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
  104. package/BookReaderDemo/immersion-1up.html +2 -2
  105. package/BookReaderDemo/immersion-mode.html +2 -4
  106. package/BookReaderDemo/toggle_controls.html +3 -2
  107. package/BookReaderDemo/view_mode.html +2 -1
  108. package/BookReaderDemo/viewmode-cycle.html +2 -3
  109. package/CHANGELOG.md +289 -0
  110. package/README.md +14 -1
  111. package/babel.config.js +20 -0
  112. package/codecov.yml +6 -0
  113. package/index.html +4 -1
  114. package/jsconfig.json +19 -0
  115. package/netlify.toml +9 -0
  116. package/package.json +71 -60
  117. package/renovate.json +52 -0
  118. package/scripts/preversion.js +4 -1
  119. package/src/BookNavigator/assets/bookmark-colors.js +1 -1
  120. package/src/BookNavigator/assets/button-base.js +9 -2
  121. package/src/BookNavigator/assets/ia-logo.js +17 -0
  122. package/src/BookNavigator/assets/icon_checkmark.js +1 -1
  123. package/src/BookNavigator/assets/icon_close.js +1 -1
  124. package/src/BookNavigator/assets/icon_sort_asc.js +5 -0
  125. package/src/BookNavigator/assets/{icon_sort_ascending.js → icon_sort_desc.js} +2 -2
  126. package/src/BookNavigator/assets/icon_sort_neutral.js +5 -0
  127. package/src/BookNavigator/assets/icon_volumes.js +11 -0
  128. package/src/BookNavigator/book-navigator.js +586 -0
  129. package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
  130. package/src/BookNavigator/bookmarks/bookmark-edit.js +3 -4
  131. package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
  132. package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +3 -8
  133. package/src/BookNavigator/bookmarks/bookmarks-provider.js +27 -17
  134. package/src/BookNavigator/bookmarks/ia-bookmarks.js +116 -67
  135. package/src/BookNavigator/delete-modal-actions.js +1 -1
  136. package/src/BookNavigator/downloads/downloads-provider.js +36 -21
  137. package/src/BookNavigator/downloads/downloads.js +41 -25
  138. package/src/BookNavigator/search/search-provider.js +80 -28
  139. package/src/BookNavigator/search/search-results.js +28 -25
  140. package/src/BookNavigator/sharing.js +27 -0
  141. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -10
  142. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
  143. package/src/BookNavigator/volumes/volumes-provider.js +88 -53
  144. package/src/BookNavigator/volumes/volumes.js +41 -14
  145. package/src/BookReader/BookModel.js +64 -34
  146. package/src/BookReader/DragScrollable.js +233 -0
  147. package/src/BookReader/Mode1Up.js +56 -351
  148. package/src/BookReader/Mode1UpLit.js +388 -0
  149. package/src/BookReader/Mode2Up.js +73 -1318
  150. package/src/BookReader/Mode2UpLit.js +776 -0
  151. package/src/BookReader/ModeCoordinateSpace.js +29 -0
  152. package/src/BookReader/ModeSmoothZoom.js +312 -0
  153. package/src/BookReader/ModeThumb.js +18 -12
  154. package/src/BookReader/Navbar/Navbar.js +12 -38
  155. package/src/BookReader/PageContainer.js +81 -6
  156. package/src/BookReader/ReduceSet.js +1 -1
  157. package/src/BookReader/Toolbar/Toolbar.js +10 -37
  158. package/src/BookReader/events.js +2 -3
  159. package/src/BookReader/options.js +24 -2
  160. package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
  161. package/src/BookReader/utils/ScrollClassAdder.js +31 -0
  162. package/src/BookReader/utils/SelectionObserver.js +43 -0
  163. package/src/BookReader/utils.js +118 -13
  164. package/src/BookReader.js +446 -1062
  165. package/src/assets/icons/close-circle-dark.svg +1 -0
  166. package/src/assets/icons/magnify-minus.svg +3 -7
  167. package/src/assets/icons/magnify-plus.svg +3 -7
  168. package/src/assets/icons/voice.svg +1 -0
  169. package/src/css/BookReader.scss +1 -17
  170. package/src/css/_BRBookmarks.scss +1 -1
  171. package/src/css/_BRComponent.scss +1 -1
  172. package/src/css/_BRmain.scss +33 -24
  173. package/src/css/_BRnav.scss +11 -38
  174. package/src/css/_BRpages.scss +149 -40
  175. package/src/css/_BRsearch.scss +67 -226
  176. package/src/css/_TextSelection.scss +87 -27
  177. package/src/css/_colorbox.scss +2 -2
  178. package/src/css/_controls.scss +20 -7
  179. package/src/css/_icons.scss +7 -1
  180. package/src/ia-bookreader/ia-bookreader.js +224 -0
  181. package/src/plugins/plugin.archive_analytics.js +3 -3
  182. package/src/plugins/plugin.autoplay.js +5 -11
  183. package/src/plugins/plugin.chapters.js +211 -186
  184. package/src/plugins/plugin.resume.js +3 -3
  185. package/src/plugins/plugin.text_selection.js +464 -134
  186. package/src/plugins/plugin.vendor-fullscreen.js +4 -4
  187. package/src/plugins/search/plugin.search.js +175 -120
  188. package/src/plugins/search/utils.js +43 -0
  189. package/src/plugins/search/view.js +64 -202
  190. package/src/plugins/tts/AbstractTTSEngine.js +68 -40
  191. package/src/plugins/tts/FestivalTTSEngine.js +13 -14
  192. package/src/plugins/tts/PageChunk.js +15 -21
  193. package/src/plugins/tts/PageChunkIterator.js +8 -12
  194. package/src/plugins/tts/WebTTSEngine.js +87 -71
  195. package/src/plugins/tts/plugin.tts.js +95 -126
  196. package/src/plugins/tts/utils.js +0 -25
  197. package/src/plugins/url/UrlPlugin.js +191 -0
  198. package/src/plugins/{plugin.url.js → url/plugin.url.js} +45 -16
  199. package/src/util/browserSniffing.js +22 -0
  200. package/src/util/docCookies.js +21 -2
  201. package/tests/e2e/README.md +37 -0
  202. package/tests/e2e/autoplay.test.js +2 -2
  203. package/tests/e2e/base.test.js +8 -16
  204. package/tests/e2e/helpers/base.js +53 -48
  205. package/tests/e2e/helpers/debug.js +1 -1
  206. package/tests/e2e/helpers/params.js +17 -0
  207. package/tests/e2e/helpers/rightToLeft.js +8 -14
  208. package/tests/e2e/helpers/search.js +73 -0
  209. package/tests/e2e/models/Navigation.js +20 -37
  210. package/tests/e2e/rightToLeft.test.js +4 -5
  211. package/tests/e2e/viewmode.test.js +40 -33
  212. package/tests/jest/BookNavigator/book-navigator.test.js +658 -0
  213. package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +43 -0
  214. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
  215. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
  216. package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
  217. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +67 -0
  218. package/tests/jest/BookNavigator/downloads/downloads.test.js +53 -0
  219. package/tests/jest/BookNavigator/search/search-provider.test.js +167 -0
  220. package/tests/{karma/BookNavigator → jest/BookNavigator/search}/search-results.test.js +109 -60
  221. package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
  222. package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
  223. package/tests/jest/BookNavigator/volumes/volumes-provider.test.js +184 -0
  224. package/tests/jest/BookNavigator/volumes/volumes.test.js +97 -0
  225. package/tests/{BookReader → jest/BookReader}/BookModel.test.js +74 -14
  226. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +193 -0
  227. package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
  228. package/tests/jest/BookReader/Mode1UpLit.test.js +73 -0
  229. package/tests/jest/BookReader/Mode2Up.test.js +98 -0
  230. package/tests/jest/BookReader/Mode2UpLit.test.js +190 -0
  231. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +16 -0
  232. package/tests/jest/BookReader/ModeSmoothZoom.test.js +218 -0
  233. package/tests/jest/BookReader/ModeThumb.test.js +71 -0
  234. package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +10 -10
  235. package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +88 -6
  236. package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
  237. package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +2 -2
  238. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
  239. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
  240. package/tests/jest/BookReader/utils/SelectionObserver.test.js +43 -0
  241. package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
  242. package/tests/jest/BookReader/utils.test.js +229 -0
  243. package/tests/jest/BookReader.keyboard.test.js +190 -0
  244. package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +9 -1
  245. package/tests/{BookReader.test.js → jest/BookReader.test.js} +26 -37
  246. package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +2 -2
  247. package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +4 -4
  248. package/tests/jest/plugins/plugin.chapters.test.js +145 -0
  249. package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
  250. package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
  251. package/tests/jest/plugins/plugin.text_selection.test.js +317 -0
  252. package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
  253. package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +26 -47
  254. package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +39 -6
  255. package/tests/jest/plugins/search/utils.js +25 -0
  256. package/tests/jest/plugins/search/utils.test.js +29 -0
  257. package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +29 -9
  258. package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
  259. package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
  260. package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
  261. package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +47 -1
  262. package/tests/{plugins → jest/plugins}/tts/utils.test.js +1 -60
  263. package/tests/jest/plugins/url/UrlPlugin.test.js +198 -0
  264. package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +53 -14
  265. package/tests/jest/setup.js +3 -0
  266. package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
  267. package/tests/jest/util/docCookies.test.js +24 -0
  268. package/tests/{util → jest/util}/strings.test.js +1 -1
  269. package/tests/{utils.js → jest/utils.js} +38 -0
  270. package/webpack.config.js +11 -6
  271. package/.babelrc +0 -12
  272. package/.dependabot/config.yml +0 -6
  273. package/.testcaferc.json +0 -5
  274. package/BookReader/bookreader-component-bundle.js +0 -14311
  275. package/BookReader/bookreader-component-bundle.js.LICENSE.txt +0 -38
  276. package/BookReader/bookreader-component-bundle.js.map +0 -1
  277. package/BookReader/icons/sort-ascending.svg +0 -1
  278. package/BookReader/icons/sort-descending.svg +0 -1
  279. package/BookReader/jquery-1.10.1.js +0 -108
  280. package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
  281. package/BookReader/plugins/plugin.menu_toggle.js +0 -369
  282. package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
  283. package/BookReader/plugins/plugin.mobile_nav.js +0 -335
  284. package/BookReader/plugins/plugin.mobile_nav.js.map +0 -1
  285. package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
  286. package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
  287. package/karma.conf.js +0 -23
  288. package/src/BookNavigator/BookModel.js +0 -14
  289. package/src/BookNavigator/BookNavigator.js +0 -452
  290. package/src/BookNavigator/assets/book-loader.js +0 -27
  291. package/src/BookNavigator/assets/icon_sort_descending.js +0 -5
  292. package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
  293. package/src/BookNavigator/search/a-search-result.js +0 -55
  294. package/src/BookReader/DebugConsole.js +0 -54
  295. package/src/BookReaderComponent/BookReaderComponent.js +0 -112
  296. package/src/ItemNavigator/ItemNavigator.js +0 -372
  297. package/src/ItemNavigator/providers/sharing.js +0 -29
  298. package/src/assets/icons/sort-ascending.svg +0 -1
  299. package/src/assets/icons/sort-descending.svg +0 -1
  300. package/src/css/_MobileNav.scss +0 -194
  301. package/src/dragscrollable-br.js +0 -261
  302. package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
  303. package/src/plugins/plugin.mobile_nav.js +0 -287
  304. package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
  305. package/tests/BookReader/DebugConsole.test.js +0 -25
  306. package/tests/BookReader/Mode1Up.test.js +0 -164
  307. package/tests/BookReader/Mode2Up.test.js +0 -247
  308. package/tests/BookReader/utils.test.js +0 -109
  309. package/tests/e2e/helpers/desktopSearch.js +0 -72
  310. package/tests/e2e/helpers/mobileSearch.js +0 -85
  311. package/tests/e2e/ia-production/ia-prod-base.js +0 -17
  312. package/tests/karma/BookNavigator/book-navigator.test.js +0 -132
  313. package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
  314. package/tests/karma/BookNavigator/volumes.test.js +0 -101
  315. package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
  316. package/tests/plugins/plugin.chapters.test.js +0 -130
  317. package/tests/plugins/plugin.mobile_nav.test.js +0 -66
  318. package/tests/plugins/plugin.text_selection.test.js +0 -203
  319. package/tests/util/docCookies.test.js +0 -15
@@ -0,0 +1,145 @@
1
+ import sinon from "sinon";
2
+
3
+ import BookReader from "@/src/BookReader.js";
4
+ import "@/src/plugins/plugin.chapters.js";
5
+ import { BookModel } from "@/src/BookReader/BookModel";
6
+ import { deepCopy } from "../utils";
7
+
8
+ const SAMPLE_TOC = [{
9
+ "pagenum": "3",
10
+ "level": 1,
11
+ "label": "CHAPTER I",
12
+ "type": { "key": "/type/toc_item" },
13
+ "title": "THE COUNTRY AND THE MISSION 1",
14
+ "pageIndex": 3,
15
+ }, {
16
+ "pagenum": "17",
17
+ "level": 1,
18
+ "label": "CHAPTER II",
19
+ "type": { "key": "/type/toc_item" },
20
+ "title": "THE COUNTRY AND THE MISSION 2",
21
+ "pageIndex": 17,
22
+ }, {
23
+ "pagenum": "undefined",
24
+ "level": 1,
25
+ "label": "CHAPTER III",
26
+ "type": { "key": "/type/toc_item" },
27
+ "title": "THE COUNTRY AND THE MISSION 3",
28
+ }, {
29
+ "pagenum": "40",
30
+ "level": 1,
31
+ "label": "CHAPTER IV",
32
+ "type": { "key": "/type/toc_item" },
33
+ "title": "THE COUNTRY AND THE MISSION 4",
34
+ "pageIndex": 40,
35
+ }];
36
+
37
+ const SAMPLE_TOC_UNDEF = [
38
+ {
39
+ "pagenum": "undefined",
40
+ "level": 1,
41
+ "label": "CHAPTER I",
42
+ "type": { "key": "/type/toc_item" },
43
+ "title": "THE COUNTRY AND THE MISSION 1",
44
+ },
45
+ {
46
+ "pagenum": "undefined",
47
+ "level": 1,
48
+ "label": "CHAPTER II",
49
+ "type": { "key": "/type/toc_item" },
50
+ "title": "THE COUNTRY AND THE MISSION 2",
51
+ },
52
+ ];
53
+
54
+ afterEach(() => {
55
+ sinon.restore();
56
+ });
57
+
58
+ describe("BRChaptersPlugin", () => {
59
+ beforeEach(() => {
60
+ sinon.stub(BookModel.prototype, "getPageIndex").callsFake((str) =>
61
+ parseFloat(str)
62
+ );
63
+ });
64
+
65
+ describe("_chaptersInit", () => {
66
+ test("does not render when no open library record", async () => {
67
+ const fakeBR = {
68
+ options: {},
69
+ getOpenLibraryRecord: async () => null,
70
+ _chaptersRender: sinon.stub(),
71
+ };
72
+ await BookReader.prototype._chapterInit.call(fakeBR);
73
+ expect(fakeBR._chaptersRender.callCount).toBe(0);
74
+ });
75
+
76
+ test("does not render when open library record with no TOC", async () => {
77
+ const fakeBR = {
78
+ options: {},
79
+ getOpenLibraryRecord: async () => ({ key: "/books/OL1M" }),
80
+ _chaptersRender: sinon.stub(),
81
+ };
82
+ await BookReader.prototype._chapterInit.call(fakeBR);
83
+ expect(fakeBR._chaptersRender.callCount).toBe(0);
84
+ });
85
+
86
+ test("renders if valid TOC on open library", async () => {
87
+ const fakeBR = {
88
+ options: {},
89
+ bind: sinon.stub(),
90
+ book: {
91
+ getPageIndex: (str) => parseFloat(str),
92
+ },
93
+ getOpenLibraryRecord: async () => ({
94
+ "title": "The Adventures of Sherlock Holmes",
95
+ "table_of_contents": deepCopy(SAMPLE_TOC_UNDEF),
96
+ "ocaid": "adventureofsherl0000unse",
97
+ }),
98
+ _chaptersRender: sinon.stub(),
99
+ };
100
+ await BookReader.prototype._chapterInit.call(fakeBR);
101
+ expect(fakeBR._chaptersRender.callCount).toBe(1);
102
+ });
103
+ });
104
+
105
+ describe('_chaptersRender', () => {
106
+ test('renders markers and panel', () => {
107
+ const fakeBR = {
108
+ _tocEntries: SAMPLE_TOC,
109
+ _chaptersRenderMarker: sinon.stub(),
110
+ shell: {
111
+ menuProviders: {},
112
+ updateMenuContents: sinon.stub(),
113
+ }
114
+ };
115
+ BookReader.prototype._chaptersRender.call(fakeBR);
116
+ expect(fakeBR.shell.menuProviders['chapters']).toBeTruthy();
117
+ expect(fakeBR.shell.updateMenuContents.callCount).toBe(1);
118
+ expect(fakeBR._chaptersRenderMarker.callCount).toBeGreaterThan(1);
119
+ });
120
+ });
121
+
122
+ describe('_chaptersUpdateCurrent', () => {
123
+ test('highlights the current chapter', () => {
124
+ const fakeBR = {
125
+ mode: 2,
126
+ firstIndex: 16,
127
+ displayedIndices: [16, 17],
128
+ _tocEntries: SAMPLE_TOC,
129
+ _chaptersPanel: {
130
+ currentChapter: null,
131
+ }
132
+ };
133
+ BookReader.prototype._chaptersUpdateCurrent.call(fakeBR);
134
+ expect(fakeBR._chaptersPanel.currentChapter).toEqual(SAMPLE_TOC[1]);
135
+
136
+ fakeBR.mode = 1;
137
+ BookReader.prototype._chaptersUpdateCurrent.call(fakeBR);
138
+ expect(fakeBR._chaptersPanel.currentChapter).toEqual(SAMPLE_TOC[0]);
139
+
140
+ fakeBR.firstIndex = 0;
141
+ BookReader.prototype._chaptersUpdateCurrent.call(fakeBR);
142
+ expect(fakeBR._chaptersPanel.currentChapter).toBeUndefined();
143
+ });
144
+ });
145
+ });
@@ -1,7 +1,7 @@
1
1
  import sinon from 'sinon';
2
2
 
3
- import BookReader from '../../src/BookReader.js';
4
- import { _attachEventListeners } from '../../src/plugins/plugin.iframe.js';
3
+ import BookReader from '@/src/BookReader.js';
4
+ import { _attachEventListeners } from '@/src/plugins/plugin.iframe.js';
5
5
 
6
6
  afterEach(() => {
7
7
  sinon.restore();
@@ -1,8 +1,8 @@
1
- import BookReader from '../../src/BookReader.js';
2
- import '../../src/plugins/plugin.resume.js';
1
+ import BookReader from '@/src/BookReader.js';
2
+ import '@/src/plugins/plugin.resume.js';
3
3
 
4
4
  import sinon from 'sinon';
5
- import * as docCookies from '../../src/util/docCookies.js';
5
+ import * as docCookies from '@/src/util/docCookies.js';
6
6
 
7
7
  let br;
8
8
  beforeAll(() => {
@@ -0,0 +1,317 @@
1
+ import sinon from 'sinon';
2
+
3
+ import '@/src/BookReader.js';
4
+ import {
5
+ BookreaderWithTextSelection,
6
+ Cache,
7
+ genMap,
8
+ lookAroundWindow,
9
+ zip,
10
+ } from '@/src/plugins/plugin.text_selection.js';
11
+
12
+
13
+ /** @type {BookReader} */
14
+
15
+ // djvu.xml book infos copied from https://ia803103.us.archive.org/14/items/goodytwoshoes00newyiala/goodytwoshoes00newyiala_djvu.xml
16
+ const FAKE_XML_1WORD = `
17
+ <OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
18
+ <PARAGRAPH>
19
+ <LINE>
20
+ <WORD coords="1216,2768,1256,2640">test</WORD>
21
+ </LINE>
22
+ </PARAGRAPH>
23
+ </OBJECT>`;
24
+ const FAKE_XML_MULT_WORDS = `
25
+ <OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
26
+ <PARAGRAPH>
27
+ <LINE>
28
+ <WORD coords="1216,2768,1256,2640">test1</WORD>
29
+ <WORD coords="1400,2768,1500,2640">test2</WORD>
30
+ <WORD coords="1600,2768,1700,2640">test3</WORD>
31
+ </LINE>
32
+ </PARAGRAPH>
33
+ </OBJECT>`;
34
+ const FAKE_XML_MULT_LINES = `
35
+ <OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
36
+ <PARAGRAPH>
37
+ <LINE>
38
+ <WORD coords="119,2050,230,2014" x-confidence="29">way </WORD>
39
+ <WORD coords="230,2038,320,2002" x-confidence="30">can </WORD>
40
+ <WORD coords="320,2039,433,2002" x-confidence="28">false </WORD>
41
+ <WORD coords="433,2051,658,2003" x-confidence="29">judgment </WORD>
42
+ <WORD coords="658,2039,728,2002" x-confidence="30">be </WORD>
43
+ <WORD coords="658,2039,728,2002" x-confidence="30">-</WORD>
44
+ <WORD coords="728,2039,939,2001" x-confidence="29">formed. </WORD>
45
+ <WORD coords="939,2039,1087,2001" x-confidence="29">There </WORD>
46
+ <WORD coords="1087,2039,1187,2002" x-confidence="29">still </WORD>
47
+ <WORD coords="1187,2038,1370,2003" x-confidence="29">remains </WORD>
48
+ <WORD coords="1370,2037,1433,2014" x-confidence="28">an-</WORD>
49
+ </LINE>
50
+ <LINE>
51
+ <WORD coords="244,2099,370,2063" x-confidence="29">other mode </WORD>
52
+ <WORD coords="370,2100,427,2064" x-confidence="29">in </WORD>
53
+ <WORD coords="427,2100,566,2063" x-confidence="29">which </WORD>
54
+ <WORD coords="566,2100,670,2063" x-confidence="29">false </WORD>
55
+ <WORD coords="670,2112,907,2063" x-confidence="29">judgments </WORD>
56
+ <WORD coords="907,2112,1006,2064" x-confidence="29">may </WORD>
57
+ <WORD coords="1006,2100,1071,2063" x-confidence="29">be </WORD>
58
+ <WORD coords="1071,2100,1266,2062" x-confidence="29">formed. </WORD>
59
+ <WORD coords="1266,2110,1435,2062" x-confidence="29">Suppose</WORD>
60
+ </LINE>
61
+ <LINE>
62
+ <WORD coords="118,2160,217,2123" x-confidence="29">that </WORD>
63
+ <WORD coords="217,2160,289,2124" x-confidence="29">we </WORD>
64
+ <WORD coords="289,2160,400,2124" x-confidence="29">have </WORD>
65
+ <WORD coords="400,2160,456,2124" x-confidence="30">in </WORD>
66
+ <WORD coords="456,2161,542,2136" x-confidence="29">our </WORD>
67
+ <WORD coords="542,2161,660,2124" x-confidence="29">souls </WORD>
68
+ <WORD coords="660,2160,700,2136" x-confidence="29">a </WORD>
69
+ <WORD coords="700,2160,847,2129" x-confidence="28">waxen </WORD>
70
+ <WORD coords="847,2160,983,2123" x-confidence="29">tablet </WORD>
71
+ <WORD coords="983,2160,1045,2124" x-confidence="29">of </WORD>
72
+ <WORD coords="1045,2160,1211,2124" x-confidence="29">various </WORD>
73
+ <WORD coords="1211,2171,1398,2122" x-confidence="29">qualities </WORD>
74
+ <WORD coords="1398,2157,1434,2122" x-confidence="29">lastWord</WORD>
75
+ </LINE>
76
+ </PARAGRAPH>
77
+ </OBJECT>`;
78
+ const FAKE_XML_5COORDS = `
79
+ <OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
80
+ <PARAGRAPH>
81
+ <LINE>
82
+ <WORD coords="1216,2768,1256,2640,2690">test</WORD>
83
+ </LINE>
84
+ </PARAGRAPH>
85
+ </OBJECT>`;
86
+ const FAKE_XML_EMPTY = '';
87
+
88
+ describe("Generic tests", () => {
89
+ document.body.innerHTML = '<div id="BookReader">';
90
+ const br = new BookreaderWithTextSelection({
91
+ data: [
92
+ [
93
+ { width: 800, height: 1200,
94
+ uri: '//archive.org/download/BookReader/img/page001.jpg' },
95
+ ],
96
+ [
97
+ { width: 800, height: 1200,
98
+ uri: '//archive.org/download/BookReader/img/page002.jpg' },
99
+ { width: 800, height: 1200,
100
+ uri: '//archive.org/download/BookReader/img/page003.jpg' },
101
+ ],
102
+ [
103
+ { width: 800, height: 1200,
104
+ uri: '//archive.org/download/BookReader/img/page004.jpg' },
105
+ { width: 800, height: 1200,
106
+ uri: '//archive.org/download/BookReader/img/page005.jpg' },
107
+ ]
108
+ ],
109
+ });
110
+ br.init();
111
+
112
+ afterEach(() => {
113
+ sinon.restore();
114
+ $('.BRtextLayer').remove();
115
+ });
116
+
117
+ test("_createPageContainer overridden function still creates a BRpagecontainer element", () => {
118
+ const spy = sinon.spy(br.textSelectionPlugin, 'createTextLayer');
119
+ sinon.stub(br.textSelectionPlugin, "getPageText")
120
+ .returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
121
+ const container = br._createPageContainer(1, {});
122
+ expect(container).toBeTruthy();
123
+ expect(spy.callCount).toBe(1);
124
+ });
125
+
126
+ // test loading first object from sample data
127
+ test("_createPageContainer handles index 0", () => {
128
+ const spy = sinon.spy(br.textSelectionPlugin, 'createTextLayer');
129
+ br._createPageContainer(0, {});
130
+ expect(spy.callCount).toBe(1);
131
+ });
132
+
133
+ // test loading last object from sample data
134
+ test("_createPageContainer handles index -1", () => {
135
+ const spy = sinon.spy(br.textSelectionPlugin, 'createTextLayer');
136
+ br._createPageContainer(-1, {});
137
+ expect(spy.callCount).toBe(0);
138
+ });
139
+
140
+ test("createTextLayer will render the last page and create text layer properly", async () => {
141
+ const $container = br.refs.$brContainer;
142
+ sinon.stub(br.textSelectionPlugin, "getPageText")
143
+ .returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
144
+ const pageIndex = br.data.length - 1;
145
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: pageIndex, width: 100, height: 100 }});
146
+ expect($container.find(".BRtextLayer").length).toBe(1);
147
+ expect($container.find("p").length).toBe(1);
148
+ });
149
+
150
+ test("createTextLayer will not create text layer if there are too many words", async () => {
151
+ const $container = br.refs.$brContainer;
152
+ const xml = FAKE_XML_1WORD.replace(/<WORD.*<\/WORD>/, FAKE_XML_1WORD.match(/<WORD.*<\/WORD>/)[0].repeat(3000));
153
+ sinon.stub(br.textSelectionPlugin, "getPageText")
154
+ .returns($(new DOMParser().parseFromString(xml, "text/xml")));
155
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 0, width: 100, height: 100 }});
156
+ expect($container.find(".BRtextLayer").length).toBe(0);
157
+ expect($container.find("p").length).toBe(0);
158
+ expect($container.find(".BRwordElement").length).toBe(0);
159
+ });
160
+
161
+ test("createTextLayer creates text layer with paragraph with 1 word element", async () => {
162
+ const $container = br.refs.$brContainer;
163
+ sinon.stub(br.textSelectionPlugin, "getPageText")
164
+ .returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
165
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 1, width: 100, height: 100 }});
166
+ expect($container.find(".BRtextLayer").length).toBe(1);
167
+ expect($container.find("p").length).toBe(1);
168
+ expect($container.find(".BRwordElement").length).toBe(1);
169
+ expect($container.find(".BRwordElement").text()).toBe("test");
170
+ });
171
+
172
+ test("createTextLayer creates text layer with paragraph with multiple word elements", async () => {
173
+ const $container = br.refs.$brContainer;
174
+ sinon.stub(br.textSelectionPlugin, "getPageText")
175
+ .returns($(new DOMParser().parseFromString(FAKE_XML_MULT_WORDS, "text/xml")));
176
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 2, width: 100, height: 100 }});
177
+ expect($container.find(".BRtextLayer").length).toBe(1);
178
+ expect($container.find("p").length).toBe(1);
179
+ expect($container.find(".BRwordElement").length).toBe(3);
180
+ expect($container.find(".BRspace").length).toBe(2);
181
+ });
182
+
183
+ test("createTextLayer creates text layer with paragraph with word with 5 params coordinates", async () => {
184
+ const $container = br.refs.$brContainer;
185
+ sinon.stub(br.textSelectionPlugin, "getPageText")
186
+ .returns($(new DOMParser().parseFromString(FAKE_XML_5COORDS, "text/xml")));
187
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
188
+ expect($container.find(".BRtextLayer").length).toBe(1);
189
+ expect($container.find("p").length).toBe(1);
190
+ expect($container.find(".BRwordElement").length).toBe(1);
191
+ });
192
+
193
+ test("createTextLayer handles multiple lines", async () => {
194
+ const $container = br.refs.$brContainer;
195
+ sinon.stub(br.textSelectionPlugin, "getPageText")
196
+ .returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
197
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
198
+ expect($container.find(".BRtextLayer").length).toBe(1);
199
+ expect($container.find("p").length).toBe(1);
200
+ expect($container.find(".BRlineElement").length).toBe(3);
201
+ // Adds space at end of line; except last line/hyphens
202
+ expect($container.find("p").text()).toMatch(/another/);
203
+ expect($container.find("p").text()).toMatch(/Suppose /);
204
+ expect($container.find("p").text()).toMatch(/lastWord$/);
205
+ expect($container.find("p > br").length).toBe(1);
206
+ });
207
+
208
+ test("createTextLayer repairs trailing hyphens", async () => {
209
+ const $container = br.refs.$brContainer;
210
+ sinon.stub(br.textSelectionPlugin, "getPageText")
211
+ .returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
212
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
213
+
214
+ expect($container.find(".BRwordElement--hyphen").length).toBe(1);
215
+ expect($container.find(".BRwordElement--hyphen").closest(".BRlineElement").text().endsWith(' ')).toBe(false);
216
+ expect($container.find(".BRwordElement--hyphen").closest(".BRlineElement").text().endsWith('-')).toBe(false);
217
+ });
218
+
219
+ test("createTextLayer can handle empty xml", async () => {
220
+ const $container = br.refs.$brContainer;
221
+ sinon.stub(br.textSelectionPlugin, "getPageText")
222
+ .returns($(new DOMParser().parseFromString(FAKE_XML_EMPTY, "text/xml")));
223
+ await br.textSelectionPlugin.createTextLayer({ $container, page: { index: 4, width: 100, height: 100 }});
224
+ expect($container.find(".BRtextLayer").length).toBe(1);
225
+ expect($container.find("p").length).toBe(0);
226
+ expect($container.find(".BRwordElement").length).toBe(0);
227
+ });
228
+
229
+ const LONG_PRESS_DURATION = 500;
230
+ test("calling stopPageFlip does not allow long click to flip the page", () => {
231
+ const $container = br.refs.$brContainer;
232
+ br.textSelectionPlugin.stopPageFlip($container);
233
+ const currIndex = br.currentIndex();
234
+ $container.find("BRwordElement").trigger("mousedown");
235
+ // Waits for long press
236
+ setTimeout(() => {
237
+ $container.find("BRwordElement").trigger("mousedown");
238
+ // Waits for flipping animation
239
+ setTimeout(() => {
240
+ expect(br.currentIndex()).toBe(currIndex);
241
+ }, 2000);
242
+ }, LONG_PRESS_DURATION);
243
+ });
244
+ });
245
+
246
+ describe("Cache", () => {
247
+ test('Adding works', () => {
248
+ const c = new Cache(10);
249
+ c.add(35);
250
+ expect(c.entries).toEqual([35]);
251
+ });
252
+
253
+ test('Size does not grow beyond limit', () => {
254
+ const c = new Cache(2);
255
+ c.add(35);
256
+ c.add(32);
257
+ c.add(12);
258
+ c.add(11);
259
+ c.add(112);
260
+ expect(c.entries).toHaveLength(2);
261
+ });
262
+
263
+ test('Oldest evicted first', () => {
264
+ const c = new Cache(2);
265
+ c.add(35);
266
+ c.add(32);
267
+ c.add(12);
268
+ c.add(12);
269
+ c.add(10);
270
+ expect(c.entries).toEqual([12, 10]);
271
+ });
272
+ });
273
+
274
+ describe('genMap', () => {
275
+ test('handles empty', () => {
276
+ expect(Array.from(genMap([], x => x ** 2))).toEqual([]);
277
+ });
278
+
279
+ test('handles non-empty', () => {
280
+ expect(Array.from(genMap([1,2,3], x => x ** 2))).toEqual([1,4,9]);
281
+ });
282
+ });
283
+
284
+ describe('lookAroundWindow', () => {
285
+ test('handles empty', () => {
286
+ expect(Array.from(lookAroundWindow([]))).toEqual([]);
287
+ });
288
+
289
+ test('handles smaller than window', () => {
290
+ expect(Array.from(lookAroundWindow([1]))).toEqual([[undefined, 1, undefined]]);
291
+ expect(Array.from(lookAroundWindow([1, 2]))).toEqual([[undefined, 1, 2], [1, 2, undefined]]);
292
+ expect(Array.from(lookAroundWindow([1, 2, 3]))).toEqual([[undefined, 1, 2], [1, 2, 3], [2, 3, undefined]]);
293
+ });
294
+
295
+ test('handles larger than window', () => {
296
+ expect(Array.from(lookAroundWindow([1, 2, 3, 4]))).toEqual([
297
+ [undefined, 1, 2],
298
+ [1, 2, 3],
299
+ [2, 3, 4],
300
+ [3, 4, undefined],
301
+ ]);
302
+ });
303
+ });
304
+
305
+ describe('zip', () => {
306
+ test('handles empty', () => {
307
+ expect(Array.from(zip([], []))).toEqual([]);
308
+ });
309
+
310
+ test('uneven throws error', () => {
311
+ expect(() => Array.from(zip([1], [2, 3]))).toThrow();
312
+ });
313
+
314
+ test('handles even', () => {
315
+ expect(Array.from(zip([1, 2], [3, 4]))).toEqual([[1, 3], [2, 4]]);
316
+ });
317
+ });
@@ -1,6 +1,6 @@
1
1
 
2
- import BookReader from '../../src/BookReader.js';
3
- import * as util from '../../src/plugins/plugin.vendor-fullscreen.js';
2
+ import BookReader from '@/src/BookReader.js';
3
+ import * as util from '@/src/plugins/plugin.vendor-fullscreen.js';
4
4
 
5
5
  let br;
6
6
  beforeEach(() => {
@@ -1,9 +1,9 @@
1
+ import BookReader from '@/src/BookReader.js';
2
+ import '@/src/plugins/search/plugin.search.js';
3
+ import { deepCopy } from '../../utils.js';
4
+ import { DUMMY_RESULTS } from './utils.js';
1
5
 
2
- import BookReader from '../../../src/BookReader.js';
3
- import '../../../src/plugins/plugin.mobile_nav.js';
4
- import '../../../src/plugins/search/plugin.search.js';
5
-
6
- jest.mock('../../../src/plugins/search/view.js');
6
+ jest.mock('@/src/plugins/search/view.js');
7
7
 
8
8
  let br;
9
9
  const namespace = 'BookReader:';
@@ -18,27 +18,7 @@ beforeEach(() => {
18
18
  $.ajax = jest.fn().mockImplementation(() => {
19
19
  // return from:
20
20
  // `https://ia800304.us.archive.org/fulltext/inside.php?item_id=adventuresofoli00dick&doc=adventuresofoli00dick&path=/30/items/adventuresofoli00dick&q=child&callback=<serialized jQ CB>`
21
- return Promise.resolve({
22
- ia: "adventuresofoli00dick",
23
- q: "child",
24
- indexed: true,
25
- page_count: 644,
26
- body_length: 666,
27
- leaf0_missing: false,
28
- matches: [{
29
- text: 'For a long; time after it was ushered into this world of sorrow and trouble, by the parish surgeon, it remained a matter of considerable doubt wliether the {{{child}}} Avould survi^ e to bear any name at all; in which case it is somewhat more than probable that these memoirs would never have appeared; or, if they had, that being comprised within a couple of pages, they would have possessed the inestimable meiit of being the most concise and faithful specimen of biography, extant in the literature of any age or country.',
30
- par: [{
31
- boxes: [{r: 1221, b: 2121, t: 2075, page: 37, l: 1107}],
32
- b: 2535,
33
- t: 1942,
34
- page_width: 1790,
35
- r: 1598,
36
- l: 50,
37
- page_height: 2940,
38
- page: 37
39
- }]
40
- }]
41
- });
21
+ return Promise.resolve(deepCopy(DUMMY_RESULTS));
42
22
  });
43
23
 
44
24
  $.fn.trigger = jest.fn();
@@ -46,6 +26,7 @@ beforeEach(() => {
46
26
  br = new BookReader();
47
27
  br.initToolbar = jest.fn();
48
28
  br.showProgressPopup = jest.fn();
29
+ br.searchXHR = jest.fn();
49
30
  });
50
31
 
51
32
  afterEach(() => {
@@ -101,7 +82,7 @@ describe('Plugin: Search', () => {
101
82
  expect(br.search.mock.calls[0][1])
102
83
  .toHaveProperty('goToFirstResult', true);
103
84
  expect(br.search.mock.calls[0][1])
104
- .toHaveProperty('suppressFragmentChange', true);
85
+ .toHaveProperty('suppressFragmentChange', false);
105
86
  });
106
87
 
107
88
  test('calling `search` fires ajax call`', () => {
@@ -116,28 +97,30 @@ describe('Plugin: Search', () => {
116
97
  expect(triggeredEvents()).toContain(`${namespace}SearchStarted`);
117
98
  });
118
99
 
119
- test('SearchCallback event fires when AJAX search returns results', () => {
100
+ test('SearchStarted event fires and should go to first result', () => {
120
101
  br.init();
121
- const dfd = br.search('foo');
122
- return dfd.then(() => {
123
- expect(triggeredEvents()).toContain(`${namespace}SearchCallback`);
124
- });
102
+ br.search('foo', { goToFirstResult: true});
103
+ expect(br.options.goToFirstResult).toBeTruthy();
125
104
  });
126
105
 
127
- test('SearchCallbackError event fires when AJAX search returns error', () => {
106
+ test('SearchCallback event fires when AJAX search returns results', async () => {
107
+ br.init();
108
+ await br.search('foo');
109
+ expect(triggeredEvents()).toContain(`${namespace}SearchCallback`);
110
+ });
111
+
112
+ test('SearchCallbackError event fires when AJAX search returns error', async () => {
128
113
  $.ajax = jest.fn().mockImplementation(() => {
129
114
  return Promise.resolve({
130
115
  error: true,
131
116
  });
132
117
  });
133
118
  br.init();
134
- const dfd = br.search('foo');
135
- return dfd.then(() => {
136
- expect(triggeredEvents()).toContain(`${namespace}SearchCallbackError`);
137
- });
119
+ await br.search('foo');
120
+ expect(triggeredEvents()).toContain(`${namespace}SearchCallbackError`);
138
121
  });
139
122
 
140
- test('SearchCallbackNotIndexed event fires when AJAX search returns false indexed value', () => {
123
+ test('SearchCallbackNotIndexed event fires when AJAX search returns false indexed value', async () => {
141
124
  $.ajax = jest.fn().mockImplementation(() => {
142
125
  return Promise.resolve({
143
126
  matches: [],
@@ -145,22 +128,18 @@ describe('Plugin: Search', () => {
145
128
  });
146
129
  });
147
130
  br.init();
148
- const dfd = br.search('foo');
149
- return dfd.then(() => {
150
- expect(triggeredEvents()).toContain(`${namespace}SearchCallbackBookNotIndexed`);
151
- });
131
+ await br.search('foo');
132
+ expect(triggeredEvents()).toContain(`${namespace}SearchCallbackBookNotIndexed`);
152
133
  });
153
134
 
154
- test('SearchCallbackEmpty event fires when AJAX search returns no matches', () => {
135
+ test('SearchCallbackEmpty event fires when AJAX search returns no matches', async () => {
155
136
  $.ajax = jest.fn().mockImplementation(() => {
156
137
  return Promise.resolve({
157
138
  matches: [],
158
139
  });
159
140
  });
160
141
  br.init();
161
- const dfd = br.search('foo');
162
- return dfd.then(() => {
163
- expect(triggeredEvents()).toContain(`${namespace}SearchCallbackEmpty`);
164
- });
142
+ await br.search('foo');
143
+ expect(triggeredEvents()).toContain(`${namespace}SearchCallbackEmpty`);
165
144
  });
166
145
  });