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

Commit d5a4718

Browse files
Kerryhughnsturt2live
authored
Test display of qr code login section (#9456)
* Support for login + E2EE set up with QR * Whitespace * Padding * Refactor of fetch * Whitespace * CSS whitespace * Add link to MSC3906 * Handle incorrect typing in MatrixClientPeg.get() * Use unstable class name * fix: use unstable class name * Use default fetch client instead * Update to revised function name * Refactor device manager panel and make it work with new sessions manager * Lint fix * Add missing interstitials and update wording * Linting * i18n * Lint * Use sensible sdk config name for fallback server * Improve error handling for QR code generation * Refactor feature availability logic * Hide device manager panel if no options available * Put sign in with QR behind lab setting * Reduce scope of PR to just showing code on existing device * i18n updates * Handle null features * Testing for LoginWithQRSection * Refactor to handle UIA * Imports * Reduce diff complexity * Remove unnecessary change * Remove unused styles * Support UIA * Tidy up * i18n * Remove additional unused parts of flow * Add extra instruction when showing QR code * Add getVersions to server mocks * Use proper colours for theme support * Test cases * Lint * Remove obsolete snapshot * Don't override error if already set * Remove unused var * Update src/components/views/settings/devices/LoginWithQRSection.tsx Co-authored-by: Travis Ralston <[email protected]> * Update src/components/views/auth/LoginWithQR.tsx Co-authored-by: Travis Ralston <[email protected]> * Update src/components/views/auth/LoginWithQR.tsx Co-authored-by: Travis Ralston <[email protected]> * Update src/components/views/auth/LoginWithQR.tsx Co-authored-by: Travis Ralston <[email protected]> * Update src/components/views/auth/LoginWithQR.tsx Co-authored-by: Travis Ralston <[email protected]> * Update src/components/views/auth/LoginWithQR.tsx Co-authored-by: Travis Ralston <[email protected]> * Update res/css/views/auth/_LoginWithQR.pcss Co-authored-by: Kerry <[email protected]> * Use spacing variables * Remove debug * Style + docs * preventDefault * Names of tests * Fixes for js-sdk refactor * Update snapshots to match test names * Refactor labs config to make deployment simpler * i18n * Unused imports * Typo * Stateless component * Whitespace * Use context not MatrixClientPeg * Add missing context * Type updates to match js-sdk * Wrap click handlers in useCallback * Update src/components/views/settings/DevicesPanel.tsx Co-authored-by: Travis Ralston <[email protected]> * Wait for DOM update instead of timeout * Add missing snapshot update from last commit * Remove void keyword in favour of then() clauses * test main paths in LoginWithQR * test coverage for display of qr code section * remove unused test props Co-authored-by: Hugh Nimmo-Smith <[email protected]> Co-authored-by: Hugh Nimmo-Smith <[email protected]> Co-authored-by: Travis Ralston <[email protected]>
1 parent 8066b9f commit d5a4718

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

src/components/views/auth/LoginWithQR.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
370370
}
371371

372372
return (
373-
<div className="mx_LoginWithQR">
373+
<div data-testid="login-with-qr" className="mx_LoginWithQR">
374374
<div className={centreTitle ? "mx_LoginWithQR_centreTitle" : ""}>
375375
{ backButton ?
376376
<AccessibleButton

test/components/views/settings/devices/__snapshots__/LoginWithQR-test.tsx.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`<LoginWithQR /> approves login and waits for new device 1`] = `
44
<div>
55
<div
66
class="mx_LoginWithQR"
7+
data-testid="login-with-qr"
78
>
89
<div
910
class=""
@@ -61,6 +62,7 @@ exports[`<LoginWithQR /> displays confirmation digits after connected to rendezv
6162
<div>
6263
<div
6364
class="mx_LoginWithQR"
65+
data-testid="login-with-qr"
6466
>
6567
<div
6668
class=""
@@ -122,6 +124,7 @@ exports[`<LoginWithQR /> displays error when approving login fails 1`] = `
122124
<div>
123125
<div
124126
class="mx_LoginWithQR"
127+
data-testid="login-with-qr"
125128
>
126129
<div
127130
class="mx_LoginWithQR_centreTitle"
@@ -168,6 +171,7 @@ exports[`<LoginWithQR /> displays qr code after it is created 1`] = `
168171
<div>
169172
<div
170173
class="mx_LoginWithQR"
174+
data-testid="login-with-qr"
171175
>
172176
<div
173177
class=""
@@ -232,6 +236,7 @@ exports[`<LoginWithQR /> displays unknown error if connection to rendezvous fail
232236
<div>
233237
<div
234238
class="mx_LoginWithQR"
239+
data-testid="login-with-qr"
235240
>
236241
<div
237242
class="mx_LoginWithQR_centreTitle"
@@ -278,6 +283,7 @@ exports[`<LoginWithQR /> no content in case of no support 1`] = `
278283
<div>
279284
<div
280285
class="mx_LoginWithQR"
286+
data-testid="login-with-qr"
281287
>
282288
<div
283289
class="mx_LoginWithQR_centreTitle"
@@ -324,6 +330,7 @@ exports[`<LoginWithQR /> renders spinner while generating code 1`] = `
324330
<div>
325331
<div
326332
class="mx_LoginWithQR"
333+
data-testid="login-with-qr"
327334
>
328335
<div
329336
class=""

test/components/views/settings/tabs/user/SecurityUserSettingsTab-test.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import { render } from '@testing-library/react';
16+
import { fireEvent, render } from '@testing-library/react';
1717
import React from 'react';
1818

1919
import SecurityUserSettingsTab from "../../../../../../src/components/views/settings/tabs/user/SecurityUserSettingsTab";
@@ -26,6 +26,7 @@ import {
2626
mockClientMethodsCrypto,
2727
mockClientMethodsDevice,
2828
mockPlatformPeg,
29+
flushPromises,
2930
} from '../../../../../test-utils';
3031

3132
describe('<SecurityUserSettingsTab />', () => {
@@ -42,6 +43,12 @@ describe('<SecurityUserSettingsTab />', () => {
4243
...mockClientMethodsCrypto(),
4344
getRooms: jest.fn().mockReturnValue([]),
4445
getIgnoredUsers: jest.fn(),
46+
getVersions: jest.fn().mockResolvedValue({
47+
unstable_features: {
48+
'org.matrix.msc3882': true,
49+
'org.matrix.msc3886': true,
50+
},
51+
}),
4552
});
4653

4754
const getComponent = () =>
@@ -70,4 +77,34 @@ describe('<SecurityUserSettingsTab />', () => {
7077

7178
expect(queryByTestId('devices-section')).toBeFalsy();
7279
});
80+
81+
it('does not render qr code login section when disabled', () => {
82+
settingsValueSpy.mockReturnValue(false);
83+
const { queryByText } = render(getComponent());
84+
85+
expect(settingsValueSpy).toHaveBeenCalledWith('feature_qr_signin_reciprocate_show');
86+
87+
expect(queryByText('Sign in with QR code')).toBeFalsy();
88+
});
89+
90+
it('renders qr code login section when enabled', async () => {
91+
settingsValueSpy.mockImplementation(settingName => settingName === 'feature_qr_signin_reciprocate_show');
92+
const { getByText } = render(getComponent());
93+
94+
// wait for versions call to settle
95+
await flushPromises();
96+
97+
expect(getByText('Sign in with QR code')).toBeTruthy();
98+
});
99+
100+
it('enters qr code login section when show QR code button clicked', async () => {
101+
settingsValueSpy.mockImplementation(settingName => settingName === 'feature_qr_signin_reciprocate_show');
102+
const { getByText, getByTestId } = render(getComponent());
103+
// wait for versions call to settle
104+
await flushPromises();
105+
106+
fireEvent.click(getByText('Show QR code'));
107+
108+
expect(getByTestId("login-with-qr")).toBeTruthy();
109+
});
73110
});

test/components/views/settings/tabs/user/SessionManagerTab-test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
import SessionManagerTab from '../../../../../../src/components/views/settings/tabs/user/SessionManagerTab';
3535
import MatrixClientContext from '../../../../../../src/contexts/MatrixClientContext';
3636
import {
37+
flushPromises,
3738
flushPromisesWithFakeTimers,
3839
getMockClientWithEventEmitter,
3940
mkPusher,
@@ -47,6 +48,7 @@ import {
4748
ExtendedDevice,
4849
} from '../../../../../../src/components/views/settings/devices/types';
4950
import { INACTIVE_DEVICE_AGE_MS } from '../../../../../../src/components/views/settings/devices/filter';
51+
import SettingsStore from '../../../../../../src/settings/SettingsStore';
5052

5153
mockPlatformPeg();
5254

@@ -1142,4 +1144,50 @@ describe('<SessionManagerTab />', () => {
11421144

11431145
expect(checkbox.getAttribute('aria-checked')).toEqual("false");
11441146
});
1147+
1148+
describe('QR code login', () => {
1149+
const settingsValueSpy = jest.spyOn(SettingsStore, 'getValue');
1150+
1151+
beforeEach(() => {
1152+
settingsValueSpy.mockClear().mockReturnValue(false);
1153+
// enable server support for qr login
1154+
mockClient.getVersions.mockResolvedValue({
1155+
versions: [],
1156+
unstable_features: {
1157+
'org.matrix.msc3882': true,
1158+
'org.matrix.msc3886': true,
1159+
},
1160+
});
1161+
});
1162+
1163+
it('does not render qr code login section when disabled', () => {
1164+
settingsValueSpy.mockReturnValue(false);
1165+
const { queryByText } = render(getComponent());
1166+
1167+
expect(settingsValueSpy).toHaveBeenCalledWith('feature_qr_signin_reciprocate_show');
1168+
1169+
expect(queryByText('Sign in with QR code')).toBeFalsy();
1170+
});
1171+
1172+
it('renders qr code login section when enabled', async () => {
1173+
settingsValueSpy.mockImplementation(settingName => settingName === 'feature_qr_signin_reciprocate_show');
1174+
const { getByText } = render(getComponent());
1175+
1176+
// wait for versions call to settle
1177+
await flushPromises();
1178+
1179+
expect(getByText('Sign in with QR code')).toBeTruthy();
1180+
});
1181+
1182+
it('enters qr code login section when show QR code button clicked', async () => {
1183+
settingsValueSpy.mockImplementation(settingName => settingName === 'feature_qr_signin_reciprocate_show');
1184+
const { getByText, getByTestId } = render(getComponent());
1185+
// wait for versions call to settle
1186+
await flushPromises();
1187+
1188+
fireEvent.click(getByText('Show QR code'));
1189+
1190+
expect(getByTestId("login-with-qr")).toBeTruthy();
1191+
});
1192+
});
11451193
});

0 commit comments

Comments
 (0)