diff --git a/src/__tests__/connection/enterprise/__snapshots__/hrd_screen.test.js.snap b/src/__tests__/connection/enterprise/__snapshots__/hrd_screen.test.js.snap new file mode 100644 index 000000000..4860eab9a --- /dev/null +++ b/src/__tests__/connection/enterprise/__snapshots__/hrd_screen.test.js.snap @@ -0,0 +1,59 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`HRDScreen Component renders correctly when there is an enterprise domain 1`] = ` +
+ Please enter your corporate credentials at [ 'domain.com' ]. +

+ } + data-i18n={ + Object { + "str": [Function], + } + } + data-model={ + Immutable.Map { + "id": "__lock-id__", + "i18n": Immutable.Map { + "strings": Immutable.Map { + "enterpriseLoginIntructions": "Login with your corporate credentials.", + "enterpriseActiveLoginInstructions": "Please enter your corporate credentials at %s.", + }, + }, + } + } + data-passwordInputPlaceholder=" []" + data-usernameInputPlaceholder=" []" +/> +`; + +exports[`HRDScreen Component renders correctly when there is no enterprise domain 1`] = ` +
+ Login with your corporate credentials. [] +

+ } + data-i18n={ + Object { + "str": [Function], + } + } + data-model={ + Immutable.Map { + "id": "__lock-id__", + "i18n": Immutable.Map { + "strings": Immutable.Map { + "enterpriseLoginIntructions": "Login with your corporate credentials.", + "enterpriseActiveLoginInstructions": "Please enter your corporate credentials at %s.", + }, + }, + } + } + data-passwordInputPlaceholder=" []" + data-usernameInputPlaceholder=" []" +/> +`; diff --git a/src/__tests__/connection/enterprise/hrd_screen.test.js b/src/__tests__/connection/enterprise/hrd_screen.test.js new file mode 100644 index 000000000..00c1ea18f --- /dev/null +++ b/src/__tests__/connection/enterprise/hrd_screen.test.js @@ -0,0 +1,52 @@ +import React from 'react'; +import { mockComponent, expectComponent } from 'testUtils'; +import I from 'immutable'; +import { dataFns } from '../../../utils/data_utils'; +import * as i18n from '../../../i18n'; + +const { set } = dataFns(['i18n']); + +jest.mock('engine/classic'); +jest.mock('connection/enterprise/hrd_pane', () => mockComponent('hrd_pane')); +jest.mock('connection/enterprise', () => ({ + enterpriseDomain: jest.fn(() => 'domain.com') +})); + +const getComponent = () => { + const HRDScreen = require('connection/enterprise/hrd_screen').default; + const screen = new HRDScreen(); + return screen.render(); +}; + +describe('HRDScreen Component', () => { + let i18nProp; + let lock; + + beforeEach(() => { + lock = I.fromJS({ id: '__lock-id__' }); + + jest.resetModules(); + + const lang = I.fromJS({ + enterpriseLoginIntructions: 'Login with your corporate credentials.', + enterpriseActiveLoginInstructions: 'Please enter your corporate credentials at %s.' + }); + + lock = set(lock, 'strings', lang); + + i18nProp = { + str: (keypath, ...args) => i18n.str(lock, keypath, args) + }; + }); + + it('renders correctly when there is an enterprise domain', () => { + const Component = getComponent(); + expectComponent().toMatchSnapshot(); + }); + + it('renders correctly when there is no enterprise domain', () => { + require('connection/enterprise').enterpriseDomain.mockImplementation(() => null); + const Component = getComponent(); + expectComponent().toMatchSnapshot(); + }); +}); diff --git a/src/__tests__/connection/passwordless/__snapshots__/ask_vcode.test.jsx.snap b/src/__tests__/connection/passwordless/__snapshots__/ask_vcode.test.jsx.snap new file mode 100644 index 000000000..ec8769f53 --- /dev/null +++ b/src/__tests__/connection/passwordless/__snapshots__/ask_vcode.test.jsx.snap @@ -0,0 +1,75 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AskVCode renders correctly when logging in with a phone number 1`] = ` +
+`; + +exports[`AskVCode renders correctly when logging in with email 1`] = ` +
+`; diff --git a/src/__tests__/connection/passwordless/ask_vcode.test.jsx b/src/__tests__/connection/passwordless/ask_vcode.test.jsx new file mode 100644 index 000000000..06e25c903 --- /dev/null +++ b/src/__tests__/connection/passwordless/ask_vcode.test.jsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { mockComponent } from 'testUtils'; +import I from 'immutable'; +import { setField } from '../../../field'; +import * as i18n from '../../../i18n'; +import { expectComponent } from '../../testUtils'; +import { dataFns } from '../../../utils/data_utils'; +import { setPhoneNumber, initLocation } from '../../../field/phone_number'; + +const { set } = dataFns(['i18n']); + +jest.mock('engine/classic'); +jest.mock('field/vcode/vcode_pane', () => mockComponent('vcode_pane')); +jest.mock('field/phone-number/locations', () => ({ + __esModule: true, + default: [['United Kingdom', 'UK', '+44']] +})); + +jest.mock('connection/passwordless/index', () => ({ + isEmail: jest.fn() +})); + +const getComponent = () => { + const VCodeScreen = require('connection/passwordless/ask_vcode').default; + const screen = new VCodeScreen(); + return screen.render(); +}; + +describe('AskVCode', () => { + let lock; + let i18nProp; + + beforeEach(() => { + lock = I.fromJS({ id: '__lock-id__' }); + + jest.resetModules(); + + const lang = I.fromJS({ + passwordlessEmailCodeInstructions: 'An email with the code has been sent to %s.', + passwordlessSMSCodeInstructions: 'An SMS with the code has been sent to %s.' + }); + + lock = set(lock, 'strings', lang); + + i18nProp = { + str: (keypath, ...args) => i18n.str(lock, keypath, args) + }; + }); + + it('renders correctly when logging in with email', () => { + require('connection/passwordless/index').isEmail.mockImplementation(() => true); + + const Component = getComponent(); + const l = setField(lock, 'email', 'test@user.com'); + + expectComponent().toMatchSnapshot(); + }); + + it('renders correctly when logging in with a phone number', () => { + require('connection/passwordless/index').isEmail.mockImplementation(() => false); + + const Component = getComponent(); + let l = setPhoneNumber(lock, '456 789'); + l = initLocation(l, 'UK'); + + expectComponent().toMatchSnapshot(); + }); +}); diff --git a/src/connection/enterprise/hrd_pane.jsx b/src/connection/enterprise/hrd_pane.jsx index 69c2c5ae9..9d69b9e95 100644 --- a/src/connection/enterprise/hrd_pane.jsx +++ b/src/connection/enterprise/hrd_pane.jsx @@ -24,7 +24,7 @@ export default class HRDPane extends React.Component { } HRDPane.propTypes = { - header: PropTypes.element, + header: PropTypes.string, i18n: PropTypes.object.isRequired, model: PropTypes.object.isRequired, passwordInputPlaceholder: PropTypes.string.isRequired, diff --git a/src/connection/enterprise/hrd_screen.jsx b/src/connection/enterprise/hrd_screen.jsx index 4b71e8c41..2eeb09b32 100644 --- a/src/connection/enterprise/hrd_screen.jsx +++ b/src/connection/enterprise/hrd_screen.jsx @@ -11,10 +11,10 @@ const Component = ({ i18n, model }) => { var headerText; - if (domain != null) { - headerText = i18n.html('enterpriseActiveLoginInstructions', domain); + if (domain !== null) { + headerText = i18n.str('enterpriseActiveLoginInstructions', domain); } else { - headerText = i18n.html('enterpriseLoginIntructions'); + headerText = i18n.str('enterpriseLoginIntructions'); } headerText = headerText || null; diff --git a/src/connection/passwordless/ask_vcode.jsx b/src/connection/passwordless/ask_vcode.jsx index ba88db67a..ebe178d3e 100644 --- a/src/connection/passwordless/ask_vcode.jsx +++ b/src/connection/passwordless/ask_vcode.jsx @@ -9,8 +9,8 @@ import { humanPhoneNumberWithDiallingCode } from '../../field/phone_number'; const Component = ({ i18n, model }) => { const instructions = isEmail(model) - ? i18n.html('passwordlessEmailCodeInstructions', getFieldValue(model, 'email')) - : i18n.html('passwordlessSMSCodeInstructions', humanPhoneNumberWithDiallingCode(model)); + ? i18n.str('passwordlessEmailCodeInstructions', getFieldValue(model, 'email')) + : i18n.str('passwordlessSMSCodeInstructions', humanPhoneNumberWithDiallingCode(model)); return ( or create an account', passwordlessSMSAlternativeInstructions: 'Otherwise, enter your phone to sign in
or create an account', - passwordlessSMSCodeInstructions: 'An SMS with the code has been sent
to %s.', + passwordlessSMSCodeInstructions: 'An SMS with the code has been sent to %s.', passwordlessSMSInstructions: 'Enter your phone to sign in
or create an account', phoneNumberInputPlaceholder: 'your phone number', resendCodeAction: 'Did not get the code?',