Skip to content

Commit ec5f330

Browse files
committed
test: fix integration tests
1 parent 69a07a8 commit ec5f330

File tree

5 files changed

+70
-51
lines changed

5 files changed

+70
-51
lines changed

ts/components/dialog/SessionPasswordDialog.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
4242
}
4343

4444
public componentDidMount() {
45+
document.addEventListener('keyup', this.onEnterPressed);
46+
4547
setTimeout(() => {
4648
// tslint:disable-next-line: no-unused-expression
4749
this.passportInput && this.passportInput.focus();
4850
}, 1);
4951
}
5052

53+
public componentWillUnmount() {
54+
document.removeEventListener('keyup', this.onEnterPressed);
55+
}
56+
5157
public render() {
5258
const { passwordAction } = this.props;
5359
let placeholders: Array<string> = [];
@@ -93,15 +99,17 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
9399
this.passportInput = input;
94100
}}
95101
placeholder={placeholders[0]}
96-
onKeyUp={this.onPasswordInput}
102+
onChange={this.onPasswordInput}
103+
onPaste={this.onPasswordInput}
97104
data-testid="password-input"
98105
/>
99106
{passwordAction !== 'enter' && passwordAction !== 'remove' && (
100107
<input
101108
type="password"
102109
id="password-modal-input-confirm"
103110
placeholder={placeholders[1]}
104-
onKeyUp={this.onPasswordConfirmInput}
111+
onChange={this.onPasswordConfirmInput}
112+
onPaste={this.onPasswordConfirmInput}
105113
data-testid="password-input-confirm"
106114
/>
107115
)}
@@ -110,7 +118,8 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
110118
type="password"
111119
id="password-modal-input-reconfirm"
112120
placeholder={placeholders[2]}
113-
onKeyUp={this.onPasswordRetypeInput}
121+
onPaste={this.onPasswordRetypeInput}
122+
onChange={this.onPasswordRetypeInput}
114123
data-testid="password-input-reconfirm"
115124
/>
116125
)}
@@ -258,6 +267,13 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
258267
this.closeDialog();
259268
}
260269

270+
private async onEnterPressed(event: any) {
271+
if (event.key === 'Enter') {
272+
event.stopPropagation();
273+
return this.setPassword();
274+
}
275+
}
276+
261277
private async handleActionEnter(enteredPassword: string) {
262278
// be sure the password is valid
263279
if (!this.validatePassword(enteredPassword)) {
@@ -321,30 +337,18 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
321337
window.inboxStore?.dispatch(sessionPassword(null));
322338
}
323339

324-
private async onPasswordInput(event: any) {
325-
if (event.key === 'Enter') {
326-
return this.setPassword();
327-
}
340+
private onPasswordInput(event: any) {
328341
const currentPasswordEntered = event.target.value;
329-
330342
this.setState({ currentPasswordEntered });
331343
}
332344

333-
private async onPasswordConfirmInput(event: any) {
334-
if (event.key === 'Enter') {
335-
return this.setPassword();
336-
}
345+
private onPasswordConfirmInput(event: any) {
337346
const currentPasswordConfirmEntered = event.target.value;
338-
339347
this.setState({ currentPasswordConfirmEntered });
340348
}
341349

342-
private async onPasswordRetypeInput(event: any) {
343-
if (event.key === 'Enter') {
344-
return this.setPassword();
345-
}
350+
private onPasswordRetypeInput(event: any) {
346351
const currentPasswordRetypeEntered = event.target.value;
347-
348352
this.setState({ currentPasswordRetypeEntered });
349353
}
350354
}

ts/components/settings/section/CategoryPrivacy.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const SettingsCategoryPrivacy = (props: {
9797
displayPasswordModal('change', props.onPasswordUpdated);
9898
}}
9999
buttonText={window.i18n('changePassword')}
100+
dataTestId="change-password-settings-button"
100101
/>
101102
)}
102103
{props.hasPassword && (
@@ -108,6 +109,7 @@ export const SettingsCategoryPrivacy = (props: {
108109
}}
109110
buttonColor={SessionButtonColor.Danger}
110111
buttonText={window.i18n('removePassword')}
112+
dataTestId="remove-password-settings-button"
111113
/>
112114
)}
113115
</>

ts/test/automation/disappearing_messages.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
waitForReadableMessageWithText,
1111
waitForTestIdWithText,
1212
} from './utils';
13+
import { sleepFor } from '../../session/utils/Promise';
1314

1415
let windows: Array<Page> = [];
1516
test.beforeEach(beforeAllClean);
@@ -50,7 +51,9 @@ test('Disappearing Messages', async () => {
5051
'readable-message',
5152
'You set the disappearing message timer to 5 seconds'
5253
);
54+
await sleepFor(2000);
5355
// Check top right hand corner indicator
56+
5457
await waitForTestIdWithText(windowA, 'disappearing-messages-indicator', '5 seconds');
5558
// Send message
5659
// Wait for tick of confirmation
@@ -87,7 +90,7 @@ test('Disappearing Messages', async () => {
8790
`${userA.userName} set the disappearing message timer to 5 seconds`
8891
);
8992
// Wait 5 seconds
90-
await waitForMatchingText(windowB, `${userA.userName} disabled disappearing messages`);
93+
await waitForMatchingText(windowB, `${userA.userName} has turned off disappearing messages.`);
9194
// verify message is deleted in windowB
9295
const errorDesc2 = 'Should not be found';
9396
try {

ts/test/automation/password.spec.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { _electron, Page, test } from '@playwright/test';
2+
import { sleepFor } from '../../session/utils/Promise';
23
import { beforeAllClean, forceCloseAllWindows } from './setup/beforeEach';
34
import { newUser } from './setup/new_user';
45
import { openAppAndWait } from './setup/open';
@@ -36,42 +37,40 @@ test.describe('Password checks', () => {
3637
await clickOnTestIdWithText(window, 'set-password-button');
3738
// Enter password
3839
await typeIntoInput(window, 'password-input', testPassword);
39-
await window.keyboard.press('Delete');
4040
// Confirm password
4141
await typeIntoInput(window, 'password-input-confirm', testPassword);
42-
await window.keyboard.press('Delete');
43-
// Click OK
44-
await clickOnMatchingText(window, 'OK');
45-
// await window.keyboard.press('Enter');
42+
// Click Done
43+
await clickOnMatchingText(window, 'Done');
4644
// Check toast notification
4745
await waitForTestIdWithText(
4846
window,
4947
'session-toast',
50-
'Your password has been set. Please keep it safe'
48+
'Your password has been set. Please keep it safe.'
5149
);
50+
// Click on settings tab
51+
await sleepFor(300);
52+
await clickOnTestIdWithText(window, 'settings-section');
5253
// Type password into input field
5354

5455
await typeIntoInput(window, 'password-input', testPassword);
55-
// Click OK
56-
await clickOnMatchingText(window, 'OK');
56+
57+
// Click Done
58+
await clickOnMatchingText(window, 'Done');
59+
await clickOnTestIdWithText(window, 'settings-section');
60+
5761
// Change password
58-
await clickOnMatchingText(window, 'Change Password');
62+
await clickOnTestIdWithText(window, 'change-password-settings-button', 'Change Password');
63+
64+
console.warn('clicked Change Password');
5965
// Enter old password
6066
await typeIntoInput(window, 'password-input', testPassword);
61-
await window.keyboard.press('Delete');
6267
// Enter new password
6368
await typeIntoInput(window, 'password-input-confirm', newTestPassword);
64-
await window.keyboard.press('Delete');
65-
// await window.fill('#password-modal-input-confirm', newTestPassword);
6669
await window.keyboard.press('Tab');
6770
// Confirm new password
6871
await typeIntoInput(window, 'password-input-reconfirm', newTestPassword);
69-
await window.keyboard.press('Delete');
70-
// await window.fill('#password-modal-input-reconfirm', newTestPassword);
7172
// Press enter on keyboard
7273
await window.keyboard.press('Enter');
73-
// Select OK
74-
await clickOnMatchingText(window, 'OK');
7574
// Check toast notification for 'changed password'
7675
await waitForTestIdWithText(
7776
window,
@@ -92,36 +91,44 @@ test.describe('Password checks', () => {
9291
await clickOnMatchingText(window, 'Set Password');
9392
// Enter password
9493
await typeIntoInput(window, 'password-input', testPassword);
95-
await window.keyboard.press('Delete');
9694
// Confirm password
9795
await typeIntoInput(window, 'password-input-confirm', testPassword);
98-
await window.keyboard.press('Delete');
99-
// Click OK
96+
// Click Done
10097
await window.keyboard.press('Enter');
98+
// // Click on settings tab
99+
await sleepFor(100);
100+
await clickOnTestIdWithText(window, 'settings-section');
101+
101102
// Type password into input field
103+
await sleepFor(100);
102104
await typeIntoInput(window, 'password-input', testPassword);
103-
await window.keyboard.press('Delete');
104-
// Click OK
105-
await clickOnMatchingText(window, 'OK');
106-
// Navigate away from settings tab
105+
// Click Done
106+
await clickOnMatchingText(window, 'Done');
107+
await sleepFor(100);
108+
await window.mouse.click(0, 0);
107109
await clickOnTestIdWithText(window, 'message-section');
110+
await sleepFor(100);
111+
108112
// // Click on settings tab
113+
await sleepFor(1000);
109114
await clickOnTestIdWithText(window, 'settings-section');
110115
// // Try with incorrect password
111-
await typeIntoInput(window, 'password-input', '0000');
112-
await window.keyboard.press('Delete');
116+
await typeIntoInput(window, 'password-input', '000000');
113117
// Confirm
114-
await clickOnMatchingText(window, 'OK');
118+
await clickOnMatchingText(window, 'Done');
115119
// // invalid password banner showing?
116120
await waitForMatchingText(window, 'Invalid password');
117121
// // Empty password
118122
// // Navigate away from settings tab
123+
await window.mouse.click(0, 0);
124+
await sleepFor(100);
119125
await clickOnTestIdWithText(window, 'message-section');
126+
await sleepFor(100);
120127
// // Click on settings tab
121128
await clickOnTestIdWithText(window, 'settings-section');
122129
// // No password entered
123-
await clickOnMatchingText(window, 'OK');
130+
await clickOnMatchingText(window, 'Done');
124131
// // Banner should ask for password to be entered
125-
await waitForMatchingText(window, 'Please enter your password');
132+
await waitForMatchingText(window, 'Enter password');
126133
});
127134
});

ts/test/automation/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ export async function waitForMatchingText(window: Page, text: string) {
2828
}
2929

3030
export async function clickOnMatchingText(window: Page, text: string, rightButton = false) {
31+
console.info(`clickOnMatchingText: "${text}"`);
3132
return window.click(`"${text}"`, rightButton ? { button: 'right' } : undefined);
3233
}
3334

3435
export async function clickOnTestIdWithText(window: Page, dataTestId: string, text?: string) {
35-
if (text) {
36-
return window.click(`css=[data-testid=${dataTestId}]:has-text("${text}")`);
37-
}
36+
console.info(`clickOnTestIdWithText with testId:${dataTestId} and text:${text ? text : 'none'}`);
37+
38+
const builtSelector = !text
39+
? `css=[data-testid=${dataTestId}]`
40+
: `css=[data-testid=${dataTestId}]:has-text("${text}")`;
3841

39-
const builtSelector = `css=[data-testid=${dataTestId}]`;
4042
await window.waitForSelector(builtSelector);
4143
return window.click(builtSelector);
4244
}
@@ -46,6 +48,7 @@ export function getMessageTextContentNow() {
4648
}
4749

4850
export async function typeIntoInput(window: Page, dataTestId: string, text: string) {
51+
console.info(`typeIntoInput testId: ${dataTestId} : "${text}"`);
4952
const builtSelector = `css=[data-testid=${dataTestId}]`;
5053
return window.fill(builtSelector, text);
5154
}

0 commit comments

Comments
 (0)