Skip to content

Commit

Permalink
test: add e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlsilva committed Jun 4, 2024
1 parent acd7c87 commit 990d339
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const FooterButtons = ({
confirmTitle = '',
disabled = false,
cancelBackgroundColor = '',
confirmBackgroundColor = ''
confirmBackgroundColor = '',
testID = ''
}): React.ReactElement => {
const { colors } = useTheme();
return (
Expand All @@ -55,12 +56,14 @@ const FooterButtons = ({
color={colors.backdropColor}
title={cancelTitle}
onPress={cancelAction}
testID={`${testID}-cancel`}
/>
<Button
style={{ flex: 1, backgroundColor: confirmBackgroundColor || colors.buttonBackgroundDangerDefault }}
title={confirmTitle}
onPress={confirmAction}
disabled={disabled}
testID={`${testID}-confirm`}
/>
</View>
);
Expand Down Expand Up @@ -96,7 +99,7 @@ const ActionSheetContentWithInputAndSubmit = ({
customText?: React.ReactElement;
confirmBackgroundColor?: string;
showInput?: boolean;
inputs?: { placeholder: string, secureTextEntry?: boolean }[];
inputs?: { placeholder: string; secureTextEntry?: boolean }[];
isDisabled?: (inputValues: string[]) => boolean;
}): React.ReactElement => {
const { colors } = useTheme();
Expand Down Expand Up @@ -130,7 +133,7 @@ const ActionSheetContentWithInputAndSubmit = ({
}
}}
inputRef={inputRefs.current[index] as any}
testID={`${testID}-${index}`}
testID={`${testID}-input-${index}`}
secureTextEntry={inputConfig.secureTextEntry}
bottomSheet={isIOS}
/>
Expand All @@ -148,7 +151,7 @@ const ActionSheetContentWithInputAndSubmit = ({
}, 100);
if (inputValues[0]) onSubmit(inputValues[0]);
}}
testID={testID}
testID={`${testID}-input`}
secureTextEntry={secureTextEntry}
bottomSheet={isIOS}
/>
Expand Down Expand Up @@ -176,6 +179,7 @@ const ActionSheetContentWithInputAndSubmit = ({
cancelTitle={i18n.t('Cancel')}
confirmTitle={confirmTitle || i18n.t('Save')}
disabled={disabled}
testID={testID}
/>
</View>
);
Expand Down
6 changes: 3 additions & 3 deletions app/containers/ChangePasswordRequired.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ChangePasswordRequired = () => {
testID='change-password-required-sheet'
inputs={inputs}
onSubmit={input => changePassword(input[0])}
isDisabled={input => loading || input[0] === '' || input[0] !== input[1]}
isDisabled={input => loading || input[0] === '' || requiresPasswordConfirmation ? input[0] !== input[1] : false}
/>
)
});
Expand All @@ -61,8 +61,8 @@ export const ChangePasswordRequired = () => {
</View>
<Text style={[styles.title, { color: colors.fontTitlesLabels }]}>{I18n.t('You_need_to_change_your_password')}</Text>
<Text style={[styles.description, { color: colors.fontDefault }]}>{I18n.t('To_continue_using_RocketChat')}</Text>
<Button title={I18n.t('Change_password')} type='primary' onPress={showActionSheetPassword} />
<Button title={I18n.t('Logout')} type='secondary' backgroundColor={colors.surfaceTint} onPress={() => dispatch(logout())} />
<Button testID='change-password-required-button' title={I18n.t('Change_password')} type='primary' onPress={showActionSheetPassword} />
<Button testID='change-password-required-logout' title={I18n.t('Logout')} type='secondary' backgroundColor={colors.surfaceTint} onPress={() => dispatch(logout())} />
</View>
);
};
Expand Down
3 changes: 3 additions & 0 deletions app/views/RoomsListView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
this.handleHasPermission();
this.setHeader();
}
if (prevProps.user.requirePasswordChange !== this.props.user.requirePasswordChange) {
this.setHeader();
}
}

componentWillUnmount() {
Expand Down
5 changes: 3 additions & 2 deletions e2e/helpers/data_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ITestUser {
email: string;
}

export const createRandomUser = async (): Promise<ITestUser> => {
export const createRandomUser = async (customProps?: Object): Promise<ITestUser> => {
try {
await login(data.adminUser, data.adminPassword);
const user = data.randomUser();
Expand All @@ -45,7 +45,8 @@ export const createRandomUser = async (): Promise<ITestUser> => {
username: user.username,
name: user.name,
password: user.password,
email: user.email
email: user.email,
...(customProps || {})
});
return user;
} catch (error) {
Expand Down
63 changes: 63 additions & 0 deletions e2e/tests/onboarding/08-change-password-required.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { by, device, element, waitFor } from 'detox';

import { login, logout, navigateToLogin } from '../../helpers/app';
import { createRandomUser } from '../../helpers/data_setup';

describe('Change password required', () => {
let user = { username: '', password: '' };

beforeAll(async () => {
user = await createRandomUser({ requirePasswordChange: true });
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin();
await login(user.username, user.password);
});

describe('Usage', () => {
it('should have required password info displayed', async () => {
await waitFor(element(by.id(`change-password-required-button`)))
.toExist()
.withTimeout(5000);
});

it('should logout correctly', async () => {
await waitFor(element(by.id(`change-password-required-logout`)))
.toExist()
.withTimeout(5000);
await element(by.id('change-password-required-logout')).tap();
await waitFor(element(by.id('new-server-view')))
.toExist()
.withTimeout(10000);
});

it('should change password correctly', async () => {
await navigateToLogin();
await login(user.username, user.password);
await waitFor(element(by.id(`change-password-required-button`)))
.toExist()
.withTimeout(5000);
await element(by.id('change-password-required-button')).tap();
await waitFor(element(by.id(`action-sheet-content-with-input-and-submit`)))
.toExist()
.withTimeout(5000);
await element(by.id('change-password-required-sheet-input-0')).replaceText('123456');
await element(by.id('change-password-required-sheet-input-1')).replaceText('123456');
await element(by.id('change-password-required-sheet-confirm')).tap();
await waitFor(element(by.id(`change-password-required-button`)))
.not.toExist()
.withTimeout(5000);
await waitFor(element(by.id('rooms-list-view-item-general')))
.toExist()
.withTimeout(10000);
await logout();
});

it('should login correctly after password change', async () => {
await navigateToLogin();
await login(user.username, '123456');
await waitFor(element(by.id('rooms-list-view-item-general')))
.toExist()
.withTimeout(10000);
});
});
});

0 comments on commit 990d339

Please sign in to comment.