From da68ab3ffc6feddba7b42059e5901587b5f2d342 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 21 Oct 2020 14:25:40 +0200 Subject: [PATCH 1/2] client credit insurance e2e path --- e2e/helpers/extensions.js | 12 ++--- e2e/helpers/selectors.js | 8 +++ .../02-client/20_credit_insurance.spec.js | 51 +++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 e2e/paths/02-client/20_credit_insurance.spec.js diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index a3c52748d..5413733ee 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -399,16 +399,16 @@ let actions = { pickDate: async function(selector, date) { date = date || new Date(); - const tzoffset = date.getTimezoneOffset() * 60000; - const localIso = (new Date(date.getTime() - tzoffset)) - .toISOString(); + const timeZoneOffset = date.getTimezoneOffset() * 60000; + const localDate = (new Date(date.getTime() - timeZoneOffset)) + .toISOString().substr(0, 10); await this.wait(selector); - await this.evaluate((selector, localIso) => { + await this.evaluate((selector, localDate) => { let input = document.querySelector(selector).$ctrl.input; - input.value = localIso.substr(0, 10); + input.value = localDate; input.dispatchEvent(new Event('change')); - }, selector, localIso); + }, selector, localDate); }, pickTime: async function(selector, time) { diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index a2ce49b8d..10dd56c38 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -202,6 +202,14 @@ export default { firstDocWorker: 'vn-client-dms-index vn-td:nth-child(8) > span', firstDocWorkerDescriptor: '.vn-popover.shown vn-worker-descriptor' }, + clientCreditInsurance: { + addNewContract: 'vn-client-credit-insurance-index vn-float-button[ui-sref="client.card.creditInsurance.create"]', + newCredit: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.credit"]', + newGrade: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.grade"]', + newStartingDate: 'vn-client-credit-insurance-create vn-date-picker[ng-model="$ctrl.creditClassification.started"]', + endCurrentContract: 'vn-client-credit-insurance-index vn-icon-button[icon="lock"]', + saveNewContract: 'vn-client-credit-insurance-create vn-submit' + }, clientContacts: { addContactButton: 'vn-client-contact vn-icon[icon="add_circle"]', name: 'vn-client-contact vn-textfield[ng-model="contact.name"]', diff --git a/e2e/paths/02-client/20_credit_insurance.spec.js b/e2e/paths/02-client/20_credit_insurance.spec.js new file mode 100644 index 000000000..5ae56d52f --- /dev/null +++ b/e2e/paths/02-client/20_credit_insurance.spec.js @@ -0,0 +1,51 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Client credit insurance path', () => { + let browser; + let page; + let previousMonth = new Date(); + previousMonth.setMonth(previousMonth.getMonth() - 1); + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('insurance', 'client'); + await page.accessToSearchResult('Tony Stark'); + await page.accessToSection('client.card.creditInsurance.index'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should open the create a new credit contract form', async() => { + await page.waitToClick(selectors.clientCreditInsurance.addNewContract); + await page.waitForState('client.card.creditInsurance.create'); + }); + + it('should create a new credit contract', async() => { + await page.write(selectors.clientCreditInsurance.newCredit, '1000'); + await page.write(selectors.clientCreditInsurance.newGrade, '1'); + await page.pickDate(selectors.clientCreditInsurance.newStartingDate, previousMonth); + await page.waitToClick(selectors.clientCreditInsurance.saveNewContract); + await page.waitForState('client.card.creditInsurance.index'); + }); + + it(`should verify the addNewContract button is not present since there's an active contract`, async() => { + await page.waitForSelector(selectors.clientCreditInsurance.addNewContract, {hidden: true}); + }); + + it(`should bring the current contract to an end`, async() => { + await page.waitToClick(selectors.clientCreditInsurance.endCurrentContract); + await page.waitToClick(selectors.globalItems.acceptButton); + }); + + it(`should verify the addNewContract button is now present since there's no active contract`, async() => { + await page.waitForSelector(selectors.clientCreditInsurance.addNewContract, {visible: true}); + }); + + it(`should verify the endCurrentContract button is not present since there's no active contract`, async() => { + await page.waitForSelector(selectors.clientCreditInsurance.endCurrentContract, {hidden: true}); + }); +}); From 787b7df4afacb08b0d68f2ddf3df625614be9aa1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 22 Oct 2020 14:33:51 +0200 Subject: [PATCH 2/2] e2e now check different type of grades --- e2e/helpers/selectors.js | 15 ++++-- .../02-client/20_credit_insurance.spec.js | 47 +++++++++++++++++-- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 10dd56c38..8cea46964 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -204,11 +204,18 @@ export default { }, clientCreditInsurance: { addNewContract: 'vn-client-credit-insurance-index vn-float-button[ui-sref="client.card.creditInsurance.create"]', - newCredit: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.credit"]', - newGrade: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.grade"]', - newStartingDate: 'vn-client-credit-insurance-create vn-date-picker[ng-model="$ctrl.creditClassification.started"]', + newCreditClassification: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.credit"]', + newInsuranceCredit: 'vn-client-credit-insurance-insurance-create vn-input-number[ng-model="$ctrl.insurance.credit"]', + newClassificationGrade: 'vn-client-credit-insurance-create vn-input-number[ng-model="$ctrl.creditClassification.grade"]', + newInsuranceGrade: 'vn-client-credit-insurance-insurance-create vn-input-number[ng-model="$ctrl.insurance.grade"]', + newClassificationStartingDate: 'vn-client-credit-insurance-create vn-date-picker[ng-model="$ctrl.creditClassification.started"]', + newInsuranceStartingDate: 'vn-client-credit-insurance-insurance-create vn-date-picker[ng-model="$ctrl.insurance.created"]', endCurrentContract: 'vn-client-credit-insurance-index vn-icon-button[icon="lock"]', - saveNewContract: 'vn-client-credit-insurance-create vn-submit' + firstContratViewCreditButton: 'vn-client-credit-insurance-index vn-card > vn-horizontal:nth-child(1) vn-icon-button[icon="desktop_windows"]', + addNewCredit: 'vn-client-credit-insurance-insurance-index vn-float-button vn-icon[icon="add"]', + saveNewContract: 'vn-client-credit-insurance-create vn-submit', + saveNewInsuranceCredit: 'vn-client-credit-insurance-insurance-create button[type="submit"]', + anyCreditInsuranceLine: 'vn-client-credit-insurance-insurance-index vn-tbody > vn-tr', }, clientContacts: { addContactButton: 'vn-client-contact vn-icon[icon="add_circle"]', diff --git a/e2e/paths/02-client/20_credit_insurance.spec.js b/e2e/paths/02-client/20_credit_insurance.spec.js index 5ae56d52f..278eb861a 100644 --- a/e2e/paths/02-client/20_credit_insurance.spec.js +++ b/e2e/paths/02-client/20_credit_insurance.spec.js @@ -25,9 +25,9 @@ describe('Client credit insurance path', () => { }); it('should create a new credit contract', async() => { - await page.write(selectors.clientCreditInsurance.newCredit, '1000'); - await page.write(selectors.clientCreditInsurance.newGrade, '1'); - await page.pickDate(selectors.clientCreditInsurance.newStartingDate, previousMonth); + await page.write(selectors.clientCreditInsurance.newCreditClassification, '1000'); + await page.write(selectors.clientCreditInsurance.newClassificationGrade, '1'); + await page.pickDate(selectors.clientCreditInsurance.newClassificationStartingDate, previousMonth); await page.waitToClick(selectors.clientCreditInsurance.saveNewContract); await page.waitForState('client.card.creditInsurance.index'); }); @@ -36,7 +36,46 @@ describe('Client credit insurance path', () => { await page.waitForSelector(selectors.clientCreditInsurance.addNewContract, {hidden: true}); }); - it(`should bring the current contract to an end`, async() => { + it(`should click the view credits button`, async() => { + await page.waitToClick(selectors.clientCreditInsurance.firstContratViewCreditButton); + await page.waitForState('client.card.creditInsurance.insurance.index'); + }); + + it('should click the add new credit button which opens the new credit form', async() => { + await page.waitToClick(selectors.clientCreditInsurance.addNewCredit); + await page.waitForState('client.card.creditInsurance.insurance.create'); + }); + + it('should fill the form but provide no grade to the new credit hence fail', async() => { + await page.write(selectors.clientCreditInsurance.newInsuranceCredit, '2000'); + await page.pickDate(selectors.clientCreditInsurance.newInsuranceStartingDate, previousMonth); + await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit); + const message = await page.waitForSnackbar(); + + expect(message.text).toEqual('The grade must be similar to the last one'); + }); + + it('should provide a correct grade and succesfully save a new credit then be redirected to the credit index', async() => { + await page.write(selectors.clientCreditInsurance.newInsuranceGrade, '999'); + await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit); + const message = await page.waitForSnackbar(); + await page.waitForState('client.card.creditInsurance.insurance.index'); + + expect(message.text).toEqual('Data saved!'); + }); + + it('should check the amount of credits is the expected', async() => { + const result = await page.countElement(selectors.clientCreditInsurance.anyCreditInsuranceLine); + + expect(result).toEqual(2); + }); + + it('should navigate to the credit insurance section', async() => { + await page.waitToClick(`vn-left-menu li > a[ui-sref="client.card.creditInsurance.index"]`); + await page.waitForState('client.card.creditInsurance.index'); + }); + + it('should bring the current contract to an end', async() => { await page.waitToClick(selectors.clientCreditInsurance.endCurrentContract); await page.waitToClick(selectors.globalItems.acceptButton); });