Device manager - label devices as inactive (PSG-638) (#9175)
* filter devices by security recommendation * display inactive status on device tile * unify DeviceSecurityVariation type, add correct icon to inactive ui * tidy * avoid dead code warning
This commit is contained in:
parent
d21498de94
commit
4a5ed2f899
10 changed files with 189 additions and 25 deletions
|
@ -17,9 +17,8 @@ limitations under the License.
|
|||
import { render } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import DeviceSecurityCard, {
|
||||
DeviceSecurityVariation,
|
||||
} from '../../../../../src/components/views/settings/devices/DeviceSecurityCard';
|
||||
import DeviceSecurityCard from '../../../../../src/components/views/settings/devices/DeviceSecurityCard';
|
||||
import { DeviceSecurityVariation } from '../../../../../src/components/views/settings/devices/filter';
|
||||
|
||||
describe('<DeviceSecurityCard />', () => {
|
||||
const defaultProps = {
|
||||
|
|
|
@ -109,5 +109,18 @@ describe('<DeviceTile />', () => {
|
|||
const { getByTestId } = render(getComponent({ device }));
|
||||
expect(getByTestId('device-metadata-lastActivity').textContent).toEqual('Last activity Dec 29, 2021');
|
||||
});
|
||||
|
||||
it('renders with inactive notice when last activity was more than 90 days ago', () => {
|
||||
const device: IMyDevice = {
|
||||
device_id: '123',
|
||||
last_seen_ip: '1.2.3.4',
|
||||
last_seen_ts: now - (MS_DAY * 100),
|
||||
};
|
||||
const { getByTestId, queryByTestId } = render(getComponent({ device }));
|
||||
expect(getByTestId('device-metadata-inactive').textContent).toEqual('Inactive for 90+ days (Dec 4, 2021)');
|
||||
// last activity and verification not shown when inactive
|
||||
expect(queryByTestId('device-metadata-lastActivity')).toBeFalsy();
|
||||
expect(queryByTestId('device-metadata-verificationStatus')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
77
test/components/views/settings/devices/filter-test.ts
Normal file
77
test/components/views/settings/devices/filter-test.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
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 {
|
||||
DeviceSecurityVariation,
|
||||
filterDevicesBySecurityRecommendation,
|
||||
} from "../../../../../src/components/views/settings/devices/filter";
|
||||
|
||||
const MS_DAY = 86400000;
|
||||
describe('filterDevicesBySecurityRecommendation()', () => {
|
||||
const unverifiedNoMetadata = { device_id: 'unverified-no-metadata', isVerified: false };
|
||||
const verifiedNoMetadata = { device_id: 'verified-no-metadata', isVerified: true };
|
||||
const hundredDaysOld = { device_id: '100-days-old', isVerified: true, last_seen_ts: Date.now() - (MS_DAY * 100) };
|
||||
const hundredDaysOldUnverified = {
|
||||
device_id: 'unverified-100-days-old',
|
||||
isVerified: false,
|
||||
last_seen_ts: Date.now() - (MS_DAY * 100),
|
||||
};
|
||||
const fiftyDaysOld = { device_id: '50-days-old', isVerified: true, last_seen_ts: Date.now() - (MS_DAY * 50) };
|
||||
|
||||
const devices = [
|
||||
unverifiedNoMetadata,
|
||||
verifiedNoMetadata,
|
||||
hundredDaysOld,
|
||||
hundredDaysOldUnverified,
|
||||
fiftyDaysOld,
|
||||
];
|
||||
|
||||
it('returns all devices when no securityRecommendations are passed', () => {
|
||||
expect(filterDevicesBySecurityRecommendation(devices, [])).toBe(devices);
|
||||
});
|
||||
|
||||
it('returns devices older than 90 days as inactive', () => {
|
||||
expect(filterDevicesBySecurityRecommendation(devices, [DeviceSecurityVariation.Inactive])).toEqual([
|
||||
// devices without ts metadata are not filtered as inactive
|
||||
hundredDaysOld,
|
||||
hundredDaysOldUnverified,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns correct devices for verified filter', () => {
|
||||
expect(filterDevicesBySecurityRecommendation(devices, [DeviceSecurityVariation.Verified])).toEqual([
|
||||
verifiedNoMetadata,
|
||||
hundredDaysOld,
|
||||
fiftyDaysOld,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns correct devices for unverified filter', () => {
|
||||
expect(filterDevicesBySecurityRecommendation(devices, [DeviceSecurityVariation.Unverified])).toEqual([
|
||||
unverifiedNoMetadata,
|
||||
hundredDaysOldUnverified,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns correct devices for combined verified and inactive filters', () => {
|
||||
expect(filterDevicesBySecurityRecommendation(
|
||||
devices,
|
||||
[DeviceSecurityVariation.Unverified, DeviceSecurityVariation.Inactive],
|
||||
)).toEqual([
|
||||
hundredDaysOldUnverified,
|
||||
]);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue