From 2c52f090711fa525389b221fb541e2a0e39fce05 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Tue, 10 Dec 2024 08:06:05 -0700 Subject: [PATCH] update text, add tests (#29485) Co-authored-by: Mattermost Build --- .../setup/__snapshots__/setup.test.tsx.snap | 90 +++++++++++++++++++ .../src/components/mfa/setup/setup.test.tsx | 74 +++++++++++++++ .../src/components/mfa/setup/setup.tsx | 32 +------ webapp/channels/src/i18n/en.json | 6 +- 4 files changed, 171 insertions(+), 31 deletions(-) create mode 100644 webapp/channels/src/components/mfa/setup/__snapshots__/setup.test.tsx.snap create mode 100644 webapp/channels/src/components/mfa/setup/setup.test.tsx diff --git a/webapp/channels/src/components/mfa/setup/__snapshots__/setup.test.tsx.snap b/webapp/channels/src/components/mfa/setup/__snapshots__/setup.test.tsx.snap new file mode 100644 index 0000000000..8082324a6b --- /dev/null +++ b/webapp/channels/src/components/mfa/setup/__snapshots__/setup.test.tsx.snap @@ -0,0 +1,90 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/mfa/setup should match snapshot without required text 1`] = ` +
+
+

+ +

+

+ +

+
+
+ qr code image +
+
+
+
+

+ +

+
+

+ +

+

+ +

+ +
+
+`; diff --git a/webapp/channels/src/components/mfa/setup/setup.test.tsx b/webapp/channels/src/components/mfa/setup/setup.test.tsx new file mode 100644 index 0000000000..629429ad8a --- /dev/null +++ b/webapp/channels/src/components/mfa/setup/setup.test.tsx @@ -0,0 +1,74 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {shallow} from 'enzyme'; +import React from 'react'; + +import Setup from 'components/mfa/setup/setup'; + +import {mountWithIntl} from 'tests/helpers/intl-test-helper'; +import {TestHelper} from 'utils/test_helper'; + +jest.mock('actions/global_actions', () => ({ + redirectUserToDefaultTeam: jest.fn(), +})); + +describe('components/mfa/setup', () => { + const user = TestHelper.getUserMock(); + const generateMfaSecret = jest.fn().mockImplementation(() => Promise.resolve({data: {secret: 'generated secret', qr_code: 'qrcode'}})); + const activateMfa = jest.fn().mockImplementation(() => Promise.resolve({data: {}})); + const baseProps = { + state: {enforceMultifactorAuthentication: false}, + updateParent: jest.fn(), + currentUser: user, + siteName: 'test', + enforceMultifactorAuthentication: false, + actions: { + activateMfa, + generateMfaSecret, + }, + history: {push: jest.fn()}, + }; + + test('should match snapshot without required text', async () => { + const wrapper = shallow( + , + ); + expect(wrapper).toMatchSnapshot(); + const requiredText = wrapper.find('#mfa.setup.required_mfa'); + expect(requiredText).not.toBeFalsy(); + }); + + test('should match snapshot with required text', async () => { + const props = { + ...baseProps, + enforceMultifactorAuthentication: true, + }; + + const wrapper = shallow( + , + ); + const requiredText = wrapper.find('#mfa.setup.required_mfa'); + expect(requiredText).toBeDefined(); + }); + + test('should set state after calling component did mount', async () => { + const wrapper = shallow( + , + ); + expect(generateMfaSecret).toBeCalled(); + await wrapper.instance().componentDidMount(); + expect(wrapper.state('secret')).toEqual('generated secret'); + expect(wrapper.state('qrCode')).toEqual('qrcode'); + }); + + test('should call activateMfa on submission', async () => { + const wrapper = mountWithIntl( + , + ); + + (wrapper.instance() as Setup).input.current!.value = 'testcodeinput'; + wrapper.find('form').simulate('submit', {preventDefault: () => {}}); + expect(baseProps.actions.activateMfa).toBeCalledWith('testcodeinput'); + }); +}); diff --git a/webapp/channels/src/components/mfa/setup/setup.tsx b/webapp/channels/src/components/mfa/setup/setup.tsx index 5d209e8e91..3c2d068784 100644 --- a/webapp/channels/src/components/mfa/setup/setup.tsx +++ b/webapp/channels/src/components/mfa/setup/setup.tsx @@ -6,7 +6,6 @@ import {defineMessage, FormattedMessage} from 'react-intl'; import type {UserProfile} from '@mattermost/types/users'; -import ExternalLink from 'components/external_link'; import LocalizedPlaceholderInput from 'components/localized_placeholder_input'; type MFAControllerState = { @@ -58,7 +57,7 @@ type State = { } export default class Setup extends React.PureComponent { - private input: React.RefObject; + input: React.RefObject; public constructor(props: Props) { super(props); @@ -127,7 +126,6 @@ export default class Setup extends React.PureComponent { error: error.message, }); } - return; } @@ -169,35 +167,13 @@ export default class Setup extends React.PureComponent {

{msg}, - linkiTunes: (msg: React.ReactNode) => ( - - {msg} - - ), - linkGooglePlay: (msg: React.ReactNode) => ( - - {msg} - - ), - }} + defaultMessage='1. Scan the QR code below using an authenticator app of your choice, such as Google Authenticator, Microsoft Authenticator app, or 1Password.' />

{chunks}, - }} + defaultMessage='Alternatively, enter the secret key displayed below into the authenticator app manually.' />

@@ -224,7 +200,7 @@ export default class Setup extends React.PureComponent {

{chunks}, }} diff --git a/webapp/channels/src/i18n/en.json b/webapp/channels/src/i18n/en.json index 2638e4396c..cb5d551b46 100644 --- a/webapp/channels/src/i18n/en.json +++ b/webapp/channels/src/i18n/en.json @@ -4322,9 +4322,9 @@ "mfa.setup.required_mfa": "Multi-factor authentication is required on {siteName}.", "mfa.setup.save": "Save", "mfa.setup.secret": "Secret: {secret}", - "mfa.setup.step1": "Step 1: On your phone, download Google Authenticator from iTunes or Google Play", - "mfa.setup.step2_secret": "Step 2: Use Google Authenticator to scan this QR code, or manually type in the secret key.", - "mfa.setup.step3_code": "Step 3: Enter the code generated by Google Authenticator.", + "mfa.setup.step1": "1. Scan the QR code below using an authenticator app of your choice, such as Google Authenticator, Microsoft Authenticator app, or 1Password.", + "mfa.setup.step2_secret": "Alternatively, enter the secret key displayed below into the authenticator app manually.", + "mfa.setup.step3_code": "2. Enter the code generated by the authenticator app in the field below.", "mfa.setupTitle": "Multi-factor Authentication Setup", "mobile.set_status.away.icon": "Away Icon", "mobile.set_status.dnd.icon": "Do Not Disturb Icon",