1- import { fireEvent , render , screen } from '@testing-library/react' ;
1+ import { fireEvent , render , screen , waitFor } from '@testing-library/react' ;
22import type { KeyboardEvent as ReactKeyboardEvent } from 'react' ;
33import { beforeEach , describe , expect , it , vi } from 'vitest' ;
44import { BlueprintEditorInspector } from '../BlueprintEditorInspector' ;
@@ -65,8 +65,19 @@ beforeEach(() => {
6565 resetEditorStore ( ) ;
6666} ) ;
6767
68+ const ensureLayoutGroupButton = async ( groupName : 'Grid' | 'Spacing' ) => {
69+ if ( ! screen . queryByRole ( 'button' , { name : 'Layout' } ) ) {
70+ const styleToggle = await screen . findByRole ( 'button' , { name : 'Style' } ) ;
71+ fireEvent . click ( styleToggle ) ;
72+ }
73+ if ( ! screen . queryByRole ( 'button' , { name : groupName } ) ) {
74+ fireEvent . click ( await screen . findByRole ( 'button' , { name : 'Layout' } ) ) ;
75+ }
76+ return await screen . findByRole ( 'button' , { name : groupName } ) ;
77+ } ;
78+
6879describe ( 'BlueprintEditorInspector layout panel' , ( ) => {
69- it ( 'updates gap for a Flex node' , ( ) => {
80+ it ( 'updates gap for a Flex node' , async ( ) => {
7081 resetEditorStore ( {
7182 mirDoc : createMirDoc ( [
7283 {
@@ -91,15 +102,15 @@ describe('BlueprintEditorInspector layout panel', () => {
91102 />
92103 ) ;
93104
94- fireEvent . change ( screen . getByPlaceholderText ( '8' ) , {
105+ fireEvent . change ( await screen . findByPlaceholderText ( '8' ) , {
95106 target : { value : '24' } ,
96107 } ) ;
97108
98109 const child = useEditorStore . getState ( ) . mirDoc . ui . root . children ?. [ 0 ] ;
99110 expect ( child ?. props ?. gap ) . toBe ( 24 ) ;
100111 } ) ;
101112
102- it ( 'updates gridTemplateColumns for a Grid node' , ( ) => {
113+ it ( 'updates gridTemplateColumns for a Grid node' , async ( ) => {
103114 resetEditorStore ( {
104115 mirDoc : createMirDoc ( [
105116 {
@@ -125,15 +136,25 @@ describe('BlueprintEditorInspector layout panel', () => {
125136 />
126137 ) ;
127138
139+ fireEvent . click ( await ensureLayoutGroupButton ( 'Grid' ) ) ;
140+ await waitFor ( ( ) => {
141+ expect ( screen . getAllByTestId ( 'mdr-input' ) . length ) . toBeGreaterThanOrEqual (
142+ 2
143+ ) ;
144+ } ) ;
128145 const inputs = screen . getAllByTestId ( 'mdr-input' ) as HTMLInputElement [ ] ;
129146 // [0] id, [1] columns (gap uses editor-only UnitInput)
130147 fireEvent . change ( inputs [ 1 ] , { target : { value : '3' } } ) ;
131148
132- const child = useEditorStore . getState ( ) . mirDoc . ui . root . children ?. [ 0 ] ;
133- expect ( child ?. style ?. gridTemplateColumns ) . toBe ( 'repeat(3, minmax(0, 1fr))' ) ;
149+ await waitFor ( ( ) => {
150+ const child = useEditorStore . getState ( ) . mirDoc . ui . root . children ?. [ 0 ] ;
151+ expect ( child ?. style ?. gridTemplateColumns ) . toBe (
152+ 'repeat(3, minmax(0, 1fr))'
153+ ) ;
154+ } ) ;
134155 } ) ;
135156
136- it ( 'keeps margin shorthand and per-side inputs in sync' , ( ) => {
157+ it ( 'keeps margin shorthand and per-side inputs in sync' , async ( ) => {
137158 resetEditorStore ( {
138159 mirDoc : createMirDoc ( [
139160 {
@@ -157,25 +178,27 @@ describe('BlueprintEditorInspector layout panel', () => {
157178 />
158179 ) ;
159180
160- const shorthandInput = screen . getByTestId (
181+ fireEvent . click ( await ensureLayoutGroupButton ( 'Spacing' ) ) ;
182+
183+ const shorthandInput = ( await screen . findByTestId (
161184 'inspector-margin-shorthand'
162- ) as HTMLInputElement ;
185+ ) ) as HTMLInputElement ;
163186 fireEvent . change ( shorthandInput , { target : { value : '10px 20px' } } ) ;
164187
165- fireEvent . click ( screen . getByTestId ( 'inspector-margin-toggle' ) ) ;
166-
167- const topInput = screen
168- . getByTestId ( 'inspector-margin-top' )
169- . querySelector ( 'input' ) as HTMLInputElement ;
170- const rightInput = screen
171- . getByTestId ( 'inspector-margin-right' )
172- . querySelector ( 'input' ) as HTMLInputElement ;
173- const bottomInput = screen
174- . getByTestId ( 'inspector-margin-bottom' )
175- . querySelector ( 'input' ) as HTMLInputElement ;
176- const leftInput = screen
177- . getByTestId ( 'inspector-margin-left' )
178- . querySelector ( 'input' ) as HTMLInputElement ;
188+ fireEvent . click ( await screen . findByTestId ( 'inspector-margin-toggle' ) ) ;
189+
190+ const topInput = (
191+ await screen . findByTestId ( 'inspector-margin-top' )
192+ ) . querySelector ( 'input' ) as HTMLInputElement ;
193+ const rightInput = (
194+ await screen . findByTestId ( 'inspector-margin-right' )
195+ ) . querySelector ( 'input' ) as HTMLInputElement ;
196+ const bottomInput = (
197+ await screen . findByTestId ( 'inspector-margin-bottom' )
198+ ) . querySelector ( 'input' ) as HTMLInputElement ;
199+ const leftInput = (
200+ await screen . findByTestId ( 'inspector-margin-left' )
201+ ) . querySelector ( 'input' ) as HTMLInputElement ;
179202
180203 expect ( topInput . value ) . toBe ( '10' ) ;
181204 expect ( rightInput . value ) . toBe ( '20' ) ;
0 commit comments