#820 e2e item.diary

This commit is contained in:
Carlos Jimenez 2018-11-16 12:03:52 +01:00
parent 30df8abed2
commit ed15d5566e
3 changed files with 106 additions and 17 deletions

View File

@ -17,10 +17,10 @@ Nightmare.action('login', function(userName, done) {
Nightmare.action('changeLanguageToEnglish', function(done) {
this.wait('#lang')
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).title;
}, '#lang')
.then((title) => {
.then(title => {
if (title === 'Change language')
this.then(done);
else {
@ -41,7 +41,7 @@ Nightmare.action('waitForLogin', function(userName, done) {
Nightmare.action('parsedUrl', function(done) {
this.url()
.then((url) => {
.then(url => {
done(null, new URL(url));
});
});
@ -58,7 +58,7 @@ Nightmare.action('waitPropertyLength', function(selector, property, minLength, d
return element && element[property] != null && element[property] !== '' && element[property].length >= minLength;
}, selector, property, minLength)
.getProperty(selector, property)
.then((result) => done(null, result), done);
.then(result => done(null, result), done);
});
Nightmare.action('waitProperty', function(selector, property, done) {
@ -67,7 +67,7 @@ Nightmare.action('waitProperty', function(selector, property, done) {
return element && element[property] != null && element[property] !== '';
}, selector, property)
.getProperty(selector, property)
.then((result) => done(null, result), done);
.then(result => done(null, result), done);
});
Nightmare.action('getInnerText', function(selector, done) {
@ -108,7 +108,7 @@ Nightmare.action('waitToClick', function(selector, done) {
Nightmare.action('isVisible', function(selector, done) {
this.wait(selector)
.evaluate_now((elementSelector) => {
.evaluate_now(elementSelector => {
const selectorMatches = document.querySelectorAll(elementSelector);
const element = selectorMatches[0];
if (selectorMatches.length > 1)
@ -116,7 +116,7 @@ Nightmare.action('isVisible', function(selector, done) {
let isVisible = false;
if (element) {
const eventHandler = (event) => {
const eventHandler = event => {
event.preventDefault();
isVisible = true;
};
@ -149,7 +149,7 @@ Nightmare.action('isVisible', function(selector, done) {
Nightmare.action('selectText', function(selector, done) {
this.wait(selector)
.evaluate((elementToSelect) => {
.evaluate(elementToSelect => {
const range = document.createRange();
range.selectNodeContents(document.querySelector(elementToSelect));
const sel = window.getSelection();
@ -161,7 +161,7 @@ Nightmare.action('selectText', function(selector, done) {
});
Nightmare.action('countElement', function(selector, done) {
this.evaluate_now((selector) => {
this.evaluate_now(selector => {
return document.querySelectorAll(selector).length;
}, done, selector);
});
@ -209,24 +209,24 @@ Nightmare.action('waitForTextInInput', function(selector, name, done) {
Nightmare.action('waitForInnerText', function(selector, done) {
this.wait(selector)
.wait((selector) => {
.wait(selector => {
const innerText = document.querySelector(selector).innerText;
return innerText != null && innerText != '';
}, selector)
.evaluate_now((selector) => {
.evaluate_now(selector => {
return document.querySelector(selector).innerText;
}, done, selector);
});
Nightmare.action('waitForEmptyInnerText', function(selector, done) {
this.wait((selector) => {
this.wait(selector => {
return document.querySelector(selector).innerText == '';
}, selector)
.then(done);
});
Nightmare.action('waitForURL', function(hashURL, done) {
this.wait((hash) => {
this.wait(hash => {
return document.location.hash.includes(hash);
}, hashURL)
.then(done);
@ -234,7 +234,7 @@ Nightmare.action('waitForURL', function(hashURL, done) {
Nightmare.action('waitForShapes', function(selector, done) {
this.wait(selector)
.evaluate_now((selector) => {
.evaluate_now(selector => {
const shapes = document.querySelectorAll(selector);
const shapesList = [];
@ -248,14 +248,14 @@ Nightmare.action('waitForShapes', function(selector, done) {
Nightmare.action('waitForSnackbar', function(done) {
this.wait(500).waitForShapes('vn-snackbar .shape .text')
.then((shapes) => {
.then(shapes => {
done(null, shapes);
});
});
Nightmare.action('waitForLastShape', function(selector, done) {
this.wait(selector)
.evaluate_now((selector) => {
.evaluate_now(selector => {
const shape = document.querySelector(selector);
return shape.innerText;
@ -264,7 +264,7 @@ Nightmare.action('waitForLastShape', function(selector, done) {
Nightmare.action('waitForLastSnackbar', function(done) {
this.wait(500).waitForLastShape('vn-snackbar .shape .text')
.then((shapes) => {
.then(shapes => {
done(null, shapes);
});
});

View File

@ -296,8 +296,17 @@ export default {
botanical: `vn-item-summary vn-vertical[name="botanical"]`,
barcode: `vn-item-summary vn-vertical[name="barcode"]`
},
itemDiary: {
thirdTicketId: 'vn-item-diary > vn-vertical > vn-card > div > vn-vertical > vn-table > div > vn-tbody > vn-tr:nth-child(3) > vn-td:nth-child(2) > span',
firstBalance: 'vn-item-diary > vn-vertical > vn-card > div > vn-vertical > vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td.balance',
fifthBalance: 'vn-item-diary > vn-vertical > vn-card > div > vn-vertical > vn-table > div > vn-tbody > vn-tr.ng-scope.isToday.isIn > vn-td.balance > span',
warehouseSelect: 'vn-item-diary vn-autocomplete[field="$ctrl.warehouseFk"] > div > div > input',
warehouseSelectFourthOption: 'vn-item-diary > vn-vertical > vn-card > div > vn-vertical > vn-horizontal > vn-autocomplete > vn-drop-down > vn-popover > div > div.content > div > div.list > ul > li:nth-child(4)'
},
ticketSummary: {
sale: 'vn-ticket-summary > vn-card > div > vn-vertical > vn-horizontal > table > tbody > tr',
firstSaleItemId: 'vn-ticket-summary > vn-card > div > vn-vertical > vn-horizontal:nth-child(3) > table > tbody > tr > td:nth-child(2) > span',
popoverDiaryButton: 'vn-ticket-summary > vn-item-descriptor-popover vn-item-descriptor vn-icon[icon="icon-transaction"]',
firstSaleQuantity: 'vn-ticket-summary > vn-card > div > vn-vertical > vn-horizontal:nth-child(3) > table > tbody > tr > td:nth-child(4)',
firstSaleDiscount: 'vn-ticket-summary > vn-card > div > vn-vertical > vn-horizontal:nth-child(3) > table > tbody > tr > td:nth-child(6)'
},

View File

@ -0,0 +1,80 @@
import selectors from '../../helpers/selectors.js';
import config from '../../helpers/config.js';
import createNightmare from '../../helpers/nightmare';
describe('Ticket diary path', () => {
const nightmare = createNightmare();
beforeAll(() => {
nightmare
.waitForLogin('employee');
});
it('should click on the Tickets button of the top bar menu', async () => {
const url = await nightmare
.waitToClick(selectors.globalItems.applicationsMenuButton)
.wait(selectors.globalItems.applicationsMenuVisible)
.waitToClick(selectors.globalItems.ticketsButton)
.wait(selectors.ticketsIndex.searchResult)
.parsedUrl();
expect(url.hash).toEqual('#!/ticket/index');
});
it('should search for a specific ticket', async () => {
const result = await nightmare
.wait(selectors.ticketsIndex.searchResult)
.type(selectors.ticketsIndex.searchTicketInput, 'id:1')
.click(selectors.ticketsIndex.searchButton)
.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1)
.countElement(selectors.ticketsIndex.searchResult);
expect(result).toEqual(1);
});
it(`should click on the search result to access to the ticket summary`, async () => {
const url = await nightmare
.waitForTextInElement(selectors.ticketsIndex.searchResult, 'address 21')
.waitToClick(selectors.ticketsIndex.searchResult)
.waitForURL('/summary')
.url();
expect(url).toContain('/summary');
});
it(`should navigate to the item diary from the 1st sale item id descriptor popover`, async () => {
const url = await nightmare
.waitToClick(selectors.ticketSummary.firstSaleItemId)
.waitToClick(selectors.ticketSummary.popoverDiaryButton)
.waitForLogin('employee')
.goto(`${config.url}#!/item/1/diary?warehouseFk=1&ticketFk=1`)
.parsedUrl();
expect(url.hash).toContain('/diary');
});
it(`should check the seventh line id is marked as counter`, async () => {
const result = await nightmare
.waitProperty(selectors.itemDiary.thirdTicketId, 'className')
.getProperty(selectors.itemDiary.thirdTicketId, 'className');
expect(result).toContain('counter');
});
it(`should check the fifth line balance is marked as counter`, async () => {
const result = await nightmare
.getProperty(selectors.itemDiary.fifthBalance, 'className');
expect(result).toContain('counter');
});
it(`should change to the warehouse two and check there are sales marked as negative balance`, async () => {
const result = await nightmare
.waitToClick(selectors.itemDiary.warehouseSelect)
.waitToClick(selectors.itemDiary.warehouseSelectFourthOption)
.waitProperty(selectors.itemDiary.firstBalance, 'className')
.getProperty(selectors.itemDiary.firstBalance, 'className');
expect(result).toContain('balance');
});
});