From 5af51763d6c954a71458b181b35ec0a691ac00a8 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Mon, 28 Dec 2020 12:55:28 +0100 Subject: [PATCH 1/2] Created back test field for entryObservation --- .../models/specs/entry-observation.spec.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 modules/entry/back/models/specs/entry-observation.spec.js diff --git a/modules/entry/back/models/specs/entry-observation.spec.js b/modules/entry/back/models/specs/entry-observation.spec.js new file mode 100644 index 000000000..fca13139c --- /dev/null +++ b/modules/entry/back/models/specs/entry-observation.spec.js @@ -0,0 +1,29 @@ +const app = require('vn-loopback/server/server'); + +describe('EntryObservation', () => { + const entryId = 1; + + it('should throw a user error if the observation type is duplicated.', async() => { + const observations = [ + { + entryFk: entryId, + observationTypeFk: 1, + description: 'repeated description' + }, + { + entryFk: entryId, + observationTypeFk: 1, + description: 'repeated description' + }, + ]; + + let error; + try { + await app.models.EntryObservation.create(observations); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + }); +}); From 5765fee47d4fccaab6b455302d3680b34c3c285f Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 31 Dec 2020 16:42:38 +0100 Subject: [PATCH 2/2] e2e path for entry.observation - missing role --- e2e/helpers/selectors.js | 8 +++ e2e/paths/12-entry/06_observations.spec.js | 66 ++++++++++++++++++++++ loopback/locale/en.json | 3 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 e2e/paths/12-entry/06_observations.spec.js diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 066d432c8..8d40542b8 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -939,6 +939,14 @@ export default { newEntryCompany: 'vn-entry-create vn-autocomplete[ng-model="$ctrl.entry.companyFk"]', saveNewEntry: 'vn-entry-create button[type="submit"]' }, + entryObservations: { + addNewObservation: 'vn-entry-observation vn-icon-button[icon="add_circle"]', + firstObservationType: 'vn-entry-observation vn-horizontal:nth-child(1) > vn-autocomplete[ng-model="observation.observationTypeFk"]', + secondObservationType: 'vn-entry-observation vn-horizontal:nth-child(2) > vn-autocomplete[ng-model="observation.observationTypeFk"]', + firstObservationDescription: 'vn-entry-observation vn-horizontal:nth-child(1) > vn-textfield[ng-model="observation.description"]', + secondObservationDescription: 'vn-entry-observation vn-horizontal:nth-child(2) > vn-textfield[ng-model="observation.description"]', + saveObservationsButton: 'vn-entry-observation vn-submit > button' + }, supplierSummary: { header: 'vn-supplier-summary > vn-card > h5', basicDataId: 'vn-supplier-summary vn-label-value[label="Id"]', diff --git a/e2e/paths/12-entry/06_observations.spec.js b/e2e/paths/12-entry/06_observations.spec.js new file mode 100644 index 000000000..107c2e0b6 --- /dev/null +++ b/e2e/paths/12-entry/06_observations.spec.js @@ -0,0 +1,66 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Entry observations path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + // await page.loginAndModule('buyer', 'entry'); // access denied, awaiting role confirmation + await page.loginAndModule('developer', 'entry'); + await page.accessToSearchResult('2'); + await page.accessToSection('entry.card.observation'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it(`should add two new observations of the same type then fail to save as they can't be repeated`, async() => { + await page.waitToClick(selectors.entryObservations.addNewObservation); + await page.waitToClick(selectors.entryObservations.addNewObservation); + await page.autocompleteSearch(selectors.entryObservations.firstObservationType, 'comercial'); + await page.autocompleteSearch(selectors.entryObservations.secondObservationType, 'comercial'); + await page.write(selectors.entryObservations.firstObservationDescription, 'first observation'); + await page.write(selectors.entryObservations.secondObservationDescription, 'second observation'); + await page.waitToClick(selectors.entryObservations.saveObservationsButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain(`The observation type can't be repeated`); + }); + + it('should set the 2nd observation of a different one and successfully save both', async() => { + await page.autocompleteSearch(selectors.entryObservations.secondObservationType, 'delivery'); + await page.waitToClick(selectors.entryObservations.saveObservationsButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Data saved!'); + }); + + it('should reload the section and make sure the first observation type was saved correctly', async() => { + await page.reloadSection('entry.card.observation'); + const result = await page.waitToGetProperty(selectors.entryObservations.firstObservationType, 'value'); + + expect(result).toEqual('comercial'); + }); + + it('should make sure the first observation description was saved correctly', async() => { + const result = await page.waitToGetProperty(selectors.entryObservations.firstObservationDescription, 'value'); + + expect(result).toEqual('first observation'); + }); + + it('should make sure the second observation type was saved correctly', async() => { + const result = await page.waitToGetProperty(selectors.entryObservations.secondObservationType, 'value'); + + expect(result).toEqual('delivery'); + }); + + it('should make sure the second observation description was saved correctly', async() => { + const result = await page.waitToGetProperty(selectors.entryObservations.secondObservationDescription, 'value'); + + expect(result).toEqual('second observation'); + }); +}); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 2e22f828b..1f85356dd 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -85,5 +85,6 @@ "You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data", "The social name cannot be empty": "The social name cannot be empty", "The nif cannot be empty": "The nif cannot be empty", - "A travel with this data already exists": "A travel with this data already exists" + "A travel with this data already exists": "A travel with this data already exists", + "The observation type can't be repeated": "The observation type can't be repeated" } \ No newline at end of file