forked from Ivasoft/mattermost-mobile
MM_36205 : SSO Tests [ IN PROGRESS ]
This commit is contained in:
@@ -19,9 +19,9 @@ import SSOWithWebView from './sso_with_webview';
|
||||
|
||||
interface SSOProps {
|
||||
ssoType: string;
|
||||
config: ClientConfig;
|
||||
license: ClientLicense;
|
||||
theme: Theme;
|
||||
config: Partial<ClientConfig>;
|
||||
license: Partial<ClientLicense>;
|
||||
theme: Partial<Theme>;
|
||||
serverUrl: string;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => {
|
||||
await scheduleExpiredNotification(intl);
|
||||
};
|
||||
|
||||
const isSSOWithRedirectURLAvailable = isMinimumServerVersion(config.Version, 5, 33, 0);
|
||||
const isSSOWithRedirectURLAvailable = isMinimumServerVersion(config.Version!, 5, 33, 0);
|
||||
|
||||
const props = {
|
||||
intl,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Preferences} from '@constants';
|
||||
import React from 'react';
|
||||
import {Linking} from 'react-native';
|
||||
|
||||
import {renderWithReduxIntl} from 'test/testing_library';
|
||||
import configureStore from 'test/test_store';
|
||||
import {renderWithIntl} from '@test/intl-test-helper';
|
||||
|
||||
import SSOComponent from './index';
|
||||
|
||||
@@ -15,36 +15,21 @@ describe('SSO', () => {
|
||||
license: {
|
||||
IsLicensed: 'true',
|
||||
},
|
||||
ssoType: '',
|
||||
theme: Preferences.THEMES.default,
|
||||
serverUrl: '',
|
||||
};
|
||||
|
||||
test('implement with webview when version is less than 5.32 version', async () => {
|
||||
const store = await configureStore({
|
||||
entities: {
|
||||
general: {
|
||||
config: {
|
||||
Version: '5.30.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const basicWrapper = renderWithReduxIntl(<SSOComponent {...baseProps}/>, store);
|
||||
expect(basicWrapper.queryByTestId('sso.webview')).toBeTruthy();
|
||||
expect(basicWrapper.queryByTestId('sso.redirect_url')).toBeFalsy();
|
||||
const {getByTestId} = renderWithIntl(<SSOComponent {...baseProps}/>);
|
||||
expect(getByTestId('sso.webview')).toBeTruthy();
|
||||
expect(getByTestId('sso.redirect_url')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('implement with OS browser & redirect url from version 5.33', async () => {
|
||||
(Linking.openURL as jest.Mock).mockResolvedValueOnce('');
|
||||
const store = await configureStore({
|
||||
entities: {
|
||||
general: {
|
||||
config: {
|
||||
Version: '5.33.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const basicWrapper = renderWithReduxIntl(<SSOComponent {...baseProps}/>, store);
|
||||
expect(basicWrapper.queryByTestId('sso.webview')).toBeFalsy();
|
||||
expect(basicWrapper.queryByTestId('sso.redirect_url')).toBeTruthy();
|
||||
const {getByTestId} = renderWithIntl(<SSOComponent {...baseProps}/>);
|
||||
expect(getByTestId('sso.webview')).toBeFalsy();
|
||||
expect(getByTestId('sso.redirect_url')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
import {shallow} from 'enzyme';
|
||||
|
||||
import Preferences from '@mm-redux/constants/preferences';
|
||||
import FormattedText from 'app/components/formatted_text';
|
||||
import Preferences from '@constants/preferences';
|
||||
import {renderWithIntl} from '@test/intl-test-helper';
|
||||
|
||||
import SSOWithRedirectURL from './sso_with_redirect_url';
|
||||
|
||||
@@ -22,20 +21,23 @@ describe('SSO with redirect url', () => {
|
||||
};
|
||||
|
||||
test('should show message when user navigates to the page', () => {
|
||||
const wrapperWithBaseProps = shallow(<SSOWithRedirectURL {...baseProps}/>);
|
||||
expect(wrapperWithBaseProps.find(FormattedText).find({id: 'mobile.oauth.switch_to_browser'}).exists()).toBe(true);
|
||||
const {getByTestId} = renderWithIntl(<SSOWithRedirectURL {...baseProps}/>);
|
||||
expect(getByTestId('mobile.oauth.switch_to_browser')).toBe(true);
|
||||
});
|
||||
|
||||
test('should show "try again" and hide default message when error text is displayed', () => {
|
||||
const wrapperWithBaseProps = shallow(<SSOWithRedirectURL {...baseProps}/>);
|
||||
expect(wrapperWithBaseProps.find(FormattedText).find({id: 'mobile.oauth.try_again'}).exists()).toBe(false);
|
||||
const wrapper = shallow(
|
||||
const {getByTestId} = renderWithIntl(<SSOWithRedirectURL {...baseProps}/>);
|
||||
expect(getByTestId('mobile.oauth.try_again')).toBe(false);
|
||||
});
|
||||
|
||||
test('should show "try again" and hide default message when error text is displayed', () => {
|
||||
const {getByTestId} = renderWithIntl(
|
||||
<SSOWithRedirectURL
|
||||
{...baseProps}
|
||||
loginError='some error'
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find(FormattedText).find({id: 'mobile.oauth.try_again'}).exists()).toBe(true);
|
||||
expect(wrapper.find(FormattedText).find({id: 'mobile.oauth.switch_to_browser'}).exists()).toBe(false);
|
||||
expect(getByTestId('mobile.oauth.try_again')).toBe(true);
|
||||
expect(getByTestId('mobile.oauth.switch_to_browser')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import React from 'react';
|
||||
import {IntlShape} from 'react-intl';
|
||||
import {useIntl} from 'react-intl';
|
||||
import {Linking, Platform, Text, TouchableOpacity, View} from 'react-native';
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
import {SafeAreaView} from 'react-native-safe-area-context';
|
||||
@@ -15,19 +15,18 @@ import {tryOpenURL} from '@utils/url';
|
||||
import {setDeepLinkUrl} from '@requests/local/systems';
|
||||
|
||||
interface SSOWithRedirectURLProps {
|
||||
intl: IntlShape;
|
||||
loginError: string;
|
||||
loginUrl: string;
|
||||
onCSRFToken: (token: string) => void;
|
||||
onMMToken: (token: string) => void;
|
||||
setLoginError: (value: string) => void;
|
||||
theme: Theme
|
||||
theme: Partial<Theme>
|
||||
}
|
||||
|
||||
function SSOWithRedirectURL({intl, loginError, loginUrl, onCSRFToken, onMMToken, setLoginError, theme}: SSOWithRedirectURLProps) {
|
||||
function SSOWithRedirectURL({loginError, loginUrl, onCSRFToken, onMMToken, setLoginError, theme}: SSOWithRedirectURLProps) {
|
||||
const [error, setError] = React.useState<string>('');
|
||||
const style = getStyleSheet(theme);
|
||||
|
||||
const intl = useIntl();
|
||||
let customUrlScheme = 'mmauth://';
|
||||
if (DeviceInfo.getBundleId && DeviceInfo.getBundleId().includes('rnbeta')) {
|
||||
customUrlScheme = 'mmauthbeta://';
|
||||
@@ -118,12 +117,14 @@ function SSOWithRedirectURL({intl, loginError, loginUrl, onCSRFToken, onMMToken,
|
||||
<View style={style.infoContainer}>
|
||||
<FormattedText
|
||||
id='mobile.oauth.switch_to_browser'
|
||||
testID='mobile.oauth.switch_to_browser'
|
||||
defaultMessage='Please use your browser to complete the login'
|
||||
style={style.infoText}
|
||||
/>
|
||||
<TouchableOpacity onPress={() => init()}>
|
||||
<FormattedText
|
||||
id='mobile.oauth.restart_login'
|
||||
testID='mobile.oauth.restart_login'
|
||||
defaultMessage='Restart login'
|
||||
style={style.button}
|
||||
/>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import CookieManager, {Cookies} from '@react-native-community/cookies';
|
||||
import React from 'react';
|
||||
import {IntlShape} from 'react-intl';
|
||||
import {IntlShape, useIntl} from 'react-intl';
|
||||
import {Alert, Text, View} from 'react-native';
|
||||
import {SafeAreaView} from 'react-native-safe-area-context';
|
||||
import {WebView} from 'react-native-webview';
|
||||
@@ -60,28 +60,27 @@ const oneLoginFormScalingJS = `
|
||||
|
||||
interface SSOWithWebViewProps {
|
||||
completeUrlPath: string;
|
||||
intl: IntlShape;
|
||||
loginError: string;
|
||||
loginUrl: string;
|
||||
onCSRFToken: (token: string) => void;
|
||||
onMMToken: (token: string) => void;
|
||||
serverUrl: string;
|
||||
ssoType: string;
|
||||
theme: Theme
|
||||
theme: Partial<Theme>
|
||||
}
|
||||
|
||||
type CookieResponseType = {
|
||||
MMAUTHTOKEN: string | {
|
||||
value: string
|
||||
};
|
||||
MMCSRF: string | {
|
||||
value: string
|
||||
};
|
||||
}
|
||||
// type CookieResponseType = {
|
||||
// MMAUTHTOKEN: string | {
|
||||
// value: string
|
||||
// };
|
||||
// MMCSRF: string | {
|
||||
// value: string
|
||||
// };
|
||||
// }
|
||||
|
||||
function SSOWithWebView({completeUrlPath, intl, loginError, loginUrl, onCSRFToken, onMMToken, serverUrl, ssoType, theme}: SSOWithWebViewProps) {
|
||||
function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onMMToken, serverUrl, ssoType, theme}: SSOWithWebViewProps) {
|
||||
const style = getStyleSheet(theme);
|
||||
|
||||
const intl = useIntl();
|
||||
const [error, setError] = React.useState(null);
|
||||
const [jsCode, setJSCode] = React.useState('');
|
||||
const [messagingEnabled, setMessagingEnabled] = React.useState(false);
|
||||
|
||||
@@ -21,6 +21,7 @@ global.window = {};
|
||||
|
||||
jest.doMock('react-native', () => {
|
||||
const {
|
||||
Appearance,
|
||||
Platform,
|
||||
StyleSheet,
|
||||
ViewPropTypes,
|
||||
@@ -86,6 +87,9 @@ jest.doMock('react-native', () => {
|
||||
setupLibrary: jest.fn(),
|
||||
setStringAsync: jest.fn(),
|
||||
},
|
||||
Appearance: {
|
||||
getColorScheme: jest.fn().mockReturnValue('light'),
|
||||
},
|
||||
};
|
||||
|
||||
const Linking = {
|
||||
|
||||
Reference in New Issue
Block a user