salix/e2e/paths/01-salix/05_changePassword.spec.js

76 lines
2.5 KiB
JavaScript

import getBrowser from '../../helpers/puppeteer';
const $ = {
form: 'vn-out-layout form'
};
fdescribe('ChangePassword path', async() => {
let browser;
let page;
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
});
afterAll(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');
// Bad attempt: incorrect current password
await saveExpets(await page.sendForm($.form, {
oldPassword: newPassword,
newPassword: oldPassword,
repeatPassword: oldPassword
}), 'Invalid current password');
// Bad attempt: password not meet requirements
await saveExpets(await page.sendForm($.form, {
oldPassword: oldPassword,
newPassword: oldPassword,
repeatPassword: oldPassword
}), 'Password does not meet requirements');
// Correct attempt: change password
await saveExpets(await page.sendForm($.form, {
oldPassword: oldPassword,
newPassword: newPassword,
repeatPassword: newPassword
}), 'Password updated!', 'login');
// Bad login, old password
await saveExpets(await page.doLogin(
'Maintenance',
oldPassword
), 'Invalid login');
// Correct login, new password
await saveExpets(await page.doLogin(
'Maintenance',
newPassword
), null, 'login');
for (let toExpect of toExpects)
expect(toExpect.value).toContain(toExpect.expected); // eslint-disable-line
});
});
});