@@ -15,7 +15,7 @@ limitations under the License.
1515*/
1616
1717import React from 'react' ;
18- import { render } from '@testing-library/react' ;
18+ import { fireEvent , render } from '@testing-library/react' ;
1919import { act } from 'react-dom/test-utils' ;
2020import { DeviceInfo } from 'matrix-js-sdk/src/crypto/deviceinfo' ;
2121import { logger } from 'matrix-js-sdk/src/logger' ;
@@ -192,4 +192,63 @@ describe('<SessionManagerTab />', () => {
192192
193193 expect ( getByTestId ( 'other-sessions-section' ) ) . toBeTruthy ( ) ;
194194 } ) ;
195+
196+ describe ( 'device detail expansion' , ( ) => {
197+ it ( 'renders no devices expanded by default' , async ( ) => {
198+ mockClient . getDevices . mockResolvedValue ( {
199+ devices : [ alicesDevice , alicesOlderMobileDevice , alicesMobileDevice ] ,
200+ } ) ;
201+ const { getByTestId } = render ( getComponent ( ) ) ;
202+
203+ await act ( async ( ) => {
204+ await flushPromisesWithFakeTimers ( ) ;
205+ } ) ;
206+
207+ const otherSessionsSection = getByTestId ( 'other-sessions-section' ) ;
208+
209+ // no expanded device details
210+ expect ( otherSessionsSection . getElementsByClassName ( 'mx_DeviceDetails' ) . length ) . toBeFalsy ( ) ;
211+ } ) ;
212+
213+ it ( 'toggles device expansion on click' , async ( ) => {
214+ mockClient . getDevices . mockResolvedValue ( {
215+ devices : [ alicesDevice , alicesOlderMobileDevice , alicesMobileDevice ] ,
216+ } ) ;
217+ const { getByTestId, queryByTestId } = render ( getComponent ( ) ) ;
218+
219+ await act ( async ( ) => {
220+ await flushPromisesWithFakeTimers ( ) ;
221+ } ) ;
222+
223+ act ( ( ) => {
224+ const tile = getByTestId ( `device-tile-${ alicesOlderMobileDevice . device_id } ` ) ;
225+ const toggle = tile . querySelector ( '[aria-label="Toggle device details"]' ) ;
226+ fireEvent . click ( toggle ) ;
227+ } ) ;
228+
229+ // device details are expanded
230+ expect ( getByTestId ( `device-detail-${ alicesOlderMobileDevice . device_id } ` ) ) . toBeTruthy ( ) ;
231+
232+ act ( ( ) => {
233+ const tile = getByTestId ( `device-tile-${ alicesMobileDevice . device_id } ` ) ;
234+ const toggle = tile . querySelector ( '[aria-label="Toggle device details"]' ) ;
235+ fireEvent . click ( toggle ) ;
236+ } ) ;
237+
238+ // both device details are expanded
239+ expect ( getByTestId ( `device-detail-${ alicesOlderMobileDevice . device_id } ` ) ) . toBeTruthy ( ) ;
240+ expect ( getByTestId ( `device-detail-${ alicesMobileDevice . device_id } ` ) ) . toBeTruthy ( ) ;
241+
242+ act ( ( ) => {
243+ const tile = getByTestId ( `device-tile-${ alicesMobileDevice . device_id } ` ) ;
244+ const toggle = tile . querySelector ( '[aria-label="Toggle device details"]' ) ;
245+ fireEvent . click ( toggle ) ;
246+ } ) ;
247+
248+ // alicesMobileDevice was toggled off
249+ expect ( queryByTestId ( `device-detail-${ alicesMobileDevice . device_id } ` ) ) . toBeFalsy ( ) ;
250+ // alicesOlderMobileDevice stayed open
251+ expect ( getByTestId ( `device-detail-${ alicesOlderMobileDevice . device_id } ` ) ) . toBeTruthy ( ) ;
252+ } ) ;
253+ } ) ;
195254} ) ;
0 commit comments