File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { fireEvent , render , screen } from "@testing-library/react" ;
2+ import { describe , expect , it , vi } from "vitest" ;
3+ import type { FloorFeature } from "../../../lib/types" ;
4+ import { GenericImdfFeatureEditor } from "./GenericImdfFeatureEditor" ;
5+
6+ const createFeature = ( ) : FloorFeature => ( {
7+ type : "Feature" ,
8+ id : "opening-1" ,
9+ feature_type : "opening" ,
10+ geometry : {
11+ type : "LineString" ,
12+ coordinates : [
13+ [ 4.9 , 52.37 ] ,
14+ [ 4.9001 , 52.3701 ] ,
15+ ] ,
16+ } ,
17+ properties : {
18+ level_id : "level-1" ,
19+ category : "elevator" ,
20+ name : { en : "Elevator A" } ,
21+ } ,
22+ } ) ;
23+
24+ describe ( "GenericImdfFeatureEditor" , ( ) => {
25+ it ( "allows typing in label fields without reading a cleared event target" , ( ) => {
26+ const feature = createFeature ( ) ;
27+
28+ render (
29+ < GenericImdfFeatureEditor
30+ feature = { feature }
31+ type = "opening"
32+ allFeatures = { [ feature ] }
33+ locked = { false }
34+ onCreateFeature = { vi . fn ( ) }
35+ onUpdateProperty = { vi . fn ( ) }
36+ onUpdateMetadata = { vi . fn ( ) }
37+ onDelete = { vi . fn ( ) }
38+ onClone = { vi . fn ( ) }
39+ onToggleLock = { vi . fn ( ) }
40+ /> ,
41+ ) ;
42+
43+ const nameInput = screen . getByDisplayValue ( "Elevator A" ) as HTMLInputElement ;
44+
45+ expect ( ( ) =>
46+ fireEvent . change ( nameInput , {
47+ target : { value : "Elevator" } ,
48+ } ) ,
49+ ) . not . toThrow ( ) ;
50+
51+ expect ( nameInput ) . toHaveValue ( "Elevator" ) ;
52+ } ) ;
53+ } ) ;
Original file line number Diff line number Diff line change @@ -403,12 +403,13 @@ export const GenericImdfFeatureEditor = ({
403403 className = { `input input-bordered input-sm ${ hasError ? "input-error" : "" } ` }
404404 type = "text"
405405 value = { textValue }
406- onChange = { ( event ) =>
406+ onChange = { ( event ) => {
407+ const nextValue = event . currentTarget . value ;
407408 setFieldText ( ( current ) => ( {
408409 ...current ,
409- [ field . key ] : event . currentTarget . value ,
410- } ) )
411- }
410+ [ field . key ] : nextValue ,
411+ } ) ) ;
412+ } }
412413 onBlur = { ( ) => {
413414 const value = fieldText [ field . key ] ?? textValue ;
414415 const trimmed = value . trim ( ) ;
@@ -455,12 +456,13 @@ export const GenericImdfFeatureEditor = ({
455456 < textarea
456457 className = { `textarea textarea-bordered h-24 w-full font-mono text-xs ${ hasError ? "textarea-error" : "" } ` }
457458 value = { textValue }
458- onChange = { ( event ) =>
459+ onChange = { ( event ) => {
460+ const nextValue = event . currentTarget . value ;
459461 setFieldText ( ( current ) => ( {
460462 ...current ,
461- [ field . key ] : event . currentTarget . value ,
462- } ) )
463- }
463+ [ field . key ] : nextValue ,
464+ } ) ) ;
465+ } }
464466 onBlur = { ( ) => {
465467 const value = fieldText [ field . key ] ?? textValue ;
466468 if ( value . trim ( ) . length === 0 ) {
You can’t perform that action at this time.
0 commit comments