Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 48bb745

Browse files
author
Kerry Archibald
committed
test security recs
1 parent 27be7f0 commit 48bb745

File tree

2 files changed

+336
-6
lines changed

2 files changed

+336
-6
lines changed
Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,72 @@
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+
*/
116

217
import React from 'react';
3-
import { mount } from 'enzyme';
18+
import { render } from '@testing-library/react';
419

520
import SecurityRecommendations from '../../../../../src/components/views/settings/devices/SecurityRecommendations';
621

22+
const MS_DAY = 86400000;
723
describe('<SecurityRecommendations />', () => {
8-
const defaultProps = {};
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+
};
936
const getComponent = (props = {}) =>
10-
mount(<SecurityRecommendations {...defaultProps} {...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+
});
1162

12-
it('renders', () => {
13-
const component = getComponent();
14-
expect(component).toBeTruthy();
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();
1571
});
1672
});
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<SecurityRecommendations /> renders both cards when user has both unverified and inactive devices 1`] = `
4+
<div>
5+
<div
6+
class="mx_SettingsSubsection"
7+
data-testid="security-recommendations-section"
8+
>
9+
<h3
10+
class="mx_Heading_h3 mx_SettingsSubsection_heading"
11+
>
12+
Security recommendations
13+
</h3>
14+
<div
15+
class="mx_SettingsSubsection_description"
16+
>
17+
Improve your account security by following these recommendations
18+
</div>
19+
<div
20+
class="mx_SettingsSubsection_content"
21+
>
22+
<div
23+
class="mx_DeviceSecurityCard"
24+
>
25+
<div
26+
class="mx_DeviceSecurityCard_icon Unverified"
27+
>
28+
<div
29+
height="16"
30+
width="16"
31+
/>
32+
</div>
33+
<div
34+
class="mx_DeviceSecurityCard_content"
35+
>
36+
<p
37+
class="mx_DeviceSecurityCard_heading"
38+
>
39+
Unverified sessions
40+
</p>
41+
<p
42+
class="mx_DeviceSecurityCard_description"
43+
>
44+
Verify your sessions for enhanced secure messaging or sign out from those you don't recognize or use anymore.
45+
</p>
46+
<div
47+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
48+
role="button"
49+
tabindex="0"
50+
>
51+
View all (1)
52+
</div>
53+
</div>
54+
</div>
55+
<br />
56+
<div
57+
class="mx_DeviceSecurityCard"
58+
>
59+
<div
60+
class="mx_DeviceSecurityCard_icon Inactive"
61+
>
62+
<div
63+
height="16"
64+
width="16"
65+
/>
66+
</div>
67+
<div
68+
class="mx_DeviceSecurityCard_content"
69+
>
70+
<p
71+
class="mx_DeviceSecurityCard_heading"
72+
>
73+
Inactive sessions
74+
</p>
75+
<p
76+
class="mx_DeviceSecurityCard_description"
77+
>
78+
Consider signing out from old sessions (90 days or older) you don't use anymore
79+
</p>
80+
<div
81+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
82+
role="button"
83+
tabindex="0"
84+
>
85+
View all (1)
86+
</div>
87+
</div>
88+
</div>
89+
</div>
90+
</div>
91+
</div>
92+
`;
93+
94+
exports[`<SecurityRecommendations /> renders inactive devices section when user has inactive devices 1`] = `
95+
<div>
96+
<div
97+
class="mx_SettingsSubsection"
98+
data-testid="security-recommendations-section"
99+
>
100+
<h3
101+
class="mx_Heading_h3 mx_SettingsSubsection_heading"
102+
>
103+
Security recommendations
104+
</h3>
105+
<div
106+
class="mx_SettingsSubsection_description"
107+
>
108+
Improve your account security by following these recommendations
109+
</div>
110+
<div
111+
class="mx_SettingsSubsection_content"
112+
>
113+
<div
114+
class="mx_DeviceSecurityCard"
115+
>
116+
<div
117+
class="mx_DeviceSecurityCard_icon Unverified"
118+
>
119+
<div
120+
height="16"
121+
width="16"
122+
/>
123+
</div>
124+
<div
125+
class="mx_DeviceSecurityCard_content"
126+
>
127+
<p
128+
class="mx_DeviceSecurityCard_heading"
129+
>
130+
Unverified sessions
131+
</p>
132+
<p
133+
class="mx_DeviceSecurityCard_description"
134+
>
135+
Verify your sessions for enhanced secure messaging or sign out from those you don't recognize or use anymore.
136+
</p>
137+
<div
138+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
139+
role="button"
140+
tabindex="0"
141+
>
142+
View all (1)
143+
</div>
144+
</div>
145+
</div>
146+
<br />
147+
<div
148+
class="mx_DeviceSecurityCard"
149+
>
150+
<div
151+
class="mx_DeviceSecurityCard_icon Inactive"
152+
>
153+
<div
154+
height="16"
155+
width="16"
156+
/>
157+
</div>
158+
<div
159+
class="mx_DeviceSecurityCard_content"
160+
>
161+
<p
162+
class="mx_DeviceSecurityCard_heading"
163+
>
164+
Inactive sessions
165+
</p>
166+
<p
167+
class="mx_DeviceSecurityCard_description"
168+
>
169+
Consider signing out from old sessions (90 days or older) you don't use anymore
170+
</p>
171+
<div
172+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
173+
role="button"
174+
tabindex="0"
175+
>
176+
View all (1)
177+
</div>
178+
</div>
179+
</div>
180+
</div>
181+
</div>
182+
</div>
183+
`;
184+
185+
exports[`<SecurityRecommendations /> renders unverified devices section when user has unverified devices 1`] = `
186+
<div>
187+
<div
188+
class="mx_SettingsSubsection"
189+
data-testid="security-recommendations-section"
190+
>
191+
<h3
192+
class="mx_Heading_h3 mx_SettingsSubsection_heading"
193+
>
194+
Security recommendations
195+
</h3>
196+
<div
197+
class="mx_SettingsSubsection_description"
198+
>
199+
Improve your account security by following these recommendations
200+
</div>
201+
<div
202+
class="mx_SettingsSubsection_content"
203+
>
204+
<div
205+
class="mx_DeviceSecurityCard"
206+
>
207+
<div
208+
class="mx_DeviceSecurityCard_icon Unverified"
209+
>
210+
<div
211+
height="16"
212+
width="16"
213+
/>
214+
</div>
215+
<div
216+
class="mx_DeviceSecurityCard_content"
217+
>
218+
<p
219+
class="mx_DeviceSecurityCard_heading"
220+
>
221+
Unverified sessions
222+
</p>
223+
<p
224+
class="mx_DeviceSecurityCard_description"
225+
>
226+
Verify your sessions for enhanced secure messaging or sign out from those you don't recognize or use anymore.
227+
</p>
228+
<div
229+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
230+
role="button"
231+
tabindex="0"
232+
>
233+
View all (2)
234+
</div>
235+
</div>
236+
</div>
237+
<br />
238+
<div
239+
class="mx_DeviceSecurityCard"
240+
>
241+
<div
242+
class="mx_DeviceSecurityCard_icon Inactive"
243+
>
244+
<div
245+
height="16"
246+
width="16"
247+
/>
248+
</div>
249+
<div
250+
class="mx_DeviceSecurityCard_content"
251+
>
252+
<p
253+
class="mx_DeviceSecurityCard_heading"
254+
>
255+
Inactive sessions
256+
</p>
257+
<p
258+
class="mx_DeviceSecurityCard_description"
259+
>
260+
Consider signing out from old sessions (90 days or older) you don't use anymore
261+
</p>
262+
<div
263+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
264+
role="button"
265+
tabindex="0"
266+
>
267+
View all (1)
268+
</div>
269+
</div>
270+
</div>
271+
</div>
272+
</div>
273+
</div>
274+
`;

0 commit comments

Comments
 (0)