2323 THE SOFTWARE.
2424*/
2525import './MatchMediaMock' ;
26- import { ControlElement , JsonSchema7 } from '@jsonforms/core' ;
26+ import {
27+ ArrayTranslationEnum ,
28+ ControlElement ,
29+ JsonSchema7 ,
30+ Scoped ,
31+ UISchemaElement ,
32+ } from '@jsonforms/core' ;
2733import * as React from 'react' ;
2834
29- import { materialRenderers } from '../../src' ;
35+ import { ArrayLayoutToolbar , materialRenderers } from '../../src' ;
3036import MaterialListWithDetailRenderer , {
3137 materialListWithDetailTester ,
3238} from '../../src/additional/MaterialListWithDetailRenderer' ;
3339import Enzyme , { mount , ReactWrapper } from 'enzyme' ;
3440import Adapter from '@wojtekmaj/enzyme-adapter-react-17' ;
3541import { JsonFormsStateProvider } from '@jsonforms/react' ;
36- import { ListItem } from '@mui/material' ;
37- import { initCore } from './util' ;
42+ import { ListItem , Typography } from '@mui/material' ;
43+ import { initCore , testTranslator } from './util' ;
44+ import { checkTooltip , checkTooltipTranslation } from './tooltipChecker' ;
3845
3946Enzyme . configure ( { adapter : new Adapter ( ) } ) ;
4047
@@ -47,6 +54,23 @@ const data = [
4754 message : 'Yolo' ,
4855 } ,
4956] ;
57+
58+ const emptyData : any [ ] = [ ] ;
59+
60+ const enumOrOneOfData = [
61+ {
62+ message : 'El Barto was here' ,
63+ messageType : 'MSG_TYPE_1' ,
64+ } ,
65+ {
66+ message : 'El Barto was not here' ,
67+ messageType : 'MSG_TYPE_2' ,
68+ } ,
69+ {
70+ message : 'Yolo' ,
71+ } ,
72+ ] ;
73+
5074const schema : JsonSchema7 = {
5175 type : 'array' ,
5276 items : {
@@ -69,6 +93,24 @@ const uischema: ControlElement = {
6993 scope : '#' ,
7094} ;
7195
96+ const uischemaListWithDetail : UISchemaElement & Scoped = {
97+ type : 'ListWithDetail' ,
98+ scope : '#' ,
99+ } ;
100+
101+ const enumSchema : JsonSchema7 = {
102+ type : 'array' ,
103+ items : {
104+ type : 'object' ,
105+ properties : {
106+ messageType : {
107+ type : 'string' ,
108+ enum : [ 'MSG_TYPE_1' , 'MSG_TYPE_2' ] ,
109+ } ,
110+ } ,
111+ } ,
112+ } ;
113+
72114const nestedSchema : JsonSchema7 = {
73115 type : 'array' ,
74116 items : {
@@ -346,4 +388,131 @@ describe('Material list with detail renderer', () => {
346388 const lis = wrapper . find ( ListItem ) ;
347389 expect ( lis ) . toHaveLength ( 1 ) ;
348390 } ) ;
391+
392+ it ( 'should render first simple property' , ( ) => {
393+ const core = initCore ( schema , uischema , data ) ;
394+ wrapper = mount (
395+ < JsonFormsStateProvider
396+ initState = { { renderers : materialRenderers , core } }
397+ >
398+ < MaterialListWithDetailRenderer schema = { schema } uischema = { uischema } />
399+ </ JsonFormsStateProvider >
400+ ) ;
401+
402+ expect ( wrapper . find ( ListItem ) ) . toHaveLength ( 2 ) ;
403+
404+ expect ( wrapper . find ( ListItem ) . find ( Typography ) . at ( 0 ) . text ( ) ) . toBe (
405+ 'El Barto was here'
406+ ) ;
407+ expect ( wrapper . find ( ListItem ) . find ( Typography ) . at ( 1 ) . text ( ) ) . toBe ( 'Yolo' ) ;
408+ } ) ;
409+
410+ it ( 'should render first simple enum property as translated child label' , ( ) => {
411+ const core = initCore ( enumSchema , uischema , enumOrOneOfData ) ;
412+ wrapper = mount (
413+ < JsonFormsStateProvider
414+ initState = { { renderers : materialRenderers , core, i18n : testTranslator } }
415+ >
416+ < MaterialListWithDetailRenderer
417+ schema = { enumSchema }
418+ uischema = { uischema }
419+ />
420+ </ JsonFormsStateProvider >
421+ ) ;
422+
423+ expect ( wrapper . find ( ListItem ) ) . toHaveLength ( 3 ) ;
424+
425+ expect ( wrapper . find ( ListItem ) . find ( Typography ) . at ( 0 ) . text ( ) ) . toBe (
426+ 'MSG_TYPE_1'
427+ ) ;
428+ expect ( wrapper . find ( ListItem ) . find ( Typography ) . at ( 1 ) . text ( ) ) . toBe (
429+ 'MSG_TYPE_2'
430+ ) ;
431+ expect ( wrapper . find ( ListItem ) . find ( Typography ) . at ( 2 ) . text ( ) ) . toBe ( '' ) ;
432+ } ) ;
433+
434+ it ( 'should have no data message when no translator set' , ( ) => {
435+ const core = initCore ( schema , uischema , emptyData ) ;
436+ wrapper = mount (
437+ < JsonFormsStateProvider
438+ initState = { { renderers : materialRenderers , core } }
439+ >
440+ < MaterialListWithDetailRenderer schema = { schema } uischema = { uischema } />
441+ </ JsonFormsStateProvider >
442+ ) ;
443+
444+ const noDataLabel = wrapper . find ( 'ul>p' ) . text ( ) ;
445+ expect ( noDataLabel ) . toBe ( 'No data' ) ;
446+ } ) ;
447+
448+ it ( 'should have a translation for no data' , ( ) => {
449+ const core = initCore ( schema , uischema , emptyData ) ;
450+ wrapper = mount (
451+ < JsonFormsStateProvider
452+ initState = { {
453+ renderers : materialRenderers ,
454+ core,
455+ i18n : { translate : testTranslator } ,
456+ } }
457+ >
458+ < MaterialListWithDetailRenderer schema = { schema } uischema = { uischema } />
459+ </ JsonFormsStateProvider >
460+ ) ;
461+
462+ const noDataLabel = wrapper . find ( 'ul>p' ) . text ( ) ;
463+ expect ( noDataLabel ) . toBe ( 'translator.root.noDataMessage' ) ;
464+ } ) ;
465+
466+ it ( 'should have a tooltip for add button' , ( ) => {
467+ wrapper = checkTooltip (
468+ schema ,
469+ uischemaListWithDetail ,
470+ wrapper ,
471+ ( wrapper ) => wrapper . find ( ArrayLayoutToolbar ) ,
472+ ArrayTranslationEnum . addTooltip ,
473+ {
474+ id : 'tooltip-add' ,
475+ } ,
476+ data
477+ ) ;
478+ } ) ;
479+ it ( 'should have a translatable tooltip for add button' , ( ) => {
480+ wrapper = checkTooltipTranslation (
481+ schema ,
482+ uischemaListWithDetail ,
483+ wrapper ,
484+ ( wrapper ) => wrapper . find ( ArrayLayoutToolbar ) ,
485+ {
486+ id : 'tooltip-add' ,
487+ } ,
488+ data
489+ ) ;
490+ } ) ;
491+
492+ it ( 'should have a tooltip for delete button' , ( ) => {
493+ wrapper = checkTooltip (
494+ schema ,
495+ uischemaListWithDetail ,
496+ wrapper ,
497+ ( wrapper ) => wrapper . find ( 'Memo(ListWithDetailMasterItem)' ) . at ( 0 ) ,
498+ ArrayTranslationEnum . removeTooltip ,
499+ {
500+ id : 'tooltip-remove' ,
501+ } ,
502+ data
503+ ) ;
504+ } ) ;
505+
506+ it ( 'should have a translatable tooltip for delete button' , ( ) => {
507+ wrapper = checkTooltipTranslation (
508+ schema ,
509+ uischemaListWithDetail ,
510+ wrapper ,
511+ ( wrapper ) => wrapper . find ( 'Memo(ListWithDetailMasterItem)' ) . at ( 0 ) ,
512+ {
513+ id : 'tooltip-remove' ,
514+ } ,
515+ data
516+ ) ;
517+ } ) ;
349518} ) ;
0 commit comments