forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update text, add tests (mattermost#29485)
Co-authored-by: Mattermost Build <[email protected]>
- Loading branch information
1 parent
a906e98
commit 2c52f09
Showing
4 changed files
with
171 additions
and
31 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
webapp/channels/src/components/mfa/setup/__snapshots__/setup.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`components/mfa/setup should match snapshot without required text 1`] = ` | ||
<div> | ||
<form | ||
className="form-group" | ||
onSubmit={[Function]} | ||
> | ||
<p> | ||
<MemoizedFormattedMessage | ||
defaultMessage="1. Scan the QR code below using an authenticator app of your choice, such as Google Authenticator, Microsoft Authenticator app, or 1Password." | ||
id="mfa.setup.step1" | ||
/> | ||
</p> | ||
<p> | ||
<MemoizedFormattedMessage | ||
defaultMessage="Alternatively, enter the secret key displayed below into the authenticator app manually." | ||
id="mfa.setup.step2_secret" | ||
/> | ||
</p> | ||
<div | ||
className="form-group" | ||
> | ||
<div | ||
className="col-sm-12" | ||
> | ||
<img | ||
alt="qr code image" | ||
src="data:image/png;base64," | ||
style={ | ||
Object { | ||
"maxHeight": 170, | ||
} | ||
} | ||
/> | ||
</div> | ||
</div> | ||
<br /> | ||
<div | ||
className="form-group" | ||
> | ||
<p | ||
className="col-sm-12" | ||
> | ||
<MemoizedFormattedMessage | ||
defaultMessage="Secret: {secret}" | ||
id="mfa.setup.secret" | ||
values={ | ||
Object { | ||
"secret": "", | ||
} | ||
} | ||
/> | ||
</p> | ||
</div> | ||
<p> | ||
<MemoizedFormattedMessage | ||
defaultMessage="2. Enter the code generated by the authenticator app in the field below." | ||
id="mfa.setup.step3_code" | ||
values={ | ||
Object { | ||
"strong": [Function], | ||
} | ||
} | ||
/> | ||
</p> | ||
<p> | ||
<LocalizedPlaceholderInput | ||
autoFocus={true} | ||
className="form-control" | ||
placeholder={ | ||
Object { | ||
"defaultMessage": "MFA Code", | ||
"id": "mfa.setup.code", | ||
} | ||
} | ||
/> | ||
</p> | ||
<button | ||
className="btn btn-primary" | ||
type="submit" | ||
> | ||
<MemoizedFormattedMessage | ||
defaultMessage="Save" | ||
id="mfa.setup.save" | ||
/> | ||
</button> | ||
</form> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Setup>( | ||
<Setup {...baseProps}/>, | ||
); | ||
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<Setup>( | ||
<Setup {...props}/>, | ||
); | ||
const requiredText = wrapper.find('#mfa.setup.required_mfa'); | ||
expect(requiredText).toBeDefined(); | ||
}); | ||
|
||
test('should set state after calling component did mount', async () => { | ||
const wrapper = shallow<Setup>( | ||
<Setup {...baseProps}/>, | ||
); | ||
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( | ||
<Setup {...baseProps}/>, | ||
); | ||
|
||
(wrapper.instance() as Setup).input.current!.value = 'testcodeinput'; | ||
wrapper.find('form').simulate('submit', {preventDefault: () => {}}); | ||
expect(baseProps.actions.activateMfa).toBeCalledWith('testcodeinput'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters