44 getOEmbedApiUrl ,
55 parseDocumentCloudUrl ,
66 cleanDocumentCloudUrl ,
7+ validateMode ,
78} from '../src/documentcloud/utils/utils' ;
89
910describe ( 'DocumentCloud Utils' , ( ) => {
@@ -59,10 +60,10 @@ describe( 'DocumentCloud Utils', () => {
5960 onlyshoworg : false ,
6061 pdf : true ,
6162 style : 'custom-style' ,
62- responsive : true ,
63+ responsive : true , // Check that we ignore the responsive option
6364 } ;
6465 expect ( getEmbedUrl ( params ) ) . toBe (
65- 'https://www.documentcloud.org/documents/123?embed=1&title=1&fullscreen=0&onlyshoworg=0&pdf=1&style=custom-style&responsive=1 '
66+ 'https://www.documentcloud.org/documents/123?embed=1&title=1&fullscreen=0&onlyshoworg=0&pdf=1&style=custom-style'
6667 ) ;
6768 } ) ;
6869
@@ -76,12 +77,63 @@ describe( 'DocumentCloud Utils', () => {
7677 onlyshoworg : true ,
7778 pdf : false ,
7879 style : 'border: 1px solid #000;' ,
79- responsive : false ,
80+ responsive : false , // Check that we ignore the responsive option
8081 } ;
8182 expect ( getEmbedUrl ( params ) ) . toBe (
82- 'https://embed.documentcloud.org/documents/24479621-24-03-13-epic-motion-to-enforce-injunction?embed=1&title=0&fullscreen=1&onlyshoworg=1&pdf=0&style=border%3A%201px%20solid%20%23000%3B&responsive=0 '
83+ 'https://embed.documentcloud.org/documents/24479621-24-03-13-epic-motion-to-enforce-injunction?embed=1&title=0&fullscreen=1&onlyshoworg=1&pdf=0&style=border%3A%201px%20solid%20%23000%3B'
8384 ) ;
8485 } ) ;
86+
87+ it ( 'should include valid mode parameter in embed URL' , ( ) => {
88+ // Validates that valid mode values are included in the embed URL
89+ const validModes = [ 'document' , 'notes' , 'text' , 'grid' ] ;
90+
91+ validModes . forEach ( ( mode ) => {
92+ const params = {
93+ useDocumentId : true ,
94+ documentId : '123' ,
95+ mode : mode ,
96+ } ;
97+ const result = getEmbedUrl ( params ) ;
98+ expect ( result ) . toContain ( `mode=${ mode } ` ) ;
99+ } ) ;
100+ } ) ;
101+
102+ it ( 'should exclude invalid mode parameter from embed URL' , ( ) => {
103+ // Validates that invalid mode values are not included in the embed URL
104+ const invalidModes = [
105+ 'invalid' ,
106+ 'foo' ,
107+ 'bar' ,
108+ '' ,
109+ null ,
110+ undefined ,
111+ ] ;
112+
113+ invalidModes . forEach ( ( mode ) => {
114+ const params = {
115+ useDocumentId : true ,
116+ documentId : '123' ,
117+ mode : mode ,
118+ } ;
119+ const result = getEmbedUrl ( params ) ;
120+ if ( mode && mode !== '' ) {
121+ expect ( result ) . not . toContain ( `mode=${ mode } ` ) ;
122+ }
123+ expect ( result ) . not . toContain ( 'mode=' ) ;
124+ } ) ;
125+ } ) ;
126+
127+ it ( 'should not include mode parameter when not specified' , ( ) => {
128+ // Validates that no mode parameter is added when not specified
129+ const params = {
130+ useDocumentId : true ,
131+ documentId : '123' ,
132+ title : true ,
133+ } ;
134+ const result = getEmbedUrl ( params ) ;
135+ expect ( result ) . not . toContain ( 'mode=' ) ;
136+ } ) ;
85137 } ) ;
86138
87139 // Tests for getOEmbedApiUrl
@@ -143,4 +195,30 @@ describe( 'DocumentCloud Utils', () => {
143195 } ) ;
144196 } ) ;
145197 } ) ;
198+
199+ // Tests for validateMode
200+ describe ( 'validateMode' , ( ) => {
201+ it ( 'should return valid mode values' , ( ) => {
202+ // Tests that valid mode values are returned unchanged
203+ const validModes = [ 'document' , 'notes' , 'text' , 'grid' ] ;
204+ validModes . forEach ( ( mode ) => {
205+ expect ( validateMode ( mode ) ) . toBe ( mode ) ;
206+ } ) ;
207+ } ) ;
208+
209+ it ( 'should return null for invalid mode values' , ( ) => {
210+ // Tests that invalid mode values return null
211+ const invalidModes = [
212+ 'invalid' ,
213+ 'foo' ,
214+ 'bar' ,
215+ '' ,
216+ null ,
217+ undefined ,
218+ ] ;
219+ invalidModes . forEach ( ( mode ) => {
220+ expect ( validateMode ( mode ) ) . toBeNull ( ) ;
221+ } ) ;
222+ } ) ;
223+ } ) ;
146224} ) ;
0 commit comments