|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import { render } from '@testing-library/react'; |
| 19 | + |
| 20 | +import SecurityRecommendations from '../../../../../src/components/views/settings/devices/SecurityRecommendations'; |
| 21 | + |
| 22 | +const MS_DAY = 24 * 60 * 60 * 1000; |
| 23 | +describe('<SecurityRecommendations />', () => { |
| 24 | + const unverifiedNoMetadata = { device_id: 'unverified-no-metadata', isVerified: false }; |
| 25 | + const verifiedNoMetadata = { device_id: 'verified-no-metadata', isVerified: true }; |
| 26 | + const hundredDaysOld = { device_id: '100-days-old', isVerified: true, last_seen_ts: Date.now() - (MS_DAY * 100) }; |
| 27 | + const hundredDaysOldUnverified = { |
| 28 | + device_id: 'unverified-100-days-old', |
| 29 | + isVerified: false, |
| 30 | + last_seen_ts: Date.now() - (MS_DAY * 100), |
| 31 | + }; |
| 32 | + |
| 33 | + const defaultProps = { |
| 34 | + devices: {}, |
| 35 | + }; |
| 36 | + const getComponent = (props = {}) => |
| 37 | + (<SecurityRecommendations {...defaultProps} {...props} />); |
| 38 | + |
| 39 | + it('renders null when no devices', () => { |
| 40 | + const { container } = render(getComponent()); |
| 41 | + expect(container.firstChild).toBeNull(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('renders unverified devices section when user has unverified devices', () => { |
| 45 | + const devices = { |
| 46 | + [unverifiedNoMetadata.device_id]: unverifiedNoMetadata, |
| 47 | + [verifiedNoMetadata.device_id]: verifiedNoMetadata, |
| 48 | + [hundredDaysOldUnverified.device_id]: hundredDaysOldUnverified, |
| 49 | + }; |
| 50 | + const { container } = render(getComponent({ devices })); |
| 51 | + expect(container).toMatchSnapshot(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('renders inactive devices section when user has inactive devices', () => { |
| 55 | + const devices = { |
| 56 | + [verifiedNoMetadata.device_id]: verifiedNoMetadata, |
| 57 | + [hundredDaysOldUnverified.device_id]: hundredDaysOldUnverified, |
| 58 | + }; |
| 59 | + const { container } = render(getComponent({ devices })); |
| 60 | + expect(container).toMatchSnapshot(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('renders both cards when user has both unverified and inactive devices', () => { |
| 64 | + const devices = { |
| 65 | + [verifiedNoMetadata.device_id]: verifiedNoMetadata, |
| 66 | + [hundredDaysOld.device_id]: hundredDaysOld, |
| 67 | + [unverifiedNoMetadata.device_id]: unverifiedNoMetadata, |
| 68 | + }; |
| 69 | + const { container } = render(getComponent({ devices })); |
| 70 | + expect(container).toMatchSnapshot(); |
| 71 | + }); |
| 72 | +}); |
0 commit comments