This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device manager - current session expandable details (PSG-644) (#9185)
* split current device section into component * add dropdown button for currentsession device details * test currentdevicesection * remove unnecc beforeEach * update type imports * i18n and lint
- Loading branch information
Kerry
authored
Aug 15, 2022
1 parent
0c5ad45
commit 0dffc58
Showing
15 changed files
with
642 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
res/css/components/views/settings/devices/_DeviceExpandDetailsButton.pcss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_DeviceExpandDetailsButton { | ||
height: 32px; | ||
width: 32px; | ||
background: transparent; | ||
|
||
border-radius: 4px; | ||
color: $secondary-content; | ||
|
||
--icon-transform: rotate(-90deg); | ||
} | ||
|
||
.mx_DeviceExpandDetailsButton.mx_DeviceExpandDetailsButton_expanded { | ||
--icon-transform: rotate(0deg); | ||
|
||
background: $system; | ||
} | ||
|
||
.mx_DeviceExpandDetailsButton_icon { | ||
height: 12px; | ||
width: 12px; | ||
|
||
transition: all 0.3s; | ||
transform: var(--icon-transform); | ||
transform-origin: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/components/views/settings/devices/CurrentDeviceSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { _t } from '../../../../languageHandler'; | ||
import Spinner from '../../elements/Spinner'; | ||
import SettingsSubsection from '../shared/SettingsSubsection'; | ||
import DeviceDetails from './DeviceDetails'; | ||
import DeviceExpandDetailsButton from './DeviceExpandDetailsButton'; | ||
import DeviceSecurityCard from './DeviceSecurityCard'; | ||
import DeviceTile from './DeviceTile'; | ||
import { | ||
DeviceSecurityVariation, | ||
DeviceWithVerification, | ||
} from './types'; | ||
|
||
interface Props { | ||
device?: DeviceWithVerification; | ||
isLoading: boolean; | ||
} | ||
|
||
const CurrentDeviceSection: React.FC<Props> = ({ | ||
device, isLoading, | ||
}) => { | ||
const [isExpanded, setIsExpanded] = useState(false); | ||
const securityCardProps = device?.isVerified ? { | ||
variation: DeviceSecurityVariation.Verified, | ||
heading: _t('Verified session'), | ||
description: _t('This session is ready for secure messaging.'), | ||
} : { | ||
variation: DeviceSecurityVariation.Unverified, | ||
heading: _t('Unverified session'), | ||
description: _t('Verify or sign out from this session for best security and reliability.'), | ||
}; | ||
return <SettingsSubsection | ||
heading={_t('Current session')} | ||
data-testid='current-session-section' | ||
> | ||
{ isLoading && <Spinner /> } | ||
{ !!device && <> | ||
<DeviceTile | ||
device={device} | ||
> | ||
<DeviceExpandDetailsButton | ||
data-testid='current-session-toggle-details' | ||
isExpanded={isExpanded} | ||
onClick={() => setIsExpanded(!isExpanded)} | ||
/> | ||
</DeviceTile> | ||
{ isExpanded && <DeviceDetails device={device} /> } | ||
<br /> | ||
<DeviceSecurityCard | ||
{...securityCardProps} | ||
/> | ||
</> | ||
} | ||
</SettingsSubsection>; | ||
}; | ||
|
||
export default CurrentDeviceSection; |
41 changes: 41 additions & 0 deletions
41
src/components/views/settings/devices/DeviceExpandDetailsButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
|
||
import { Icon as CaretIcon } from '../../../../../res/img/feather-customised/dropdown-arrow.svg'; | ||
import AccessibleButton from '../../elements/AccessibleButton'; | ||
|
||
interface Props { | ||
isExpanded: boolean; | ||
onClick: () => void; | ||
} | ||
|
||
const DeviceExpandDetailsButton: React.FC<Props> = ({ isExpanded, onClick, ...rest }) => { | ||
return <AccessibleButton | ||
{...rest} | ||
kind='icon' | ||
className={classNames('mx_DeviceExpandDetailsButton', { | ||
mx_DeviceExpandDetailsButton_expanded: isExpanded, | ||
})} | ||
onClick={onClick} | ||
> | ||
<CaretIcon className='mx_DeviceExpandDetailsButton_icon' /> | ||
</AccessibleButton>; | ||
}; | ||
|
||
export default DeviceExpandDetailsButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
test/components/views/settings/devices/CurrentDeviceSection-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import CurrentDeviceSection from '../../../../../src/components/views/settings/devices/CurrentDeviceSection'; | ||
|
||
describe('<CurrentDeviceSection />', () => { | ||
const deviceId = 'alices_device'; | ||
|
||
const alicesVerifiedDevice = { | ||
device_id: deviceId, | ||
isVerified: false, | ||
}; | ||
const alicesUnverifiedDevice = { | ||
device_id: deviceId, | ||
isVerified: false, | ||
}; | ||
|
||
const defaultProps = { | ||
device: alicesVerifiedDevice, | ||
isLoading: false, | ||
}; | ||
const getComponent = (props = {}): React.ReactElement => | ||
(<CurrentDeviceSection {...defaultProps} {...props} />); | ||
|
||
it('renders spinner while device is loading', () => { | ||
const { container } = render(getComponent({ device: undefined, isLoading: true })); | ||
expect(container.getElementsByClassName('mx_Spinner').length).toBeTruthy(); | ||
}); | ||
|
||
it('handles when device is falsy', async () => { | ||
const { container } = render(getComponent({ device: undefined })); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders device and correct security card when device is verified', () => { | ||
const { container } = render(getComponent()); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders device and correct security card when device is unverified', () => { | ||
const { container } = render(getComponent({ device: alicesUnverifiedDevice })); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays device details on toggle click', () => { | ||
const { container, getByTestId } = render(getComponent({ device: alicesUnverifiedDevice })); | ||
|
||
act(() => { | ||
fireEvent.click(getByTestId('current-session-toggle-details')); | ||
}); | ||
|
||
expect(container.getElementsByClassName('mx_DeviceDetails')).toMatchSnapshot(); | ||
|
||
act(() => { | ||
fireEvent.click(getByTestId('current-session-toggle-details')); | ||
}); | ||
|
||
// device details are hidden | ||
expect(container.getElementsByClassName('mx_DeviceDetails').length).toBeFalsy(); | ||
}); | ||
}); |
Oops, something went wrong.