#623 Autocomplete deberia ser capaz de mostrar dos campos

This commit is contained in:
Carlos Jimenez 2018-10-31 11:58:10 +01:00
parent 9364594a57
commit 2ced497638
8 changed files with 272 additions and 287 deletions

View File

@ -15,9 +15,10 @@ import './style.scss';
* @event change Thrown when value is changed
*/
export default class Autocomplete extends Input {
constructor($element, $scope, $http, $transclude, $translate) {
constructor($element, $scope, $http, $transclude, $translate, $interpolate) {
super($element, $scope);
this.$http = $http;
this.$interpolate = $interpolate;
this.$transclude = $transclude;
this.$translate = $translate;
this._field = undefined;
@ -167,35 +168,39 @@ export default class Autocomplete extends Input {
}
onSelectionRequest(data) {
if (data && data.length > 0) {
if (data && data.length > 0)
if (this.multiple)
this.selection = data;
else
this.selection = data[0];
} else
else
this.selection = null;
}
refreshDisplayed() {
let display = '';
let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem');
if (this._selection && this.showField) {
if (this._selection && this.showField)
if (this.multiple && Array.isArray(this._selection)) {
for (var item of this._selection) {
for (let item of this._selection) {
if (display.length > 0) display += ', ';
display += item[this.showField];
}
} else {
display = this._selection[this.showField];
if (hasTemplate) {
let template = this.$transclude(() => {}, null, 'tplItem').text();
display = this.$interpolate(template)(this._selection);
}
}
this.input.value = display;
if (this.translateFields) {
if (this.translateFields)
if (this.translateFields.indexOf(this.showField) > -1)
this.input.value = this.$translate.instant(display);
}
this.mdlUpdate();
}
@ -275,7 +280,7 @@ export default class Autocomplete extends Input {
this.$.dropDown.show(this.input, search);
}
}
Autocomplete.$inject = ['$element', '$scope', '$http', '$transclude', '$translate'];
Autocomplete.$inject = ['$element', '$scope', '$http', '$transclude', '$translate', '$interpolate'];
ngModule.component('vnAutocomplete', {
template: require('./autocomplete.html'),

View File

@ -26,7 +26,7 @@ export default class DropDown extends Component {
this.showLoadMore = true;
this.showFilter = true;
this.docKeyDownHandler = e => this.onDocKeyDown(e);
this.docKeyDownHandler = (e) => this.onDocKeyDown(e);
}
$postLink() {
@ -34,7 +34,7 @@ export default class DropDown extends Component {
this.input = this.element.querySelector('.search input');
this.ul = this.element.querySelector('ul');
this.list = this.element.querySelector('.list');
this.list.addEventListener('scroll', e => this.onScroll(e));
this.list.addEventListener('scroll', (e) => this.onScroll(e));
}
get shown() {
@ -310,9 +310,10 @@ export default class DropDown extends Component {
destroyList() {
this.ul.innerHTML = '';
if (this.scopes)
if (this.scopes) {
for (let scope of this.scopes)
scope.$destroy();
}
this.scopes = [];
}
@ -322,9 +323,10 @@ export default class DropDown extends Component {
fields.push(this.valueField);
fields.push(this.showField);
if (this.fields)
if (this.fields) {
for (let field of this.fields)
fields.push(field);
}
return fields;
}
@ -440,9 +442,10 @@ function getPosition(parent, event) {
while (target.parentNode !== parent)
target = target.parentNode;
for (let i = 0; i < children.length; i++)
for (let i = 0; i < children.length; i++) {
if (children[i] === target)
return i;
}
return -1;
}

View File

@ -21,9 +21,9 @@ Nightmare.action('changeLanguageToEnglish', function(done) {
return document.querySelector(selector).title;
}, '#lang')
.then((title) => {
if (title === 'Change language') {
if (title === 'Change language')
this.then(done);
} else {
else {
this.click('#lang')
.click('vn-main-menu [vn-id="langs-menu"] ul > li[name="en"]')
.then(done);
@ -48,7 +48,7 @@ Nightmare.action('parsedUrl', function(done) {
Nightmare.action('getProperty', function(selector, property, done) {
this.evaluate_now((selector, property) => {
return document.querySelector(selector)[property];
return document.querySelector(selector)[property].replace(/\s+/g, ' ').trim();
}, done, selector, property);
});
@ -86,9 +86,9 @@ Nightmare.action('getInputValue', function(selector, done) {
Nightmare.action('clearInput', function(selector, done) {
const backSpaces = [];
for (let i = 0; i < 50; i += 1) {
for (let i = 0; i < 50; i += 1)
backSpaces.push('\u0008');
}
this.wait(selector)
.type(selector, backSpaces.join(''))
.then(done);
@ -111,9 +111,9 @@ Nightmare.action('isVisible', function(selector, done) {
.evaluate_now((elementSelector) => {
const selectorMatches = document.querySelectorAll(elementSelector);
const element = selectorMatches[0];
if (selectorMatches.length > 1) {
if (selectorMatches.length > 1)
throw new Error(`multiple matches of ${elementSelector} found`);
}
let isVisible = false;
if (element) {
const eventHandler = (event) => {
@ -132,15 +132,15 @@ Nightmare.action('isVisible', function(selector, done) {
bubbles: true,
cancelable: true,
});
if (elementInCenter) {
if (elementInCenter)
elementInCenter.dispatchEvent(e);
}
if (elementInTopLeft) {
if (elementInTopLeft)
elementInTopLeft.dispatchEvent(e);
}
if (elementInBottomRight) {
if (elementInBottomRight)
elementInBottomRight.dispatchEvent(e);
}
element.removeEventListener('mouseover', eventHandler);
}
return isVisible;
@ -176,9 +176,8 @@ Nightmare.action('waitForNumberOfElements', function(selector, count, done) {
Nightmare.action('waitForClassNotPresent', function(selector, className, done) {
this.wait(selector)
.wait((resultSelector, targetClass) => {
if (!document.querySelector(resultSelector).classList.contains(targetClass)) {
if (!document.querySelector(resultSelector).classList.contains(targetClass))
return true;
}
}, selector, className)
.then(done);
});
@ -186,9 +185,8 @@ Nightmare.action('waitForClassNotPresent', function(selector, className, done) {
Nightmare.action('waitForClassPresent', function(selector, className, done) {
this.wait(selector)
.wait((resultSelector, targetClass) => {
if (document.querySelector(resultSelector).classList.contains(targetClass)) {
if (document.querySelector(resultSelector).classList.contains(targetClass))
return true;
}
}, selector, className)
.then(done);
});
@ -240,9 +238,9 @@ Nightmare.action('waitForShapes', function(selector, done) {
const shapes = document.querySelectorAll(selector);
const shapesList = [];
for (const shape of shapes) {
for (const shape of shapes)
shapesList.push(shape.innerText);
}
return shapesList;
}, done, selector);

View File

@ -234,7 +234,7 @@ describe('Client Edit basicData path', () => {
const result = await nightmare
.getInputValue(selectors.clientBasicData.salesPersonInput);
expect(result).toEqual('accessory');
expect(result).toEqual('accessory accessory');
});
it('should now confirm the channel have been selected', async () => {

View File

@ -1,8 +1,7 @@
import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/nightmare';
describe('Client', () => {
describe('Edit pay method path', () => {
describe('Client Edit pay method path', () => {
const nightmare = createNightmare();
beforeAll(() => {
@ -109,7 +108,7 @@ describe('Client', () => {
.waitProperty(selectors.clientPayMethod.swiftBicInput, 'value')
.getProperty(selectors.clientPayMethod.swiftBicInput, 'value');
expect(code).toEqual('GTHMCT');
expect(code).toEqual('GTHMCT Gotham City Banks');
});
it('should confirm Received LCR checkbox is checked', async () => {
@ -139,4 +138,3 @@ describe('Client', () => {
expect(checkedBox).toBeFalsy();
});
});
});

View File

@ -84,9 +84,10 @@ describe('Item', () => {
it(`should confirm the item intrastad was edited`, async () => {
const result = await nightmare
.getInputValue(selectors.itemBasicData.intrastatSelect);
.waitProperty(selectors.itemBasicData.intrastatSelect, 'value')
.getProperty(selectors.itemBasicData.intrastatSelect, 'value');
expect(result).toEqual('Coral y materiales similares');
expect(result).toEqual('5080000 Coral y materiales similares');
});
it(`should confirm the item relevancy was edited`, async () => {

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/nightmare';
describe('Item', () => {
describe('Item Create path', () => {
const nightmare = createNightmare();
describe('Create path', () => {
beforeAll(() => {
@ -9,65 +9,55 @@ describe('Item', () => {
.waitForLogin('buyer');
});
it('should access to the items index by clicking the items button', done => {
return nightmare
it('should access to the items index by clicking the items button', async () => {
const url = await nightmare
.click(selectors.moduleAccessView.itemsSectionButton)
.wait(selectors.itemsIndex.createItemButton)
.parsedUrl()
.then(url => {
.parsedUrl();
expect(url.hash).toEqual('#!/item/index');
done();
}).catch(done.fail);
});
it(`should search for the item Infinity Gauntlet to confirm it isn't created yet`, done => {
return nightmare
it(`should search for the item Infinity Gauntlet to confirm it isn't created yet`, async () => {
const result = await nightmare
.wait(selectors.itemsIndex.searchResult)
.type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet')
.click(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 0)
.countElement(selectors.itemsIndex.searchResult)
.then(result => {
.countElement(selectors.itemsIndex.searchResult);
expect(result).toEqual(0);
done();
}).catch(done.fail);
});
it('should access to the create item view by clicking the create floating button', done => {
return nightmare
it('should access to the create item view by clicking the create floating button', async () => {
const url = await nightmare
.click(selectors.itemsIndex.createItemButton)
.wait(selectors.itemCreateView.createButton)
.parsedUrl()
.then(url => {
.parsedUrl();
expect(url.hash).toEqual('#!/item/create');
done();
}).catch(done.fail);
});
it('should return to the item index by clickig the cancel button', done => {
return nightmare
it('should return to the item index by clickig the cancel button', async () => {
const url = await nightmare
.click(selectors.itemCreateView.cancelButton)
.wait(selectors.itemsIndex.createItemButton)
.parsedUrl()
.then(url => {
.parsedUrl();
expect(url.hash).toEqual('#!/item/index');
done();
}).catch(done.fail);
});
it('should now access to the create item view by clicking the create floating button', done => {
return nightmare
it('should now access to the create item view by clicking the create floating button', async () => {
const url = await nightmare
.click(selectors.itemsIndex.createItemButton)
.wait(selectors.itemCreateView.createButton)
.parsedUrl()
.then(url => {
.parsedUrl();
expect(url.hash).toEqual('#!/item/create');
done();
}).catch(done.fail);
});
it('should create the Infinity Gauntlet item', done => {
return nightmare
it('should create the Infinity Gauntlet item', async () => {
const result = await nightmare
.type(selectors.itemCreateView.name, 'Infinity Gauntlet')
.waitToClick(selectors.itemCreateView.typeSelect)
.waitToClick(selectors.itemCreateView.typeSelectOptionThree)
@ -76,90 +66,80 @@ describe('Item', () => {
.waitToClick(selectors.itemCreateView.originSelect)
.waitToClick(selectors.itemCreateView.originSelectOptionOne)
.click(selectors.itemCreateView.createButton)
.waitForLastSnackbar()
.then(result => {
.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
done();
}).catch(done.fail);
});
it('should confirm Infinity Gauntlet item was created', done => {
return nightmare
it('should confirm Infinity Gauntlet item was created', async () => {
let result = await nightmare
.wait(selectors.itemBasicData.nameInput)
.getInputValue(selectors.itemBasicData.nameInput)
.then(result => {
expect(result).toBe('Infinity Gauntlet');
return nightmare
.getInputValue(selectors.itemBasicData.nameInput);
expect(result).toEqual('Infinity Gauntlet');
result = await nightmare
.getInputValue(selectors.itemBasicData.typeSelect);
})
.then(result => {
expect(result).toBe('Crisantemo');
return nightmare
.getInputValue(selectors.itemBasicData.intrastatSelect);
})
.then(result => {
expect(result).toBe('Plantas vivas: Esqueje/injerto, Vid');
return nightmare
expect(result).toEqual('Crisantemo');
result = await nightmare
.waitProperty(selectors.itemBasicData.intrastatSelect, 'value')
.getProperty(selectors.itemBasicData.intrastatSelect, 'value');
expect(result).toEqual('6021010 Plantas vivas: Esqueje/injerto, Vid');
result = await nightmare
.getInputValue(selectors.itemBasicData.originSelect);
})
.then(result => {
expect(result).toBe('Spain');
done();
}).catch(done.fail);
expect(result).toEqual('Spain');
});
});
describe('Clone path', () => {
it('should return to the items index by clicking the return to items button', done => {
return nightmare
it('should return to the items index by clicking the return to items button', async () => {
const url = await nightmare
.click(selectors.itemBasicData.goToItemIndexButton)
.wait(selectors.itemsIndex.createItemButton)
.waitForURL('#!/item/index')
.parsedUrl()
.then(url => {
.parsedUrl();
expect(url.hash).toContain('#!/item/index');
done();
}).catch(done.fail);
});
it(`should search for the item Infinity Gauntlet`, done => {
return nightmare
it(`should search for the item Infinity Gauntlet`, async () => {
const result = await nightmare
.wait(selectors.itemsIndex.searchResult)
.type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet')
.click(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1)
.countElement(selectors.itemsIndex.searchResult)
.then(result => {
.countElement(selectors.itemsIndex.searchResult);
expect(result).toEqual(1);
done();
}).catch(done.fail);
});
it(`should clone the Infinity Gauntlet`, done => {
return nightmare
it(`should clone the Infinity Gauntlet`, async () => {
const url = await nightmare
.waitForTextInElement(selectors.itemsIndex.searchResult, 'Infinity Gauntlet')
.click(selectors.itemsIndex.searchResultCloneButton)
.waitToClick(selectors.itemsIndex.acceptClonationAlertButton)
.waitForURL('tags')
.parsedUrl()
.then(url => {
.parsedUrl();
expect(url.hash).toContain('tags');
done();
}).catch(done.fail);
});
it('should search for the item Infinity Gauntlet and find two', done => {
return nightmare
it('should search for the item Infinity Gauntlet and find two', async () => {
const result = await nightmare
.waitToClick(selectors.itemTags.goToItemIndexButton)
.wait(selectors.itemsIndex.searchResult)
.type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet')
.click(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2)
.countElement(selectors.itemsIndex.searchResult)
.then(result => {
.countElement(selectors.itemsIndex.searchResult);
expect(result).toEqual(2);
done();
}).catch(done.fail);
});
});
});

View File

@ -10,7 +10,7 @@ describe('Ticket Create packages path', () => {
});
it('should click on the Tickets button of the top bar menu', async () => {
let url = await nightmare
const url = await nightmare
.waitToClick(selectors.globalItems.applicationsMenuButton)
.wait(selectors.globalItems.applicationsMenuVisible)
.waitToClick(selectors.globalItems.ticketsButton)
@ -21,7 +21,7 @@ describe('Ticket Create packages path', () => {
});
it('should search for the ticket 1', async () => {
let result = await nightmare
const result = await nightmare
.wait(selectors.ticketsIndex.searchResult)
.type(selectors.ticketsIndex.searchTicketInput, 'id:1')
.click(selectors.ticketsIndex.searchButton)
@ -32,7 +32,7 @@ describe('Ticket Create packages path', () => {
});
it(`should click on the search result to access to the ticket packages`, async () => {
let url = await nightmare
const url = await nightmare
.waitForTextInElement(selectors.ticketsIndex.searchResultAddress, 'address 21')
.waitToClick(selectors.ticketsIndex.searchResult)
.waitToClick(selectors.ticketPackages.packagesButton)
@ -43,7 +43,7 @@ describe('Ticket Create packages path', () => {
});
it(`should delete the first package and receive and error to save a new one with blank quantity`, async () => {
let result = await nightmare
const result = await nightmare
.waitToClick(selectors.ticketPackages.firstRemovePackageButton)
.waitToClick(selectors.ticketPackages.addPackageButton)
.waitToClick(selectors.ticketPackages.firstPackageSelect)
@ -55,7 +55,7 @@ describe('Ticket Create packages path', () => {
});
it(`should attempt create a new package but receive an error if quantity is a string`, async () => {
let result = await nightmare
const result = await nightmare
.type(selectors.ticketPackages.firstQuantityInput, 'ninety 9')
.click(selectors.ticketPackages.savePackagesButton)
.waitForLastSnackbar();
@ -64,7 +64,7 @@ describe('Ticket Create packages path', () => {
});
it(`should attempt create a new package but receive an error if quantity is 0`, async () => {
let result = await nightmare
const result = await nightmare
.clearInput(selectors.ticketPackages.firstQuantityInput)
.type(selectors.ticketPackages.firstQuantityInput, 0)
.click(selectors.ticketPackages.savePackagesButton)
@ -74,7 +74,7 @@ describe('Ticket Create packages path', () => {
});
it(`should attempt create a new package but receive an error if package is blank`, async () => {
let result = await nightmare
const result = await nightmare
.clearInput(selectors.ticketPackages.firstQuantityInput)
.type(selectors.ticketPackages.firstQuantityInput, 99)
.click(selectors.ticketPackages.clearPackageSelectButton)
@ -85,7 +85,7 @@ describe('Ticket Create packages path', () => {
});
it(`should create a new package with correct data`, async () => {
let result = await nightmare
const result = await nightmare
.waitToClick(selectors.ticketPackages.firstPackageSelect)
.waitToClick(selectors.ticketPackages.firstPackageSelectOptionTwo)
.waitForTextInInput(selectors.ticketPackages.firstPackageSelect, 'Legendary Box')
@ -96,18 +96,18 @@ describe('Ticket Create packages path', () => {
});
it(`should confirm the first select is the expected one`, async () => {
let result = await nightmare
const result = await nightmare
.click(selectors.ticketSales.saleButton)
.wait(selectors.ticketSales.firstPackageSelect)
.click(selectors.ticketPackages.packagesButton)
.waitForTextInInput(selectors.ticketPackages.firstPackageSelect, 'Legendary Box')
.getInputValue(selectors.ticketPackages.firstPackageSelect);
expect(result).toEqual('Legendary Box');
expect(result).toEqual('7 : Legendary Box');
});
it(`should confirm the first quantity is the expected one`, async () => {
let result = await nightmare
const result = await nightmare
.waitForTextInInput(selectors.ticketPackages.firstQuantityInput, '99')
.getInputValue(selectors.ticketPackages.firstQuantityInput);