From 7568a5f47ff088c10c47ec5a2c2aec3ec25d4fe4 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 8 Mar 2023 10:30:57 +0100 Subject: [PATCH] refs #4466 tests added --- e2e/helpers/selectors.js | 17 ++++- e2e/paths/09-invoice-in/05_correction.spec.js | 56 +++++++++++++++ loopback/locale/en.json | 10 ++- .../invoiceIn/front/correction/index.spec.js | 71 +------------------ modules/invoiceIn/front/locale/es.yml | 1 - 5 files changed, 80 insertions(+), 75 deletions(-) create mode 100644 e2e/paths/09-invoice-in/05_correction.spec.js diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 9840696c2..66d20201a 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -1085,14 +1085,27 @@ export default { }, invoiceInSummary: { totalTaxableBase: 'vn-invoice-in-summary > vn-card > vn-horizontal > vn-auto > vn-horizontal > vn-one.taxes > span', - supplierRef: 'vn-invoice-in-summary vn-label-value:nth-child(2) > section > span' + supplierRef: 'vn-invoice-in-summary vn-label-value:nth-child(2) > section > span', + correction: 'vn-invoice-in-summary > vn-card > vn-horizontal > vn-one[ng-if="$ctrl.summary.invoiceInCorrecting"]' + }, + invoiceInCorrection: { + add: 'vn-invoice-in-correction vn-icon-button[vn-tooltip="Add correction"]', + originInvoice: 'vn-invoice-in-correction vn-autocomplete[vn-id="originInvoice"]', + type: 'vn-invoice-in-correction vn-autocomplete[vn-id="type"]', + class: 'vn-invoice-in-correction vn-autocomplete[vn-id="class"]', + reason: 'vn-invoice-in-correction vn-autocomplete[vn-id="reason"]', + deleteButton: 'vn-invoice-in-correction vn-icon-button[icon="delete"]', + saveButton: 'vn-invoice-in-correction vn-submit', }, invoiceInDescriptor: { summaryIcon: 'vn-invoice-in-descriptor a[title="Go to module summary"]', moreMenu: 'vn-invoice-in-descriptor vn-icon-button[icon=more_vert]', moreMenuDeleteInvoiceIn: '.vn-menu [name="deleteInvoice"]', moreMenuCloneInvoiceIn: '.vn-menu [name="cloneInvoice"]', - acceptButton: '.vn-confirm.shown button[response="accept"]' + acceptButton: '.vn-confirm.shown button[response="accept"]', + supplierRef: 'vn-invoice-in-descriptor h5', + correctedInvoice: 'vn-invoice-in-descriptor a[vn-tooltip="Corrected invoice"]', + originInvoice: 'vn-invoice-in-descriptor a[vn-tooltip="Origin invoice"]' }, invoiceInBasicData: { issued: 'vn-invoice-in-basic-data vn-date-picker[ng-model="$ctrl.invoiceIn.issued"]', diff --git a/e2e/paths/09-invoice-in/05_correction.spec.js b/e2e/paths/09-invoice-in/05_correction.spec.js new file mode 100644 index 000000000..ac0912783 --- /dev/null +++ b/e2e/paths/09-invoice-in/05_correction.spec.js @@ -0,0 +1,56 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('InvoiceIn correction path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('administrative', 'invoiceIn'); + await page.accessToSearchResult('1'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should reach the summary section and check that contain a correction', async() => { + await page.waitForSelector(selectors.invoiceInSummary.correction); + await page.waitToClick(selectors.invoiceInDescriptor.correctedInvoice); + const result = await page.waitToGetProperty(selectors.invoiceInDescriptor.supplierRef, 'innerText'); + + expect(result).toContain('1235'); + await page.waitToClick(selectors.invoiceInDescriptor.originInvoice); + }); + + it('should go to correction section, delete the correction and save', async() => { + await page.accessToSection('invoiceIn.card.correction'); + await page.waitToClick(selectors.invoiceInCorrection.deleteButton); + await page.waitToClick(selectors.invoiceInCorrection.saveButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Data saved!'); + }); + + it('should create a new correction', async() => { + await page.reloadSection('invoiceIn.card.correction'); + await page.waitToClick(selectors.invoiceInCorrection.add); + await page.autocompleteSearch(selectors.invoiceInCorrection.originInvoice, '1238'); + await page.autocompleteSearch(selectors.invoiceInCorrection.type, 'Sustitución'); + await page.autocompleteSearch(selectors.invoiceInCorrection.class, 'Ticket'); + await page.autocompleteSearch(selectors.invoiceInCorrection.reason, 'IVA'); + await page.waitToClick(selectors.invoiceInCorrection.saveButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Data saved!'); + }); + + it('should go to the new correction summary and check it has changed', async() => { + await page.waitToClick(selectors.invoiceInDescriptor.correctedInvoice); + const result = await page.waitToGetProperty(selectors.invoiceInDescriptor.supplierRef, 'innerText'); + + expect(result).toContain('1238'); + }); +}); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index eeb25f75d..ad23f31fd 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -147,8 +147,12 @@ "Receipt's bank was not found": "Receipt's bank was not found", "This receipt was not compensated": "This receipt was not compensated", "Client's email was not found": "Client's email was not found", - "Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº {{id}}", + "Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº {{id}}", "It is not possible to modify tracked sales": "It is not possible to modify tracked sales", "It is not possible to modify sales that their articles are from Floramondo": "It is not possible to modify sales that their articles are from Floramondo", - "It is not possible to modify cloned sales": "It is not possible to modify cloned sales" -} + "It is not possible to modify cloned sales": "It is not possible to modify cloned sales", + "Origin invoice cannot be empty": "Origin invoice cannot be empty", + "Type cannot be empty": "Type cannot be empty", + "Class cannot be empty": "Class cannot be empty", + "Reason cannot be empty": "Reason cannot be empty" +} \ No newline at end of file diff --git a/modules/invoiceIn/front/correction/index.spec.js b/modules/invoiceIn/front/correction/index.spec.js index 32febb422..e15d4de22 100644 --- a/modules/invoiceIn/front/correction/index.spec.js +++ b/modules/invoiceIn/front/correction/index.spec.js @@ -7,12 +7,10 @@ describe('InvoiceIn', () => { let controller; let $scope; let vnApp; - let $httpBackend; beforeEach(ngModule('invoiceIn')); - beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => { - $httpBackend = _$httpBackend_; + beforeEach(inject(($componentController, $rootScope, _vnApp_,) => { vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); $scope = $rootScope.$new(); @@ -25,23 +23,8 @@ describe('InvoiceIn', () => { controller.invoiceIn = {id: 1}; })); - describe('taxRate()', () => { - it('should set tax rate with the Sage tax type value', () => { - const taxRateSelection = { - rate: 21 - }; - const invoiceInTax = { - taxableBase: 200 - }; - - const taxRate = controller.taxRate(invoiceInTax, taxRateSelection); - - expect(taxRate).toEqual(42); - }); - }); - describe('onSubmit()', () => { - it('should make HTTP POST request to save tax values', () => { + it('should make HTTP POST request to save correction values', () => { controller.card = {reload: () => {}}; jest.spyOn($scope.watcher, 'check'); jest.spyOn($scope.watcher, 'notifySaved'); @@ -58,56 +41,6 @@ describe('InvoiceIn', () => { expect(controller.card.reload).toHaveBeenCalledWith(); }); }); - - describe('onResponse()', () => { - it('should return success message', () => { - controller.expense = { - code: 7050000005, - isWithheld: 0, - description: 'Test' - }; - - const data = [{ - id: controller.expense.code, - isWithheld: controller.expense.isWithheld, - name: controller.expense.description - }]; - - jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expect('POST', `Expenses`, data).respond(); - - controller.onResponse(); - $httpBackend.flush(); - - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expense saved!'); - }); - - it('should return an error if code is empty', () => { - controller.expense = { - code: null, - isWithheld: 0, - description: 'Test' - }; - - jest.spyOn(controller.vnApp, 'showError'); - controller.onResponse(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The code can't be empty`); - }); - - it('should return an error if description is empty', () => { - controller.expense = { - code: 7050000005, - isWithheld: 0, - description: null - }; - - jest.spyOn(controller.vnApp, 'showError'); - controller.onResponse(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The description can't be empty`); - }); - }); }); }); diff --git a/modules/invoiceIn/front/locale/es.yml b/modules/invoiceIn/front/locale/es.yml index bf5a3f81b..0ca1e2539 100644 --- a/modules/invoiceIn/front/locale/es.yml +++ b/modules/invoiceIn/front/locale/es.yml @@ -26,5 +26,4 @@ Correction: Rectificativa Add correction: Añadir rectificativa Remove correction: Borrar rectificativa Origin invoice: Factura origen -Correction saved!: ¡Rectificativa guardada! Corrected invoice: Factura rectificativa