refactor e2e a async await

This commit is contained in:
Carlos Jimenez 2018-10-25 09:03:43 +02:00
parent 3bcca3b39d
commit 2a2ba7a9f0
2 changed files with 97 additions and 135 deletions

View File

@ -5,108 +5,92 @@ describe('Claim edit basic data path', () => {
const nightmare = createNightmare();
beforeAll(() => {
return nightmare
nightmare
.waitForLogin('salesAssistant');
});
it('should click on the Claims button of the top bar menu', done => {
return nightmare
it('should click on the Claims button of the top bar menu', async() => {
let url = await nightmare
.waitToClick(selectors.globalItems.applicationsMenuButton)
.wait(selectors.globalItems.applicationsMenuVisible)
.waitToClick(selectors.globalItems.claimsButton)
.wait(selectors.claimsIndex.searchClaimInput)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/claim/index');
done();
}).catch(done.fail);
.parsedUrl();
expect(url.hash).toEqual('#!/claim/index');
});
it('should search for the claim with id 1', done => {
return nightmare
it('should search for the claim with id 1', async() => {
let resultCount = await nightmare
.wait(selectors.claimsIndex.searchResult)
.type(selectors.claimsIndex.searchClaimInput, '1')
.click(selectors.claimsIndex.searchButton)
.waitForNumberOfElements(selectors.claimsIndex.searchResult, 1)
.countElement(selectors.claimsIndex.searchResult)
.then(result => {
expect(result).toEqual(1);
done();
}).catch(done.fail);
.countElement(selectors.claimsIndex.searchResult);
expect(resultCount).toEqual(1);
});
it(`should click on the search result to access to the claim Basic Data`, done => {
return nightmare
it(`should click on the search result to access to the claim Basic Data`, async() => {
let url = await nightmare
.waitToClick(selectors.claimsIndex.searchResult)
.waitToClick(selectors.claimBasicData.basicDataButton)
.waitForURL('basic-data')
.url()
.then(url => {
expect(url).toContain('basic-data');
done();
}).catch(done.fail);
.url();
expect(url).toContain('basic-data');
});
it(`should edit claim state, is paid with mana and observation fields`, done => {
return nightmare
it(`should edit claim state, is paid with mana and observation fields`, async() => {
let result = await nightmare
.waitToClick(selectors.claimBasicData.claimStateSelect)
.waitToClick(selectors.claimBasicData.claimStateSelectThirdOption)
.waitToClick(selectors.claimBasicData.isPaidWithManaCheckbox)
.clearInput(selectors.claimBasicData.observationInput)
.type(selectors.claimBasicData.observationInput, 'edited observation')
.click(selectors.claimBasicData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
done();
}).catch(done.fail);
.waitForSnackbar();
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
it('should confirm the claim state was edited', done => {
return nightmare
it('should confirm the claim state was edited', async() => {
let result = await nightmare
.click(selectors.claimDetails.detailsButton)
.wait(selectors.claimDetails.addItemButton)
.click(selectors.claimBasicData.basicDataButton)
.wait(selectors.claimBasicData.claimStateSelect)
.getInputValue(selectors.claimBasicData.claimStateSelect)
.then(result => {
expect(result).toEqual('Gestionado');
done();
}).catch(done.fail);
.getInputValue(selectors.claimBasicData.claimStateSelect);
expect(result).toEqual('Gestionado');
});
it('should confirm the Is paid with mana checkbox is checked', done => {
return nightmare
it('should confirm the Is paid with mana checkbox is checked', async() => {
let value = await nightmare
.evaluate(selector => {
return document.querySelector(selector).checked;
}, selectors.claimBasicData.isPaidWithManaCheckbox)
.then(value => {
expect(value).toBeTruthy();
done();
}).catch(done.fail);
}, selectors.claimBasicData.isPaidWithManaCheckbox);
expect(value).toBeTruthy();
});
it('should confirm the claim observation was edited', done => {
return nightmare
.getInputValue(selectors.claimBasicData.observationInput)
.then(result => {
expect(result).toEqual('edited observation');
done();
}).catch(done.fail);
it('should confirm the claim observation was edited', async() => {
let result = await nightmare
.getInputValue(selectors.claimBasicData.observationInput);
expect(result).toEqual('edited observation');
});
it(`should edit the claim to leave it untainted`, done => {
return nightmare
it(`should edit the claim to leave it untainted`, async() => {
let result = await nightmare
.waitToClick(selectors.claimBasicData.claimStateSelect)
.waitToClick(selectors.claimBasicData.claimStateSelectFourthOption)
.waitToClick(selectors.claimBasicData.isPaidWithManaCheckbox)
.clearInput(selectors.claimBasicData.observationInput)
.type(selectors.claimBasicData.observationInput, 'Observation one')
.click(selectors.claimBasicData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
done();
}).catch(done.fail);
.waitForSnackbar();
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors';
import createNightmare from '../../helpers/nightmare';
describe('Client', () => {
fdescribe('Client', () => {
describe('create path', () => {
let nightmare = createNightmare();
@ -10,138 +10,116 @@ describe('Client', () => {
.waitForLogin('employee');
});
it('should access to the clients index by clicking the clients button', done => {
return nightmare
it('should access to the clients index by clicking the clients button', async() => {
let url = await nightmare
.click(selectors.moduleAccessView.clientsSectionButton)
.wait(selectors.clientsIndex.createClientButton)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/client/index');
done();
}).catch(done.fail);
.parsedUrl();
expect(url.hash).toEqual('#!/client/index');
});
it(`should search for the user Carol Danvers to confirm it isn't created yet`, done => {
return nightmare
it(`should search for the user Carol Danvers to confirm it isn't created yet`, async() => {
let result = await nightmare
.wait(selectors.clientsIndex.searchResult)
.type(selectors.clientsIndex.searchClientInput, 'Carol Danvers')
.click(selectors.clientsIndex.searchButton)
.waitForNumberOfElements(selectors.clientsIndex.searchResult, 0)
.countElement(selectors.clientsIndex.searchResult)
.then(result => {
expect(result).toEqual(0);
done();
}).catch(done.fail);
.countElement(selectors.clientsIndex.searchResult);
expect(result).toEqual(0);
});
it('should access to the create client view by clicking the create-client floating button', done => {
return nightmare
it('should access to the create client view by clicking the create-client floating button', async() => {
let url = await nightmare
.click(selectors.clientsIndex.createClientButton)
.wait(selectors.createClientView.createButton)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/client/create');
done();
}).catch(done.fail);
.parsedUrl();
expect(url.hash).toEqual('#!/client/create');
});
it('should return to the client index by clicking the cancel button', done => {
return nightmare
it('should return to the client index by clicking the cancel button', async() => {
let url = await nightmare
.click(selectors.createClientView.cancelButton)
.wait(selectors.clientsIndex.createClientButton)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/client/index');
done();
}).catch(done.fail);
.parsedUrl();
expect(url.hash).toEqual('#!/client/index');
});
it('should now access to the create client view by clicking the create-client floating button', done => {
return nightmare
it('should now access to the create client view by clicking the create-client floating button', async() => {
let url = await nightmare
.click(selectors.clientsIndex.createClientButton)
.wait(selectors.createClientView.createButton)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/client/create');
done();
}).catch(done.fail);
.parsedUrl();
expect(url.hash).toEqual('#!/client/create');
});
it('should receive an error when clicking the create button having all the form fields empty', done => {
return nightmare
it('should receive an error when clicking the create button having all the form fields empty', async() => {
let result = await nightmare
.click(selectors.createClientView.createButton)
.waitForLastSnackbar()
.then(result => {
expect(result).toEqual('Some fields are invalid');
done();
}).catch(done.fail);
.waitForLastSnackbar();
expect(result).toEqual('Some fields are invalid');
});
it('should receive an error when clicking the create button having name and Business name fields empty', done => {
return nightmare
it('should receive an error when clicking the create button having name and Business name fields empty', async() => {
let result = await nightmare
.type(selectors.createClientView.taxNumber, '74451390E')
.type(selectors.createClientView.userName, 'CaptainMarvel')
.type(selectors.createClientView.email, 'CarolDanvers@verdnatura.es')
.waitToClick(selectors.createClientView.salesPersonInput)
.waitToClick(selectors.createClientView.salesBruceBannerOption)
.click(selectors.createClientView.createButton)
.waitForLastSnackbar()
.then(result => {
expect(result).toEqual('Some fields are invalid');
done();
}).catch(done.fail);
.waitForLastSnackbar();
expect(result).toEqual('Some fields are invalid');
});
it(`should attempt to create a new user with all it's data but wrong email`, done => {
return nightmare
it(`should attempt to create a new user with all it's data but wrong email`, async() => {
let result = await nightmare
.type(selectors.createClientView.name, 'Carol Danvers')
.type(selectors.createClientView.socialName, 'AVG tax')
.clearInput(selectors.createClientView.email)
.type(selectors.createClientView.email, 'incorrect email format')
.click(selectors.createClientView.createButton)
.waitForLastSnackbar()
.then(result => {
expect(result).toEqual('Some fields are invalid');
done();
}).catch(done.fail);
.waitForLastSnackbar();
expect(result).toEqual('Some fields are invalid');
});
it(`should create a new user with all correct data`, done => {
return nightmare
it(`should create a new user with all correct data`, async() => {
let result = await nightmare
.clearInput(selectors.createClientView.email)
.type(selectors.createClientView.email, 'caroldanvers@verdnatura.es')
.click(selectors.createClientView.createButton)
.waitForLastSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
done();
}).catch(done.fail);
.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
});
it('should click on the Clients button of the top bar menu', done => {
return nightmare
it('should click on the Clients button of the top bar menu', async() => {
let url = await nightmare
.waitToClick(selectors.globalItems.applicationsMenuButton)
.wait(selectors.globalItems.applicationsMenuVisible)
.waitToClick(selectors.globalItems.clientsButton)
.wait(selectors.clientsIndex.createClientButton)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/client/index');
done();
}).catch(done.fail);
.parsedUrl();
expect(url.hash).toEqual('#!/client/index');
});
it(`should search for the user Carol Danvers to confirm it exists`, done => {
return nightmare
it(`should search for the user Carol Danvers to confirm it exists`, async() => {
let result = await nightmare
.wait(selectors.clientsIndex.searchResult)
.type(selectors.clientsIndex.searchClientInput, 'Carol Danvers')
.click(selectors.clientsIndex.searchButton)
.waitForNumberOfElements(selectors.clientsIndex.searchResult, 1)
.countElement(selectors.clientsIndex.searchResult)
.then(result => {
expect(result).toEqual(1);
done();
}).catch(done.fail);
.countElement(selectors.clientsIndex.searchResult);
expect(result).toEqual(1);
});
});
});