Skip to content

Commit

Permalink
tests: Refactor E2EE tests (#6052)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello authored Dec 16, 2024
1 parent 45cc93c commit ced38ba
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 362 deletions.
2 changes: 1 addition & 1 deletion app/lib/encryption/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class EncryptionRoom {
};

createRoomKey = async () => {
this.createNewRoomKey();
await this.createNewRoomKey();
await Services.e2eSetRoomKeyID(this.roomId, this.keyID);
await this.encryptKeyForOtherParticipants();
};
Expand Down
9 changes: 7 additions & 2 deletions app/views/E2EEToggleRoomView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const E2EEToggleRoomView = ({ navigation }: { navigation: any }) => {
const roomName = getRoomTitle(room);

return (
<SafeAreaView>
<SafeAreaView testID='e2ee-toggle-room-view'>
<StatusBar />
<List.Container>
<List.Section>
Expand All @@ -62,7 +62,12 @@ const E2EEToggleRoomView = ({ navigation }: { navigation: any }) => {
{isMissingRoomKey ? (
<List.Section>
<List.Separator />
<List.Item title='Reset_encryption_keys' color={colors.fontDanger} onPress={() => resetRoomKey(rid)} />
<List.Item
title='Reset_encryption_keys'
color={colors.fontDanger}
onPress={() => resetRoomKey(rid)}
testID='e2ee-toggle-room-reset-key'
/>
<List.Separator />
<List.Info
info={I18n.t('Reset_encryption_keys_info__room_type__', { room_type: roomType.toLowerCase() })}
Expand Down
20 changes: 16 additions & 4 deletions app/views/RoomView/RightButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
}

async componentDidMount() {
const { tmid, rid } = this.props;
const { tmid, rid, hasE2EEWarning } = this.props;
const db = database.active;
if (tmid) {
try {
Expand All @@ -97,7 +97,9 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
console.log("Can't find subscription to observe.");
}
}
this.setCanToggleEncryption();
if (hasE2EEWarning) {
this.setCanToggleEncryption();
}
}

shouldComponentUpdate(nextProps: IRightButtonsProps, nextState: IRigthButtonsState) {
Expand Down Expand Up @@ -160,7 +162,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS

componentDidUpdate(prevProps: Readonly<IRightButtonsProps>): void {
const { toggleRoomE2EEncryptionPermission } = this.props;
if (prevProps.toggleRoomE2EEncryptionPermission !== toggleRoomE2EEncryptionPermission) {
if (!dequal(prevProps.toggleRoomE2EEncryptionPermission, toggleRoomE2EEncryptionPermission)) {
this.setCanToggleEncryption();
}
}
Expand Down Expand Up @@ -190,6 +192,11 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
const subObservable = subRecord.observe();
this.subSubscription = subObservable.subscribe(sub => {
this.updateSubscription(sub);

const { hasE2EEWarning } = this.props;
if (hasE2EEWarning) {
this.setCanToggleEncryption();
}
});
};

Expand Down Expand Up @@ -459,7 +466,12 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
return (
<HeaderButton.Container onLayout={this.onLayout}>
{hasE2EEWarning ? (
<HeaderButton.Item iconName='encrypted' onPress={this.goE2EEToggleRoomView} disabled={!canToggleEncryption} />
<HeaderButton.Item
iconName='encrypted'
onPress={this.goE2EEToggleRoomView}
disabled={!canToggleEncryption}
testID='room-view-header-encryption'
/>
) : null}
{issuesWithNotifications || notificationsDisabled ? (
<HeaderButton.Item
Expand Down
28 changes: 18 additions & 10 deletions e2e/helpers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,28 @@ async function searchRoom(
nativeElementAction: keyof Pick<Detox.NativeElementActions, 'typeText' | 'replaceText'> = 'typeText',
roomTestID?: string
) {
const testID = roomTestID || `rooms-list-view-item-${room}`;
await waitFor(element(by.id('rooms-list-view')))
.toExist()
.withTimeout(30000);
await tapAndWaitFor(element(by.id('rooms-list-view-search')), element(by.id('rooms-list-view-search-input')), 5000);
if (nativeElementAction === 'replaceText') {
// trigger the input's onChangeText
await element(by.id('rooms-list-view-search-input')).typeText(' ');

try {
await waitFor(element(by.id(testID)))
.toBeVisible()
.withTimeout(2000);
await expect(element(by.id(testID))).toBeVisible();
} catch {
await tapAndWaitFor(element(by.id('rooms-list-view-search')), element(by.id('rooms-list-view-search-input')), 5000);
if (nativeElementAction === 'replaceText') {
// trigger the input's onChangeText
await element(by.id('rooms-list-view-search-input')).typeText(' ');
}
await element(by.id('rooms-list-view-search-input'))[nativeElementAction](room);
await sleep(500);
await waitFor(element(by.id(testID)))
.toBeVisible()
.withTimeout(60000);
}
await element(by.id('rooms-list-view-search-input'))[nativeElementAction](room);
await sleep(500);
await sleep(500);
await waitFor(element(by.id(roomTestID || `rooms-list-view-item-${room}`)))
.toBeVisible()
.withTimeout(60000);
}

async function navigateToRoom(room: string) {
Expand Down
1 change: 1 addition & 0 deletions e2e/helpers/data_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const createRandomUser = async (customProps?: Object): Promise<ITestUser>
email: user.email,
...(customProps || {})
});
console.log(`Created ${user.username} / ${user.password}`);
return user;
} catch (error) {
console.log(JSON.stringify(error));
Expand Down
Loading

0 comments on commit ced38ba

Please sign in to comment.