@@ -4,6 +4,8 @@ import { Text } from '@ui5/webcomponents-react/lib/Text';
44import { Toolbar } from '@ui5/webcomponents-react/lib/Toolbar' ;
55import { ToolbarDesign } from '@ui5/webcomponents-react/lib/ToolbarDesign' ;
66import { ToolbarStyle } from '@ui5/webcomponents-react/lib/ToolbarStyle' ;
7+ import { ToolbarSeparator } from '@ui5/webcomponents-react/lib/ToolbarSeparator' ;
8+ import { ToolbarSpacer } from '@ui5/webcomponents-react/lib/ToolbarSpacer' ;
79import React from 'react' ;
810
911describe ( 'Toolbar' , ( ) => {
@@ -41,23 +43,182 @@ describe('Toolbar', () => {
4143 expect ( screen . getByTestId ( 'toolbar' ) ) . toHaveClass ( 'Toolbar-active' ) ;
4244 } ) ;
4345
44- // test('Renders overflowButton', async () => {
45- // let utils;
46- //
47- // await act(async () => {
48- // utils = render(
49- // <Toolbar style={{ width: '50px' }}>
50- // <Text>Item1</Text>
51- // <Text>Item2</Text>
52- // <Text>Item3</Text>
53- // </Toolbar>
54- // );
55- // });
56- //
57- // expect(utils.asFragment()).toMatchSnapshot();
58- //
59- // await waitFor(() => expect(screen.getByTitle('Show More').className).toMatch(/overflowButtonContainer/));
60- // });
46+ test ( 'ToolbarSpacer' , ( ) => {
47+ const { getByTestId, asFragment } = render (
48+ < Toolbar data-testid = "toolbar" >
49+ < Text > Item1</ Text >
50+ < ToolbarSpacer />
51+ < Text > Item2</ Text >
52+ < Text > Item3</ Text >
53+ </ Toolbar >
54+ ) ;
55+ const toolbarSpacer = getByTestId ( 'toolbar' ) . children [ 0 ] . children [ 1 ] ;
56+ expect ( toolbarSpacer ) . toHaveClass ( 'spacer' ) ;
57+ expect ( toolbarSpacer ) . toHaveStyle ( 'flex-grow: 1' ) ;
58+
59+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
60+ } ) ;
61+
62+ test ( 'ToolbarSeparator' , ( ) => {
63+ const { getByLabelText, asFragment } = render (
64+ < Toolbar data-testid = "toolbar" >
65+ < Text > Item1</ Text >
66+ < ToolbarSeparator />
67+ < Text > Item2</ Text >
68+ < Text > Item3</ Text >
69+ </ Toolbar >
70+ ) ;
71+
72+ expect ( getByLabelText ( 'Separator' ) ) . toHaveClass ( 'ToolbarSeparator-separator' ) ;
73+
74+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
75+ } ) ;
76+
77+ test ( 'overflow menu' , ( ) => {
78+ jest . spyOn ( window , 'requestAnimationFrame' ) . mockImplementation ( ( cb ) => cb ( ) ) ;
79+
80+ HTMLElement . prototype . getBoundingClientRect = jest . fn ( function ( ) {
81+ return {
82+ width : parseFloat ( getComputedStyle ( this ) . width || 200 ) ,
83+ height : 10 ,
84+ top : 0 ,
85+ left : 0 ,
86+ bottom : 0 ,
87+ right : 0
88+ } ;
89+ } ) ;
90+
91+ const { getByTitle, getAllByTestId, getAllByText, rerender, queryByTitle, getByText, getAllByLabelText } = render (
92+ < Toolbar data-testid = "toolbar" style = { { width : '300px' } } >
93+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
94+ Item1
95+ </ Text >
96+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
97+ Item2
98+ </ Text >
99+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
100+ Item3
101+ </ Text >
102+ </ Toolbar >
103+ ) ;
104+ expect ( getByTitle ( 'Show More' ) ) . toBeInTheDocument ( ) ;
105+ expect ( getAllByTestId ( 'toolbar-item' ) ) . toHaveLength ( 5 ) ;
106+
107+ const item1 = getAllByText ( 'Item1' ) ;
108+ const item2 = getAllByText ( 'Item2' ) ;
109+ const item3 = getAllByText ( 'Item3' ) ;
110+ expect ( item1 ) . toHaveLength ( 1 ) ;
111+ expect ( item2 ) . toHaveLength ( 2 ) ;
112+ expect ( item3 ) . toHaveLength ( 2 ) ;
113+ expect ( item1 [ 0 ] ) . not . toHaveStyle ( `visibility: hidden` ) ;
114+ expect ( item2 [ 0 ] ) . toHaveStyle ( `visibility: hidden` ) ;
115+ expect ( item3 [ 0 ] ) . toHaveStyle ( `visibility: hidden` ) ;
116+
117+ expect ( document . body ) . toMatchSnapshot ( ) ;
118+
119+ rerender (
120+ < Toolbar data-testid = "toolbar" style = { { width : '1000px' } } >
121+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
122+ Item1
123+ </ Text >
124+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
125+ Item2
126+ </ Text >
127+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
128+ Item3
129+ </ Text >
130+ </ Toolbar >
131+ ) ;
132+ const updatedItem1 = getByText ( 'Item1' ) ;
133+ const updatedItem2 = getByText ( 'Item2' ) ;
134+ const updatedItem3 = getByText ( 'Item3' ) ;
135+ expect ( queryByTitle ( 'Show More' ) ) . toBeNull ( ) ;
136+ expect ( updatedItem1 ) . toBeInTheDocument ( ) ;
137+ expect ( updatedItem2 ) . toBeInTheDocument ( ) ;
138+ expect ( updatedItem3 ) . toBeInTheDocument ( ) ;
139+ expect ( updatedItem1 ) . not . toHaveStyle ( `visibility: hidden` ) ;
140+ expect ( updatedItem2 ) . not . toHaveStyle ( `visibility: hidden` ) ;
141+ expect ( updatedItem3 ) . not . toHaveStyle ( `visibility: hidden` ) ;
142+
143+ //with fragments
144+ rerender (
145+ < Toolbar data-testid = "toolbar" style = { { width : '300px' } } >
146+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
147+ Item1
148+ </ Text >
149+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
150+ Item2
151+ </ Text >
152+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
153+ Item3
154+ </ Text >
155+ </ Toolbar >
156+ ) ;
157+ expect ( getByTitle ( 'Show More' ) ) . toBeInTheDocument ( ) ;
158+ expect ( getAllByTestId ( 'toolbar-item' ) ) . toHaveLength ( 5 ) ;
159+
160+ const item1frag = getAllByText ( 'Item1' ) ;
161+ const item2frag = getAllByText ( 'Item2' ) ;
162+ const item3frag = getAllByText ( 'Item3' ) ;
163+ expect ( item1frag ) . toHaveLength ( 1 ) ;
164+ expect ( item2frag ) . toHaveLength ( 2 ) ;
165+ expect ( item3frag ) . toHaveLength ( 2 ) ;
166+ expect ( item1frag [ 0 ] ) . not . toHaveStyle ( `visibility: hidden` ) ;
167+ expect ( item2frag [ 0 ] ) . toHaveStyle ( `visibility: hidden` ) ;
168+ expect ( item3frag [ 0 ] ) . toHaveStyle ( `visibility: hidden` ) ;
169+
170+ expect ( document . body ) . toMatchSnapshot ( ) ;
171+
172+ rerender (
173+ < Toolbar data-testid = "toolbar" style = { { width : '1000px' } } >
174+ < >
175+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
176+ Item1
177+ </ Text >
178+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
179+ Item2
180+ </ Text >
181+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
182+ Item3
183+ </ Text >
184+ </ >
185+ </ Toolbar >
186+ ) ;
187+
188+ const updatedItem1frag = getByText ( 'Item1' ) ;
189+ const updatedItem2frag = getByText ( 'Item2' ) ;
190+ const updatedItem3frag = getByText ( 'Item3' ) ;
191+ expect ( queryByTitle ( 'Show More' ) ) . toBeNull ( ) ;
192+ expect ( updatedItem1frag ) . toBeInTheDocument ( ) ;
193+ expect ( updatedItem2frag ) . toBeInTheDocument ( ) ;
194+ expect ( updatedItem3frag ) . toBeInTheDocument ( ) ;
195+ expect ( updatedItem1frag ) . not . toHaveStyle ( `visibility: hidden` ) ;
196+ expect ( updatedItem2frag ) . not . toHaveStyle ( `visibility: hidden` ) ;
197+ expect ( updatedItem3frag ) . not . toHaveStyle ( `visibility: hidden` ) ;
198+
199+ //with separator
200+ rerender (
201+ < Toolbar data-testid = "toolbar" style = { { width : '300px' } } >
202+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
203+ Item1
204+ </ Text >
205+ < ToolbarSeparator />
206+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
207+ Item2
208+ </ Text >
209+ < Text data-testid = "toolbar-item" style = { { width : '200px' } } >
210+ Item3
211+ </ Text >
212+ </ Toolbar >
213+ ) ;
214+
215+ const popoverSeparator = getAllByLabelText ( 'Separator' ) [ 1 ] ;
216+
217+ expect ( popoverSeparator ) . toHaveClass ( 'ToolbarSeparator-separator' ) ;
218+ expect ( popoverSeparator ) . toHaveStyle ( 'height: 0.0625rem; margin: 0.375rem 0.1875rem; width: 100%;' ) ;
219+
220+ expect ( document . body ) . toMatchSnapshot ( ) ;
221+ } ) ;
61222
62223 test ( 'active' , ( ) => {
63224 const onClick = jest . fn ( ) ;
0 commit comments