@@ -28,8 +28,8 @@ import { trans } from "i18n";
2828export type NewChildren < ChildrenCompMap extends Record < string , Comp < unknown > > > =
2929 ChildrenCompMap & {
3030 hidden : InstanceType < typeof BoolCodeControl > ;
31- id : InstanceType < typeof StringControl > ;
3231 className : InstanceType < typeof StringControl > ;
32+ dataTestId : InstanceType < typeof StringControl > ;
3333 } ;
3434
3535export function HidableView ( props : {
@@ -56,15 +56,15 @@ export function HidableView(props: {
5656
5757export function ExtendedComponentView ( props : {
5858 children : JSX . Element | React . ReactNode ;
59- id : string ;
6059 className : string ;
60+ dataTestId : string ;
6161} ) {
62- if ( ! props . id && ! props . className ) {
62+ if ( ! props . className && ! props . dataTestId ) {
6363 return < > { props . children } </ > ;
64- }
65-
64+ }
65+
6666 return (
67- < div id = { props . id } className = { props . className } >
67+ < div className = { props . className } data-testid = { props . dataTestId } >
6868 { props . children }
6969 </ div >
7070 ) ;
@@ -73,17 +73,17 @@ export function ExtendedComponentView(props: {
7373export function ExtendedPropertyView <
7474 ChildrenCompMap extends Record < string , Comp < unknown > > ,
7575> ( props : {
76- children : JSX . Element | React . ReactNode ,
77- childrenMap : NewChildren < ChildrenCompMap >
78- }
76+ children : JSX . Element | React . ReactNode ,
77+ childrenMap : NewChildren < ChildrenCompMap >
78+ }
7979) {
8080 return (
8181 < >
82- { props . children }
83- < Section name = { trans ( "prop.component" ) } >
84- { props . childrenMap . id ?. propertyView ( { label : trans ( "prop.id " ) } ) }
85- { props . childrenMap . className ?. propertyView ( { label : trans ( "prop.className " ) } ) }
86- </ Section >
82+ { props . children }
83+ < Section name = { trans ( "prop.component" ) } >
84+ { props . childrenMap . className ?. propertyView ( { label : trans ( "prop.className " ) } ) }
85+ { props . childrenMap . dataTestId ?. propertyView ( { label : trans ( "prop.dataTestId " ) } ) }
86+ </ Section >
8787 </ >
8888 ) ;
8989}
@@ -93,7 +93,12 @@ export function uiChildren<
9393> (
9494 childrenMap : ToConstructor < ChildrenCompMap >
9595) : ToConstructor < NewChildren < ChildrenCompMap > > {
96- return { ...childrenMap , hidden : BoolCodeControl , id : StringControl , className : StringControl } as any ;
96+ return {
97+ ...childrenMap ,
98+ hidden : BoolCodeControl ,
99+ className : StringControl ,
100+ dataTestId : StringControl
101+ } as any ;
97102}
98103
99104type ViewReturn = ReactNode ;
@@ -160,14 +165,11 @@ export class UICompBuilder<
160165 }
161166
162167 build ( ) {
163- if ( this . childrenMap . hasOwnProperty ( "hidden" ) ) {
164- throw new Error ( "already has hidden" ) ;
165- }
166- if ( this . childrenMap . hasOwnProperty ( "id" ) ) {
167- throw new Error ( "already has id" ) ;
168- }
169- if ( this . childrenMap . hasOwnProperty ( "className" ) ) {
170- throw new Error ( "already has className" ) ;
168+ const reservedProps = [ "hidden" , "className" , "dataTestId" ] ;
169+ for ( const reservedProp of reservedProps ) {
170+ if ( this . childrenMap . hasOwnProperty ( reservedProp ) ) {
171+ throw new Error ( `Property »${ reservedProp } « is reserved and must not be implemented in components!` ) ;
172+ }
171173 }
172174 const newChildrenMap = uiChildren ( this . childrenMap ) ;
173175 const builder = this ;
@@ -178,7 +180,7 @@ export class UICompBuilder<
178180 ToNodeType < NewChildren < ChildrenCompMap > >
179181 > {
180182 ref : React . RefObject < HTMLDivElement > = React . createRef ( ) ;
181-
183+
182184 override parseChildrenFromValue (
183185 params : CompParams < ToDataType < NewChildren < ChildrenCompMap > > >
184186 ) : NewChildren < ChildrenCompMap > {
@@ -241,7 +243,10 @@ function UIView(props: { comp: any; viewFn: any }) {
241243 //END ADD BY FRED
242244
243245 return (
244- < ExtendedComponentView id = { childrenProps . id as string } className = { childrenProps . className as string } >
246+ < ExtendedComponentView
247+ className = { childrenProps . className as string }
248+ dataTestId = { childrenProps . dataTestId as string }
249+ >
245250 < HidableView hidden = { childrenProps . hidden as boolean } >
246251 { props . viewFn ( childrenProps , comp . dispatch ) }
247252 </ HidableView >
0 commit comments