|
1 | 1 | import { useState } from 'react'; |
2 | | -import { FlexBox, SplitterLayoutPropTypes, Text } from '../..'; |
3 | | -import { Button, Label, SplitterElement, SplitterLayout } from '../..'; |
| 2 | +import type { SplitterLayoutPropTypes } from '../..'; |
| 3 | +import { FlexBox, Text, Button, Label, SplitterElement, SplitterLayout } from '../..'; |
4 | 4 | import { cypressPassThroughTestsFactory } from '@/cypress/support/utils'; |
5 | 5 |
|
6 | 6 | function TestComp({ vertical, dir }: { vertical: SplitterLayoutPropTypes['vertical']; dir: string }) { |
@@ -130,72 +130,130 @@ describe('SplitterLayout', () => { |
130 | 130 | }); |
131 | 131 |
|
132 | 132 | [true, false].forEach((vertical) => { |
133 | | - it.only(`controlled width (${vertical ? 'vertical' : 'horizontal'})`, () => { |
| 133 | + it(`controlled width (${vertical ? 'vertical' : 'horizontal'})`, () => { |
| 134 | + function getMouseMoveArgs(amount: number): [number, number] { |
| 135 | + return vertical ? [0, amount] : [amount, 0]; |
| 136 | + } |
134 | 137 | const resize = cy.spy().as('resize'); |
135 | 138 | const TestComp = () => { |
136 | 139 | const [size0, setSize0] = useState('200px'); |
137 | | - const [size1, setSize1] = useState('200px'); |
138 | | - const [size2, setSize2] = useState('200px'); |
| 140 | + const [size1, setSize1] = useState(200); |
| 141 | + const [size2, setSize2] = useState('auto'); |
139 | 142 | const [size3, setSize3] = useState('200px'); |
140 | 143 | const setter = [setSize0, setSize1, setSize2, setSize3]; |
141 | 144 | return ( |
142 | 145 | <> |
143 | 146 | <SplitterLayout |
144 | 147 | vertical={vertical} |
145 | | - style={{ height: '600px' }} |
| 148 | + style={{ height: '900px', width: '900px', backgroundColor: 'black' }} |
146 | 149 | onResize={(e) => { |
147 | 150 | resize(e); |
148 | 151 | e.areas.forEach((item) => { |
149 | | - setter[Number(item.area.dataset.index)](item.size + 'px'); |
| 152 | + if (item.area.dataset.index === '1') { |
| 153 | + setter[Number(item.area.dataset.index)](item.size); |
| 154 | + } else { |
| 155 | + //@ts-expect-error: supported |
| 156 | + setter[Number(item.area.dataset.index)](item.size + 'px'); |
| 157 | + } |
150 | 158 | }); |
151 | 159 | }} |
152 | 160 | > |
153 | | - <SplitterElement size={size0} data-index={0}> |
| 161 | + <SplitterElement size={size0} data-index={0} style={{ backgroundColor: 'lightcoral' }}> |
154 | 162 | <FlexBox style={{ height: '100%', width: '100%' }} alignItems="Center" justifyContent="Center"> |
155 | 163 | <Text>Content 1</Text> |
156 | 164 | </FlexBox> |
157 | 165 | </SplitterElement> |
158 | | - <SplitterElement size={size1} data-index={1}> |
| 166 | + <SplitterElement size={size1} data-index={1} style={{ backgroundColor: 'lightblue' }}> |
159 | 167 | <FlexBox style={{ height: '100%', width: '100%' }} alignItems="Center" justifyContent="Center"> |
160 | | - <Text style={{ whiteSpace: 'pre-line' }}>{`Content 2 |
161 | | - with |
162 | | - multi |
163 | | - lines |
164 | | - `}</Text> |
| 168 | + <Text style={{ whiteSpace: 'pre-line' }}>{`Content 2 |
| 169 | + with |
| 170 | + multi |
| 171 | + lines`}</Text> |
165 | 172 | </FlexBox> |
166 | 173 | </SplitterElement> |
167 | | - <SplitterElement size={'auto'} data-index={2}> |
| 174 | + <SplitterElement size={'auto'} data-index={2} style={{ backgroundColor: 'lightgreen' }}> |
168 | 175 | <FlexBox style={{ height: '100%', width: '100%' }} alignItems="Center" justifyContent="Center"> |
169 | 176 | <Text> |
170 | 177 | Content 3 with long text: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy |
171 | 178 | eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et |
172 | 179 | accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est |
173 | | - Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy |
174 | | - eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et |
175 | | - accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est |
176 | | - Lorem ipsum dolor sit amet." |
| 180 | + Lorem ipsum dolor sit amet. |
177 | 181 | </Text> |
178 | 182 | </FlexBox> |
179 | 183 | </SplitterElement> |
180 | | - <SplitterElement data-index={3} size={size3}> |
| 184 | + <SplitterElement size={size3} data-index={3} style={{ backgroundColor: 'lightgoldenrodyellow' }}> |
181 | 185 | <FlexBox style={{ height: '100%', width: '100%' }} alignItems="Center" justifyContent="Center"> |
182 | 186 | <Text>Content 4</Text> |
183 | 187 | </FlexBox> |
184 | 188 | </SplitterElement> |
185 | 189 | </SplitterLayout> |
| 190 | + <span data-testid="0">{size0}</span> |
| 191 | + <br /> |
| 192 | + <span data-testid="1">{size1}</span> |
| 193 | + <br /> |
| 194 | + <span data-testid="2">{size2}</span> |
| 195 | + <br /> |
| 196 | + <span data-testid="3">{size3}</span> |
186 | 197 | </> |
187 | 198 | ); |
188 | 199 | }; |
189 | 200 |
|
190 | 201 | cy.mount(<TestComp />); |
191 | 202 |
|
192 | | - cy.get('[data-index="0"]').as('se0'); |
193 | | - cy.get('[data-index="1"]').as('se1'); |
194 | | - cy.get('[data-index="2"]').as('se2'); |
195 | | - cy.get('[data-index="3"]').as('se3'); |
196 | | - cy.findAllByRole('separator').each(($splitter, index) => { |
197 | | - cy.wrap($splitter).as(`splitter${index}`); |
198 | | - }); |
| 203 | + cy.get('@resize').should('not.have.been.called'); |
| 204 | + cy.findAllByRole('separator') |
| 205 | + .eq(0) |
| 206 | + .realMouseDown({ position: 'center' }) |
| 207 | + .realMouseMove(...getMouseMoveArgs(-100), { |
| 208 | + position: 'center', |
| 209 | + scrollBehavior: false, |
| 210 | + }) |
| 211 | + .realMouseUp({ position: 'center' }); |
| 212 | + |
| 213 | + cy.findByTestId('0') |
| 214 | + .invoke('text') |
| 215 | + .then((txt) => parseInt(txt, 10)) |
| 216 | + .should('be.within', 99, 101); |
| 217 | + cy.findByTestId('1') |
| 218 | + .invoke('text') |
| 219 | + .then((txt) => parseInt(txt, 10)) |
| 220 | + .should('be.within', 299, 301); |
| 221 | + cy.findByTestId('2').should('have.text', 'auto'); |
| 222 | + cy.findByTestId('3').invoke('text').should('equal', '200px'); |
| 223 | + |
| 224 | + cy.findAllByRole('separator').eq(0).realMouseDown({ position: 'center' }); |
| 225 | + // drag across bounding box |
| 226 | + cy.get('body') |
| 227 | + .realMouseMove(...getMouseMoveArgs(300), { |
| 228 | + position: 'center', |
| 229 | + scrollBehavior: false, |
| 230 | + }) |
| 231 | + .realMouseUp({ position: 'center' }); |
| 232 | + |
| 233 | + cy.wait(50); |
| 234 | + cy.findByTestId('0') |
| 235 | + .invoke('text') |
| 236 | + .then((txt) => parseInt(txt, 10)) |
| 237 | + .should('be.within', 383, 385); |
| 238 | + cy.findByTestId('1') |
| 239 | + .invoke('text') |
| 240 | + .then((txt) => parseInt(txt, 10)) |
| 241 | + .should('be.within', 15, 17); |
| 242 | + cy.findByTestId('2').should('have.text', 'auto'); |
| 243 | + cy.findByTestId('3').invoke('text').should('equal', '200px'); |
| 244 | + |
| 245 | + cy.findAllByRole('separator').eq(2).click().realPress('ArrowDown').realPress('ArrowDown').realPress('ArrowDown'); |
| 246 | + |
| 247 | + cy.findByTestId('0') |
| 248 | + .invoke('text') |
| 249 | + .then((txt) => parseInt(txt, 10)) |
| 250 | + .should('be.within', 383, 385); |
| 251 | + cy.findByTestId('1') |
| 252 | + .invoke('text') |
| 253 | + .then((txt) => parseInt(txt, 10)) |
| 254 | + .should('be.within', 15, 17); |
| 255 | + cy.findByTestId('2').should('have.text', '360px'); |
| 256 | + cy.findByTestId('3').should('have.text', '140px'); |
199 | 257 | }); |
200 | 258 | }); |
201 | 259 |
|
|
0 commit comments