@@ -16,6 +16,7 @@ import { useRendererProps } from '../context/RenderersPropsProvider';
1616import TNodeChildrenRenderer from '../TNodeChildrenRenderer' ;
1717import OLElement from '../elements/OLElement' ;
1818import ULElement from '../elements/ULElement' ;
19+ import { HTMLElementModelRecord } from '../shared-types' ;
1920
2021describe ( 'RenderHTML' , ( ) => {
2122 it ( 'should render without error when providing a source' , ( ) => {
@@ -179,7 +180,7 @@ describe('RenderHTML', () => {
179180 />
180181 ) ;
181182 const span = getByTestId ( 'span' ) ;
182- expect ( span . props . style ) . toMatchObject ( tagsStyles . span ) ;
183+ expect ( StyleSheet . flatten ( span . props . style ) ) . toMatchObject ( tagsStyles . span ) ;
183184 } ) ;
184185 describe ( 'regarding onTTreeChange prop' , ( ) => {
185186 const onTTreeChange = jest . fn ( ) ;
@@ -360,6 +361,162 @@ describe('RenderHTML', () => {
360361 const em = UNSAFE_getByType ( EmRenderer ) ;
361362 expect ( em . props . propsFromParent . test ) . toBeUndefined ( ) ;
362363 } ) ;
364+ it ( 'should apply `viewProps` to TBlock renderers' , ( ) => {
365+ const DivRenderer : CustomTextualRenderer = ( {
366+ TDefaultRenderer,
367+ ...props
368+ } ) => < TDefaultRenderer { ...props } viewProps = { { collapsable : false } } /> ;
369+ const { getByTestId } = render (
370+ < RenderHTML
371+ source = { {
372+ html : '<div>test</div>'
373+ } }
374+ renderers = { { div : DivRenderer } }
375+ debug = { false }
376+ contentWidth = { 100 }
377+ />
378+ ) ;
379+ const div = getByTestId ( 'div' ) ;
380+ expect ( div . props . collapsable ) . toBe ( false ) ;
381+ } ) ;
382+ it ( 'should apply `textProps` to TPhrasing renderers' , ( ) => {
383+ const SpanRenderer : CustomTextualRenderer = ( {
384+ TDefaultRenderer,
385+ ...props
386+ } ) => (
387+ < TDefaultRenderer
388+ { ...props }
389+ textProps = { { adjustsFontSizeToFit : true } }
390+ />
391+ ) ;
392+ const { getByTestId } = render (
393+ < RenderHTML
394+ source = { {
395+ html : '<span>foo<b>bar</b></span>'
396+ } }
397+ renderers = { { span : SpanRenderer } }
398+ debug = { false }
399+ contentWidth = { 100 }
400+ />
401+ ) ;
402+ const span = getByTestId ( 'span' ) ;
403+ expect ( span . props . adjustsFontSizeToFit ) . toBe ( true ) ;
404+ } ) ;
405+ it ( 'should apply `textProps` to TText renderers' , ( ) => {
406+ const SpanRenderer : CustomTextualRenderer = ( {
407+ TDefaultRenderer,
408+ ...props
409+ } ) => (
410+ < TDefaultRenderer
411+ { ...props }
412+ textProps = { { adjustsFontSizeToFit : true } }
413+ />
414+ ) ;
415+ const { getByTestId } = render (
416+ < RenderHTML
417+ source = { {
418+ html : '<span>foo</span>'
419+ } }
420+ renderers = { { span : SpanRenderer } }
421+ debug = { false }
422+ contentWidth = { 100 }
423+ />
424+ ) ;
425+ const span = getByTestId ( 'span' ) ;
426+ expect ( span . props . adjustsFontSizeToFit ) . toBe ( true ) ;
427+ } ) ;
428+ it ( 'should apply `props`' , ( ) => {
429+ const SpanRenderer : CustomTextualRenderer = ( {
430+ TDefaultRenderer,
431+ ...props
432+ } ) => (
433+ < TDefaultRenderer
434+ { ...props }
435+ nativeProps = { { accessibilityRole : 'adjustable' } }
436+ />
437+ ) ;
438+ const { getByTestId } = render (
439+ < RenderHTML
440+ source = { {
441+ html : '<span>foo</span>'
442+ } }
443+ renderers = { { span : SpanRenderer } }
444+ debug = { false }
445+ contentWidth = { 100 }
446+ />
447+ ) ;
448+ const span = getByTestId ( 'span' ) ;
449+ expect ( span . props . accessibilityRole ) . toBe ( 'adjustable' ) ;
450+ } ) ;
451+ it ( 'should apply `tnode.getReactNativeProps()` to TPhrasing renderers' , ( ) => {
452+ const customHTMLElementModels : HTMLElementModelRecord = {
453+ span : defaultHTMLElementModels . span . extend ( {
454+ reactNativeProps : {
455+ native : {
456+ accessibilityRole : 'adjustable'
457+ }
458+ }
459+ } )
460+ } ;
461+ const { getByTestId } = render (
462+ < RenderHTML
463+ source = { {
464+ html : '<span>foo<b>bar</br></span>'
465+ } }
466+ customHTMLElementModels = { customHTMLElementModels }
467+ debug = { false }
468+ contentWidth = { 100 }
469+ />
470+ ) ;
471+ const span = getByTestId ( 'span' ) ;
472+ expect ( span . props . accessibilityRole ) . toBe ( 'adjustable' ) ;
473+ } ) ;
474+ it ( 'should apply `tnode.getReactNativeProps()` to TText renderers' , ( ) => {
475+ const customHTMLElementModels : HTMLElementModelRecord = {
476+ span : defaultHTMLElementModels . span . extend ( {
477+ reactNativeProps : {
478+ native : {
479+ accessibilityRole : 'adjustable'
480+ }
481+ }
482+ } )
483+ } ;
484+ const { getByTestId } = render (
485+ < RenderHTML
486+ source = { {
487+ html : '<span>foo</span>'
488+ } }
489+ customHTMLElementModels = { customHTMLElementModels }
490+ debug = { false }
491+ contentWidth = { 100 }
492+ />
493+ ) ;
494+ const span = getByTestId ( 'span' ) ;
495+ expect ( span . props . accessibilityRole ) . toBe ( 'adjustable' ) ;
496+ } ) ;
497+ it ( 'should apply `tnode.getReactNativeProps()` to TBlock renderers' , ( ) => {
498+ const customHTMLElementModels : HTMLElementModelRecord = {
499+ div : defaultHTMLElementModels . span . extend ( {
500+ reactNativeProps : {
501+ native : {
502+ accessibilityRole : 'adjustable'
503+ }
504+ }
505+ } )
506+ } ;
507+ const { getByTestId } = render (
508+ < RenderHTML
509+ source = { {
510+ html : '<div>test</div>'
511+ } }
512+ customHTMLElementModels = { customHTMLElementModels }
513+ debug = { false }
514+ contentWidth = { 100 }
515+ />
516+ ) ;
517+ const div = getByTestId ( 'div' ) ;
518+ expect ( div . props . accessibilityRole ) . toBe ( 'adjustable' ) ;
519+ } ) ;
363520 } ) ;
364521 describe ( 'regarding TNodeRenderer' , ( ) => {
365522 describe ( 'TBlockRenderer' , ( ) => {
0 commit comments