refs #5489 refactor e2e
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-06-09 08:31:05 +02:00
parent 3e39564695
commit f797cc1761
1 changed files with 25 additions and 29 deletions

View File

@ -16,60 +16,56 @@ describe('ChangePassword path', async() => {
await browser.close();
});
const toExpects = [];
async function saveExpets(message, expectMessage, expectState) {
if (!message && expectMessage) message = await page.waitForSnackbar();
if (expectState)
toExpects.push({value: await page.getState(), expected: expectState});
if (expectMessage)
toExpects.push({value: message.text, expected: expectMessage});
}
const oldPassword = 'nightmare';
const newPassword = 'newPass.1234';
describe('Bad login', async() => {
it('should receive an error when the password is expired', async() => {
// Expired login
await saveExpets(await page.doLogin(
'Maintenance',
oldPassword
), 'The password has expired, change it from Salix', 'change-password');
await page.doLogin('Maintenance', oldPassword);
let message = await page.waitForSnackbar();
expect(message.text).toContain('The password has expired, change it from Salix');
expect(await page.getState()).toContain('change-password');
// Bad attempt: incorrect current password
await saveExpets(await page.sendForm($.form, {
message = await page.sendForm($.form, {
oldPassword: newPassword,
newPassword: oldPassword,
repeatPassword: oldPassword
}), 'Invalid current password');
});
expect(message.text).toContain('Invalid current password');
// Bad attempt: password not meet requirements
await saveExpets(await page.sendForm($.form, {
message = await page.sendForm($.form, {
oldPassword: oldPassword,
newPassword: oldPassword,
repeatPassword: oldPassword
}), 'Password does not meet requirements');
});
expect(message.text).toContain('Password does not meet requirements');
// Correct attempt: change password
await saveExpets(await page.sendForm($.form, {
message = await page.sendForm($.form, {
oldPassword: oldPassword,
newPassword: newPassword,
repeatPassword: newPassword
}), 'Password updated!', 'login');
});
expect(message.text).toContain('Password updated!');
expect(await page.getState()).toContain('login');
// Bad login, old password
await saveExpets(await page.doLogin(
'Maintenance',
oldPassword
), 'Invalid login');
await page.doLogin('Maintenance', oldPassword);
message = await page.waitForSnackbar();
expect(message.text).toContain('Invalid login');
// Correct login, new password
await saveExpets(await page.doLogin(
'Maintenance',
newPassword
), null, 'login');
await page.doLogin('Maintenance', newPassword);
await page.waitForSelector('vn-home');
for (let toExpect of toExpects)
expect(toExpect.value).toContain(toExpect.expected); // eslint-disable-line
expect(await page.getState()).toBe('home');
});
});
});