@@ -144,3 +144,87 @@ describe('createTitle', () => {
144144 expect ( title ) . toEqual ( '3 page1 - book | OpenStax' ) ;
145145 } ) ;
146146} ) ;
147+ describe ( 'createTitle (modal param)' , ( ) => {
148+ const intl = createIntl ( ) ;
149+
150+ it ( 'returns modal title for MH modal param' , ( ) => {
151+ const page = makeArchiveSection ( 'page1' ) ;
152+ const book = {
153+ title : 'book' ,
154+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
155+ } ;
156+ // params string with modal=MH
157+ const params = 'modal=MH' ;
158+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
159+ expect ( title ) . toEqual ( 'My Highlights and Notes | OpenStax' ) ;
160+ } ) ;
161+
162+ it ( 'returns modal title for KS modal param' , ( ) => {
163+ const page = makeArchiveSection ( 'page1' ) ;
164+ const book = {
165+ title : 'book' ,
166+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
167+ } ;
168+ // params string with modal=KS
169+ const params = 'modal=KS' ;
170+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
171+ expect ( title ) . toEqual ( 'REX Keyboard Shortcuts | OpenStax' ) ;
172+ } ) ;
173+
174+ it ( 'returns modal title for PQ modal param' , ( ) => {
175+ const page = makeArchiveSection ( 'page1' ) ;
176+ const book = {
177+ title : 'book' ,
178+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
179+ } ;
180+ // params string with modal=PQ
181+ const params = 'modal=PQ' ;
182+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
183+ expect ( title ) . toEqual ( 'REX Practice Questions | OpenStax' ) ;
184+ } ) ;
185+
186+ it ( 'returns modal title for SG modal param' , ( ) => {
187+ const page = makeArchiveSection ( 'page1' ) ;
188+ const book = {
189+ title : 'book' ,
190+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
191+ } ;
192+ // params string with modal=SG
193+ const params = 'modal=SG' ;
194+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
195+ expect ( title ) . toEqual ( 'REX Study Guides | OpenStax' ) ;
196+ } ) ;
197+
198+ it ( 'returns normal title if modal param is not present' , ( ) => {
199+ const page = makeArchiveSection ( 'page1' ) ;
200+ const book = {
201+ title : 'book' ,
202+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
203+ } ;
204+ const params = '' ;
205+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
206+ expect ( title ) . toEqual ( 'page1 - book | OpenStax' ) ;
207+ } ) ;
208+
209+ it ( 'returns normal title if modal param is unknown' , ( ) => {
210+ const page = makeArchiveSection ( 'page1' ) ;
211+ const book = {
212+ title : 'book' ,
213+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
214+ } ;
215+ const params = 'modal=UNKNOWN' ;
216+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
217+ expect ( title ) . toEqual ( 'page1 - book | OpenStax' ) ;
218+ } ) ;
219+
220+ it ( 'returns modal title if modal param is present among other params' , ( ) => {
221+ const page = makeArchiveSection ( 'page1' ) ;
222+ const book = {
223+ title : 'book' ,
224+ tree : makeArchiveTree ( 'book' , [ page ] ) ,
225+ } ;
226+ const params = 'foo=bar&modal=MH&baz=qux' ;
227+ const title = createTitle ( page as any as Page , book as any as Book , intl , params ) ;
228+ expect ( title ) . toEqual ( 'My Highlights and Notes | OpenStax' ) ;
229+ } ) ;
230+ } ) ;
0 commit comments