@@ -3,7 +3,9 @@ import '@/src/plugins/plugin.resume.js';
33
44import sinon from 'sinon' ;
55import * as docCookies from '@/src/util/docCookies.js' ;
6+ import { ResumePlugin } from '@/src/plugins/plugin.resume.js' ;
67
8+ /** @type {import('@/src/BookReader.js').default } */
79let br ;
810beforeAll ( ( ) => {
911 document . body . innerHTML = '<div id="BookReader">' ;
@@ -16,21 +18,6 @@ afterEach(() => {
1618 sinon . restore ( ) ;
1719} ) ;
1820
19- describe ( 'Plugin: Remember Current Page in Cookies' , ( ) => {
20- test ( 'has default option flag' , ( ) => {
21- expect ( BookReader . defaultOptions . enablePageResume ) . toEqual ( true ) ;
22- expect ( BookReader . defaultOptions . resumeCookiePath ) . toEqual ( null ) ;
23- } ) ;
24-
25- test ( 'has added BR property: getResumeValue' , ( ) => {
26- expect ( br ) . toHaveProperty ( 'getResumeValue' ) ;
27- } ) ;
28-
29- test ( 'has added BR property: updateResumeValue' , ( ) => {
30- expect ( br ) . toHaveProperty ( 'updateResumeValue' ) ;
31- } ) ;
32- } ) ;
33-
3421describe ( 'updateResumeValue' , ( ) => {
3522 /* Mark 2020-05-02
3623 Skipping while confirming with Neeraj
@@ -42,17 +29,17 @@ describe('updateResumeValue', () => {
4229 In this branch .toHaveBeenCalledTimes() === 1
4330 */
4431 test . skip ( 'starts when BookReaderInit is called' , ( ) => {
45- br . updateResumeValue = jest . fn ( ) ;
32+ br . _plugins . resume . updateResumeValue = jest . fn ( ) ;
4633 br . init ( ) ;
47- expect ( br . updateResumeValue ) . toHaveBeenCalledTimes ( 2 ) ;
34+ expect ( br . _plugins . resume . updateResumeValue ) . toHaveBeenCalledTimes ( 2 ) ;
4835 } ) ;
4936
5037 test ( 'handles cookieName=null' , ( ) => {
51- const { updateResumeValue } = BookReader . prototype ;
38+ const p = new ResumePlugin ( null ) ;
39+ p . setup ( { resumeCookiePath : '/details/goody' } ) ;
5240 const setItemSpy = sinon . spy ( docCookies , 'setItem' ) ;
53- const fakeBr = { options : { resumeCookiePath : '/details/goody' } } ;
5441
55- updateResumeValue . call ( fakeBr , 16 ) ;
42+ p . updateResumeValue ( 16 ) ;
5643 expect ( setItemSpy . callCount ) . toBe ( 1 ) ;
5744 expect ( setItemSpy . args [ 0 ] . slice ( 0 , 2 ) ) . toEqual ( [ 'br-resume' , 16 ] ) ;
5845 expect ( setItemSpy . args [ 0 ] [ 3 ] ) . toEqual ( '/details/goody' ) ;
@@ -61,38 +48,38 @@ describe('updateResumeValue', () => {
6148 test ( 'handles resumeCookiePath not set' , ( ) => {
6249 const setItemSpy = sinon . spy ( docCookies , 'setItem' ) ;
6350 // Save function
64- const saveFn = br . getCookiePath ;
65- br . getCookiePath = jest . fn ( ( ) => '/details/foo' ) ;
66- br . updateResumeValue ( 16 ) ;
51+ const saveFn = br . _plugins . resume . getCookiePath ;
52+ br . _plugins . resume . getCookiePath = jest . fn ( ( ) => '/details/foo' ) ;
53+ br . _plugins . resume . updateResumeValue ( 16 ) ;
6754 expect ( setItemSpy . args [ 0 ] [ 3 ] ) . toEqual ( '/details/foo' ) ;
6855 // Restore function
69- br . getCookiePath = saveFn ;
56+ br . _plugins . resume . getCookiePath = saveFn ;
7057 } ) ;
7158
7259 test ( 'handles cookie path from URL with decoration' , ( ) => {
7360 const complexPathWithPage = '/details/2008ELMValidityStudyFinalReportRevised/Executive%20Summary%20for%20the%20EPT%26ELM%20Validity%20Studie_20100603%20-%20Copy/page/n1/mode/2up' ;
7461 const complexPath = '/details/2008ELMValidityStudyFinalReportRevised/Executive%20Summary%20for%20the%20EPT%26ELM%20Validity%20Studie_20100603%20-%20Copy' ;
75- expect ( br . getCookiePath ( complexPathWithPage ) )
62+ expect ( br . _plugins . resume . getCookiePath ( complexPathWithPage ) )
7663 . toEqual ( complexPath ) ;
7764
78- expect ( br . getCookiePath ( '/details/item/mode/1up' ) )
65+ expect ( br . _plugins . resume . getCookiePath ( '/details/item/mode/1up' ) )
7966 . toEqual ( '/details/item' ) ;
8067
81- expect ( br . getCookiePath ( '/details/item/inside/a/long/path/model/is/used' ) )
68+ expect ( br . _plugins . resume . getCookiePath ( '/details/item/inside/a/long/path/model/is/used' ) )
8269 . toEqual ( '/details/item/inside/a/long/path/model/is/used' ) ;
8370
84- expect ( br . getCookiePath ( '/details/item/inside/a/long/path/mode/is/used' ) )
71+ expect ( br . _plugins . resume . getCookiePath ( '/details/item/inside/a/long/path/mode/is/used' ) )
8572 . toEqual ( '/details/item/inside/a/long/path' ) ;
8673 } ) ;
8774
8875 test ( 'handles cookie path from URL with no decoration' , ( ) => {
89- expect ( br . getCookiePath ( '/details/item' ) )
76+ expect ( br . _plugins . resume . getCookiePath ( '/details/item' ) )
9077 . toEqual ( '/details/item' ) ;
9178
92- expect ( br . getCookiePath ( '/details/item/' ) )
79+ expect ( br . _plugins . resume . getCookiePath ( '/details/item/' ) )
9380 . toEqual ( '/details/item/' ) ;
9481
95- expect ( br . getCookiePath ( '/details/item/almost/any/kind/of/long/path' ) )
82+ expect ( br . _plugins . resume . getCookiePath ( '/details/item/almost/any/kind/of/long/path' ) )
9683 . toEqual ( '/details/item/almost/any/kind/of/long/path' ) ;
9784 } ) ;
9885} ) ;
0 commit comments