Device manager - scroll to filtered list from security recommendations (PSG-640) (#9227)
* scroll to filtered list from security recommendations * test sessionmanager scroll to * stable snapshot * fix strict errors * prtidy * use smooth scrolling
This commit is contained in:
parent
0d6a550c33
commit
54a66bd242
8 changed files with 201 additions and 91 deletions
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
import React from 'react';
|
||||
import { act, fireEvent, render } from '@testing-library/react';
|
||||
|
||||
import FilteredDeviceList from '../../../../../src/components/views/settings/devices/FilteredDeviceList';
|
||||
import { FilteredDeviceList } from '../../../../../src/components/views/settings/devices/FilteredDeviceList';
|
||||
import { DeviceSecurityVariation } from '../../../../../src/components/views/settings/devices/types';
|
||||
import { flushPromises, mockPlatformPeg } from '../../../../test-utils';
|
||||
|
||||
|
|
|
@ -15,9 +15,10 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import { act, fireEvent, render } from '@testing-library/react';
|
||||
|
||||
import SecurityRecommendations from '../../../../../src/components/views/settings/devices/SecurityRecommendations';
|
||||
import { DeviceSecurityVariation } from '../../../../../src/components/views/settings/devices/types';
|
||||
|
||||
const MS_DAY = 24 * 60 * 60 * 1000;
|
||||
describe('<SecurityRecommendations />', () => {
|
||||
|
@ -32,6 +33,7 @@ describe('<SecurityRecommendations />', () => {
|
|||
|
||||
const defaultProps = {
|
||||
devices: {},
|
||||
goToFilteredList: jest.fn(),
|
||||
};
|
||||
const getComponent = (props = {}) =>
|
||||
(<SecurityRecommendations {...defaultProps} {...props} />);
|
||||
|
@ -69,4 +71,36 @@ describe('<SecurityRecommendations />', () => {
|
|||
const { container } = render(getComponent({ devices }));
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('clicking view all unverified devices button works', () => {
|
||||
const goToFilteredList = jest.fn();
|
||||
const devices = {
|
||||
[verifiedNoMetadata.device_id]: verifiedNoMetadata,
|
||||
[hundredDaysOld.device_id]: hundredDaysOld,
|
||||
[unverifiedNoMetadata.device_id]: unverifiedNoMetadata,
|
||||
};
|
||||
const { getByTestId } = render(getComponent({ devices, goToFilteredList }));
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(getByTestId('unverified-devices-cta'));
|
||||
});
|
||||
|
||||
expect(goToFilteredList).toHaveBeenCalledWith(DeviceSecurityVariation.Unverified);
|
||||
});
|
||||
|
||||
it('clicking view all inactive devices button works', () => {
|
||||
const goToFilteredList = jest.fn();
|
||||
const devices = {
|
||||
[verifiedNoMetadata.device_id]: verifiedNoMetadata,
|
||||
[hundredDaysOld.device_id]: hundredDaysOld,
|
||||
[unverifiedNoMetadata.device_id]: unverifiedNoMetadata,
|
||||
};
|
||||
const { getByTestId } = render(getComponent({ devices, goToFilteredList }));
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(getByTestId('inactive-devices-cta'));
|
||||
});
|
||||
|
||||
expect(goToFilteredList).toHaveBeenCalledWith(DeviceSecurityVariation.Inactive);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -48,6 +48,7 @@ exports[`<SecurityRecommendations /> renders both cards when user has both unver
|
|||
>
|
||||
<div
|
||||
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
|
||||
data-testid="unverified-devices-cta"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
|
@ -88,6 +89,7 @@ exports[`<SecurityRecommendations /> renders both cards when user has both unver
|
|||
>
|
||||
<div
|
||||
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
|
||||
data-testid="inactive-devices-cta"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
|
@ -149,6 +151,7 @@ exports[`<SecurityRecommendations /> renders inactive devices section when user
|
|||
>
|
||||
<div
|
||||
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
|
||||
data-testid="unverified-devices-cta"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
|
@ -189,6 +192,7 @@ exports[`<SecurityRecommendations /> renders inactive devices section when user
|
|||
>
|
||||
<div
|
||||
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
|
||||
data-testid="inactive-devices-cta"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
|
@ -250,6 +254,7 @@ exports[`<SecurityRecommendations /> renders unverified devices section when use
|
|||
>
|
||||
<div
|
||||
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
|
||||
data-testid="unverified-devices-cta"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
|
@ -290,6 +295,7 @@ exports[`<SecurityRecommendations /> renders unverified devices section when use
|
|||
>
|
||||
<div
|
||||
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
|
||||
data-testid="inactive-devices-cta"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
|
|
|
@ -193,6 +193,23 @@ describe('<SessionManagerTab />', () => {
|
|||
expect(getByTestId('other-sessions-section')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('goes to filtered list from security recommendations', async () => {
|
||||
mockClient.getDevices.mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
|
||||
const { getByTestId, container } = render(getComponent());
|
||||
|
||||
await act(async () => {
|
||||
await flushPromisesWithFakeTimers();
|
||||
});
|
||||
|
||||
fireEvent.click(getByTestId('unverified-devices-cta'));
|
||||
|
||||
// our session manager waits a tick for rerender
|
||||
await flushPromisesWithFakeTimers();
|
||||
|
||||
// unverified filter is set
|
||||
expect(container.querySelector('.mx_FilteredDeviceList_header')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe('device detail expansion', () => {
|
||||
it('renders no devices expanded by default', async () => {
|
||||
mockClient.getDevices.mockResolvedValue({
|
||||
|
@ -220,30 +237,24 @@ describe('<SessionManagerTab />', () => {
|
|||
await flushPromisesWithFakeTimers();
|
||||
});
|
||||
|
||||
act(() => {
|
||||
const tile = getByTestId(`device-tile-${alicesOlderMobileDevice.device_id}`);
|
||||
const toggle = tile.querySelector('[aria-label="Toggle device details"]');
|
||||
fireEvent.click(toggle);
|
||||
});
|
||||
const tile1 = getByTestId(`device-tile-${alicesOlderMobileDevice.device_id}`);
|
||||
const toggle1 = tile1.querySelector('[aria-label="Toggle device details"]') as Element;
|
||||
fireEvent.click(toggle1);
|
||||
|
||||
// device details are expanded
|
||||
expect(getByTestId(`device-detail-${alicesOlderMobileDevice.device_id}`)).toBeTruthy();
|
||||
|
||||
act(() => {
|
||||
const tile = getByTestId(`device-tile-${alicesMobileDevice.device_id}`);
|
||||
const toggle = tile.querySelector('[aria-label="Toggle device details"]');
|
||||
fireEvent.click(toggle);
|
||||
});
|
||||
const tile2 = getByTestId(`device-tile-${alicesMobileDevice.device_id}`);
|
||||
const toggle2 = tile2.querySelector('[aria-label="Toggle device details"]') as Element;
|
||||
fireEvent.click(toggle2);
|
||||
|
||||
// both device details are expanded
|
||||
expect(getByTestId(`device-detail-${alicesOlderMobileDevice.device_id}`)).toBeTruthy();
|
||||
expect(getByTestId(`device-detail-${alicesMobileDevice.device_id}`)).toBeTruthy();
|
||||
|
||||
act(() => {
|
||||
const tile = getByTestId(`device-tile-${alicesMobileDevice.device_id}`);
|
||||
const toggle = tile.querySelector('[aria-label="Toggle device details"]');
|
||||
fireEvent.click(toggle);
|
||||
});
|
||||
const tile3 = getByTestId(`device-tile-${alicesMobileDevice.device_id}`);
|
||||
const toggle3 = tile3.querySelector('[aria-label="Toggle device details"]') as Element;
|
||||
fireEvent.click(toggle3);
|
||||
|
||||
// alicesMobileDevice was toggled off
|
||||
expect(queryByTestId(`device-detail-${alicesMobileDevice.device_id}`)).toBeFalsy();
|
||||
|
|
|
@ -1,5 +1,41 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<SessionManagerTab /> goes to filtered list from security recommendations 1`] = `
|
||||
<div
|
||||
class="mx_FilteredDeviceList_header"
|
||||
>
|
||||
<span
|
||||
class="mx_FilteredDeviceList_headerLabel"
|
||||
>
|
||||
Sessions
|
||||
</span>
|
||||
<div
|
||||
class="mx_Dropdown mx_FilterDropdown"
|
||||
>
|
||||
<div
|
||||
aria-describedby="device-list-filter_value"
|
||||
aria-expanded="false"
|
||||
aria-haspopup="listbox"
|
||||
aria-label="Filter devices"
|
||||
aria-owns="device-list-filter_input"
|
||||
class="mx_AccessibleButton mx_Dropdown_input mx_no_textinput"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div
|
||||
class="mx_Dropdown_option"
|
||||
id="device-list-filter_value"
|
||||
>
|
||||
Show: Unverified
|
||||
</div>
|
||||
<span
|
||||
class="mx_Dropdown_arrow"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<SessionManagerTab /> renders current session section with a verified session 1`] = `
|
||||
<div
|
||||
class="mx_SettingsSubsection"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue