Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2131_jest_spyOn
gitea/salix/2131_jest_spyOn This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-02-26 13:24:41 +01:00
commit aedd551371
40 changed files with 537 additions and 92 deletions

View File

@ -40,16 +40,12 @@ let actions = {
},
login: async function(userName) {
try {
await this.expectURL('#!/login');
} catch (e) {
await this.goto(`${defaultURL}/#!/login`);
let dialog = await this.evaluate(() => {
return document.querySelector('button[response="accept"]');
});
if (dialog)
await this.waitToClick('button[response="accept"]');
}
await this.doLogin(userName);
await this.waitForFunction(() => {
@ -175,7 +171,7 @@ let actions = {
},
waitToClick: async function(selector) {
await this.waitForSelector(selector, {});
await this.waitForSelector(selector);
await this.click(selector);
},
@ -327,11 +323,18 @@ let actions = {
},
hideSnackbar: async function() {
await this.waitToClick('#shapes .shown button');
await this.waitFor(750); // holds up for the snackbar to be visible for a small period of time.
await this.evaluate(() => {
let hideButton = document.querySelector('#shapes .shown button');
if (hideButton)
return document.querySelector('#shapes .shown button').click();
});
},
waitForLastShape: async function(selector) {
await this.wait(selector);
waitForLastSnackbar: async function() {
const selector = 'vn-snackbar .shown .text';
await this.waitForSelector(selector);
let snackBarText = await this.evaluate(selector => {
const shape = document.querySelector(selector);
@ -341,12 +344,6 @@ let actions = {
return snackBarText;
},
waitForLastSnackbar: async function() {
await this.waitFor(1000); // this needs a refactor to be somehow dynamic ie: page.waitForResponse(urlOrPredicate[, options]) or something to fire waitForLastShape once the request is completed
await this.waitForSpinnerLoad();
return await this.waitForLastShape('vn-snackbar .shown .text');
},
accessToSearchResult: async function(searchValue) {
await this.clearInput('vn-searchbar');
await this.write('vn-searchbar', searchValue);
@ -412,7 +409,7 @@ let actions = {
.includes(searchValue.toLowerCase());
}, {}, builtSelector, searchValue);
await this.waitForMutation(`.vn-drop-down`, 'childList');
await this.waitForMutation('.vn-drop-down', 'childList');
await this.waitForContentLoaded();
},

View File

@ -28,7 +28,7 @@ export async function getBrowser() {
});
});
page = extendPage(page);
page.setDefaultTimeout(5000);
page.setDefaultTimeout(10000);
await page.goto(defaultURL, {waitUntil: 'networkidle0'});
return {page, close: browser.close.bind(browser)};
}

View File

@ -101,7 +101,6 @@ describe('Client create path', async() => {
});
it('should click on the Clients button of the top bar menu', async() => {
await page.waitFor(500);
await page.waitToClick(selectors.globalItems.applicationsMenuButton);
await page.wait(selectors.globalItems.applicationsMenuVisible);
await page.waitToClick(selectors.globalItems.clientsButton);

View File

@ -160,6 +160,7 @@ describe('Client Edit fiscalData path', () => {
});
it('should propagate the Equalization tax changes', async() => {
await page.waitFor(1000);
await page.waitToClick(selectors.clientFiscalData.acceptPropagationButton);
const result = await page.waitForLastSnackbar();

View File

@ -47,7 +47,7 @@ describe('Client Add address path', () => {
expect(result).toEqual('Incoterms is required for a non UEE member');
});
it(`should receive an error after clicking save button as consignee, incoterms and customsAgent are empty`, async() => {
it(`should receive an error after clicking save button as customsAgent is empty`, async() => {
await page.autocompleteSearch(selectors.clientAddresses.incoterms, 'Free Alongside Ship');
await page.waitToClick(selectors.clientAddresses.saveButton);
const result = await page.waitForLastSnackbar();
@ -63,13 +63,20 @@ describe('Client Add address path', () => {
expect(result).toEqual('Data saved!');
});
it(`should click on the first address button to confirm the new address exists and it's the default one`, async() => {
it(`should navigate back to the addresses index`, async() => {
let url = await page.expectURL('/address/index');
expect(url).toBe(true);
});
it(`should confirm the new address exists and it's the default one`, async() => {
const result = await page.waitToGetProperty(selectors.clientAddresses.defaultAddress, 'innerText');
expect(result).toContain('320 Park Avenue New York');
});
it(`should click on the make default icon of the second address`, async() => {
await page.waitForContentLoaded();
await page.waitToClick(selectors.clientAddresses.secondMakeDefaultStar);
const result = await page.waitForLastSnackbar();
@ -101,6 +108,7 @@ describe('Client Add address path', () => {
});
it(`should go back to the addreses section by clicking the cancel button`, async() => {
await page.waitForSelector('#shapes .shown', {hidden: true});
await page.waitToClick(selectors.clientAddresses.cancelEditAddressButton);
await page.waitToClick('.vn-confirm.shown button[response="accept"]');
let url = await page.expectURL('address/index');

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client lock verified data path', () => {
xdescribe('Client lock verified data path', () => {
let browser;
let page;
beforeAll(async() => {
@ -113,7 +113,7 @@ describe('Client lock verified data path', () => {
});
});
describe('as salesAssistant', () => {
xdescribe('as salesAssistant', () => {
it('should log in as salesAssistant then get to the client fiscal data', async() => {
await page.forceReloadSection('client.card.fiscalData');
await page.loginAndModule('salesAssistant', 'client');

View File

@ -85,7 +85,7 @@ describe('User config', () => {
await page.autocompleteSearch(selectors.globalItems.userLocalCompany, 'VNL');
let result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
expect(result).toContain('Data saved!');
});
});
@ -125,7 +125,7 @@ describe('User config', () => {
await page.clearInput(selectors.globalItems.userConfigThirdAutocomplete);
let result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
expect(result).toContain('Data saved!');
});
});
});

View File

@ -32,6 +32,6 @@ describe('Client contacts', () => {
await page.waitToClick(selectors.clientContacts.saveButton);
let result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
expect(result).toContain('Data saved!');
});
});

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Worker time control path', () => {
xdescribe('Worker time control path', () => {
let browser;
let page;
beforeAll(async() => {

View File

@ -37,22 +37,21 @@ describe('Item Edit basic data path', () => {
const result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
}, 20000);
});
it(`should create a new intrastat`, async() => {
await page.waitToClick(selectors.itemBasicData.newIntrastatButton);
await page.write(selectors.itemBasicData.newIntrastatId, '588420239');
await page.write(selectors.itemBasicData.newIntrastatDescription, 'Tropical Flowers');
await page.waitToClick(selectors.itemBasicData.acceptIntrastatButton);
await page.waitToClick(selectors.itemBasicData.acceptIntrastatButton); // this popover obscures the rest of the form for aprox 2 seconds
await page.waitFor(2000);
await page.waitForTextInField(selectors.itemBasicData.intrastat, 'Tropical Flowers');
let newcode = await page.waitToGetProperty(selectors.itemBasicData.intrastat, 'value');
expect(newcode).toEqual('588420239 Tropical Flowers');
});
it(`should save with the new intrastat`, async() => {
await page.waitFor(250);
await page.waitForTextInField(selectors.itemBasicData.intrastat, 'Tropical Flowers');
it('should save with the new intrastat', async() => {
await page.waitToClick(selectors.itemBasicData.submitBasicDataButton);
const result = await page.waitForLastSnackbar();

View File

@ -33,7 +33,6 @@ describe('Item regularize path', () => {
});
it('should search for an specific item', async() => {
await page.clearInput(selectors.itemsIndex.topbarSearch);
await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon pistol 9mm');
await page.waitToClick(selectors.itemsIndex.searchButton);
await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1);
@ -42,7 +41,7 @@ describe('Item regularize path', () => {
expect(resultCount).toEqual(1);
});
it(`should click on the search result to access to the item tax`, async() => {
it(`should click on the search result to access to the summary`, async() => {
await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon pistol 9mm');
await page.waitToClick(selectors.itemsIndex.searchResult);
let url = await page.expectURL('/summary');
@ -80,6 +79,7 @@ describe('Item regularize path', () => {
});
it('should clear the user local settings now', async() => {
await page.waitForContentLoaded();
await page.waitToClick(selectors.globalItems.userMenuButton);
await page.clearInput(selectors.globalItems.userConfigFirstAutocomplete);
const result = await page.waitForLastSnackbar();

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Item index path', () => {
xdescribe('Item index path', () => {
let browser;
let page;
beforeAll(async() => {
@ -54,7 +54,8 @@ describe('Item index path', () => {
await page.waitForSelector(selectors.itemsIndex.firstItemId, {hidden: true});
});
it('should mark all unchecked boxes to leave the index as it was', async() => {
xit('should mark all unchecked boxes to leave the index as it was', async() => {
await page.waitForContentLoaded();
await page.waitToClick(selectors.itemsIndex.fieldsToShowButton);
await page.waitToClick(selectors.itemsIndex.idCheckbox);
await page.waitToClick(selectors.itemsIndex.stemsCheckbox);

View File

@ -97,6 +97,7 @@ describe('Ticket List sale path', () => {
});
it('should select the 2nd and 3th item and delete both', async() => {
await page.waitFor(2000);
await page.waitToClick(selectors.ticketSales.secondSaleCheckbox);
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
await page.waitToClick(selectors.ticketSales.deleteSaleButton);

View File

@ -129,6 +129,7 @@ describe('Ticket descriptor path', () => {
});
it('should delete the stowaway', async() => {
await page.waitForContentLoaded();
await page.waitToClick(selectors.ticketDescriptor.moreMenu);
await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteStowawayButton);
await page.waitToClick(selectors.ticketDescriptor.acceptDeleteStowawayButton);

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Claim action path', () => {
xdescribe('Claim action path', () => {
let browser;
let page;
@ -24,7 +24,8 @@ describe('Claim action path', () => {
expect(result).toEqual('Data saved!');
});
it('should import the second importable ticket', async() => {
xit('should import the second importable ticket', async() => {
await page.waitFor(2000); // the animation adding the header element for the claimed total obscures somehow other elements for 2 seconds
await page.waitToClick(selectors.claimAction.importTicketButton);
await page.waitToClick(selectors.claimAction.secondImportableTicket);
const result = await page.waitForLastSnackbar();
@ -33,6 +34,7 @@ describe('Claim action path', () => {
});
it('should edit the second line destination field', async() => {
await page.waitForContentLoaded();
await page.autocompleteSearch(selectors.claimAction.secondLineDestination, 'Bueno');
const result = await page.waitForLastSnackbar();
@ -43,7 +45,7 @@ describe('Claim action path', () => {
await page.waitToClick(selectors.claimAction.firstDeleteLine);
const result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
expect(result).toContain('Data saved!');
});
it('should refresh the view to check the remaining line is the expected one', async() => {
@ -61,6 +63,7 @@ describe('Claim action path', () => {
});
it('should check the "is paid with mana" checkbox', async() => {
page.waitFor(2500); // can't use waitForNavigation here and needs more time than a single second to get the section ready...
await page.waitToClick(selectors.claimAction.isPaidWithManaCheckbox);
const result = await page.waitForLastSnackbar();

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('InvoiceOut descriptor path', () => {
xdescribe('InvoiceOut descriptor path', () => {
let browser;
let page;
@ -26,7 +26,7 @@ describe('InvoiceOut descriptor path', () => {
expect(result).toEqual(1);
});
it('should navigate to the invoiceOut index', async() => {
xit('should navigate to the invoiceOut index', async() => {
await page.waitToClick(selectors.globalItems.applicationsMenuButton);
await page.wait(selectors.globalItems.applicationsMenuVisible);
await page.waitToClick(selectors.globalItems.invoiceOutButton);

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Zone basic data path', () => {
xdescribe('Zone basic data path', () => {
let browser;
let page;
@ -42,7 +42,7 @@ describe('Zone basic data path', () => {
await page.waitToClick(selectors.zoneBasicData.saveButton);
});
it('should reload the section', async() => {
xit('should reload the section', async() => {
await page.reloadSection('zone.card.basicData');
let url = await page.expectURL('#!/zone/10/basic-data');
@ -73,7 +73,7 @@ describe('Zone basic data path', () => {
expect(result).toEqual('1');
});
it('should confirm the closing hour was updated', async() => {
xit('should confirm the closing hour was updated', async() => {
const result = await page.waitToGetProperty(selectors.zoneBasicData.closing, 'value');
expect(result).toEqual('21:00');

View File

@ -23,7 +23,7 @@
<section
ng-repeat="day in ::$ctrl.weekDays"
translate-attr="::{title: day.name}"
ng-click="$ctrl.selectWeekDay(day.index)">
ng-click="$ctrl.selectWeekDay($event, day.index)">
<span>{{::day.localeChar}}</span>
</section>
</div>
@ -38,7 +38,7 @@
on-last="$ctrl.repeatLast()">
<div
class="day-number"
ng-click="$ctrl.select(day)">
ng-click="$ctrl.select($event, day)">
{{::day | date: 'd'}}
</div>
</section>

View File

@ -127,10 +127,11 @@ export default class Calendar extends FormInput {
/*
* Day selection event
*/
select(day) {
select($event, day) {
if (!this.editable) return;
this.change(day);
this.emit('selection', {
$event: $event,
$days: [day],
$type: 'day'
});
@ -140,7 +141,7 @@ export default class Calendar extends FormInput {
/*
* WeekDay selection event
*/
selectWeekDay(weekday) {
selectWeekDay($event, weekday) {
if (!this.editable) return;
let days = [];
for (let day of this.days) {
@ -149,6 +150,7 @@ export default class Calendar extends FormInput {
}
this.field = days[0];
this.emit('selection', {
$event: $event,
$days: days,
$type: 'weekday',
$weekday: weekday

View File

@ -50,9 +50,15 @@ describe('Component vnCalendar', () => {
const day = new Date();
day.setHours(0, 0, 0, 0);
controller.select(day);
const clickEvent = new Event('click');
const target = document.createElement('div');
target.dispatchEvent(clickEvent);
controller.select(clickEvent, day);
let res = {
$event: clickEvent,
$days: [day],
$type: 'day'
};

View File

@ -12,6 +12,15 @@ vn-chip {
max-width: 100%;
box-sizing: border-box;
&.small {
height: 1.5em;
& > div {
padding: 0.6em;
font-size: 0.8rem;
}
}
&.colored {
background-color: $color-main;
color: $color-font-bg;

View File

@ -100,7 +100,7 @@ export default class CrudModel extends ModelProxy {
}
removeFilter() {
return applyFilter(null, null);
return this.applyFilter(null, null);
}
/**
@ -240,14 +240,12 @@ export default class CrudModel extends ModelProxy {
onRemoteDone(json, filter, append) {
let data = json.data;
if (append)
this.orgData = this.orgData.concat(data);
else {
this.orgData = data;
this.currentFilter = filter;
}
this.data = this.proxiedData.slice();
this.moreRows = filter.limit && data.length == filter.limit;
this.onRequestEnd();

View File

@ -47,4 +47,186 @@ describe('Component vnCrudModel', () => {
expect(controller.applyChanges).toHaveBeenCalledWith();
});
});
describe('setter url()', () => {
it('should set the url', () => {
spyOn(controller, 'autoRefresh');
spyOn(controller, 'clear');
controller.url = '/TestUrl';
expect(controller.url).toEqual('/TestUrl');
});
});
describe('isLoading()', () => {
it('should return false if canceler is null', () => {
controller.canceler = null;
expect(controller.isLoading).toBe(false);
});
it('should return true if canceler is not null', () => {
controller.canceler = 'validValue';
expect(controller.isLoading).toBe(true);
});
});
describe('buildFilter()', () => {
it('should build a filter and return it', () => {
controller.order = 'id ASC';
controller.fields = ['id'];
controller.limit = 1;
controller.filter = 'filterTest';
const result = controller.buildFilter();
expect(Object.keys(result).length).toEqual(13);
});
});
describe('sendRequest()', () => {
it('should call refresh() and check that the sendRequest is called', () => {
spyOn(controller, 'sendRequest').and.callThrough();
spyOn(controller, 'onRemoteDone');
spyOn(controller, 'onRemoteError');
const filter = {id: 1};
const serializedParams = encodeURIComponent(JSON.stringify(filter));
$httpBackend.whenRoute('GET', `model?filter=${serializedParams}`).respond();
controller.sendRequest(filter, true);
$httpBackend.flush();
expect(controller.isPaging).toBe(false);
});
});
describe('addFilter()', () => {
it('should call addFilter and check that the new filter has been added', () => {
spyOn(controller, 'refresh');
const filter = {where: {id: 1}};
controller.userFilter = {where: {name: 'test'}};
const filterMerged = {'where': {'and': [{'name': 'test'}, {'id': 1}]}};
controller.addFilter(filter);
expect(controller.userFilter).toEqual(filterMerged);
expect(controller.refresh).toHaveBeenCalledWith();
});
});
describe('applyFilter()', () => {
it('should call applyFilter and check that the refresh() is called', () => {
spyOn(controller, 'refresh');
const filter = {where: {id: 1}};
const params = {where: {id: 2}};
controller.applyFilter(filter, params);
expect(controller.userFilter).toEqual(filter);
expect(controller.userParams).toEqual(params);
expect(controller.refresh).toHaveBeenCalledWith();
});
});
describe('removeFilter()', () => {
it('should check the userFilter and userParams are removed', () => {
controller.removeFilter();
expect(controller.userFilter).toBe(null);
expect(controller.userParams).toBe(null);
});
});
describe('loadMore()', () => {
it('should call sendRequest with the new filter', () => {
spyOn(controller, 'sendRequest');
controller.moreRows = true;
controller.loadMore();
expect(controller.sendRequest).toHaveBeenCalledWith({'skip': 2}, true);
});
});
describe('clear()', () => {
it('should check that orgData and moreRows are set to null', () => {
controller.moreRows = true;
controller.clear();
expect(controller.moreRows).toBe(null);
expect(controller.orgData).toBe(null);
});
});
describe('refresh()', () => {
it('shold resolve a fake promise if this._url is undefined', () => {
spyOn(controller.$q, 'resolve');
controller._url = undefined;
controller.refresh();
expect(controller.$q.resolve).toHaveBeenCalledWith();
});
});
describe('onRemoteDone()', () => {
it('should check onRequestEnd is called, moreRows is true and currentFilter is undefined when append is true', () => {
spyOn(controller, 'onRequestEnd');
const append = true;
const json = {data: [
{
id: 1,
name: 'test'
}]};
const filter = {limit: 1};
controller.onRemoteDone(json, filter, append);
expect(controller.moreRows).toBe(true);
expect(controller.currentFilter).toBeUndefined();
expect(controller.onRequestEnd).toHaveBeenCalledWith();
});
it('should check onRequestEnd is called, moreRows is true and currentFilter is defined when append is false', () => {
spyOn(controller, 'onRequestEnd');
const append = false;
const json = {data: [
{
id: 1,
name: 'test'
}]};
const filter = {limit: 1};
controller.onRemoteDone(json, filter, append);
expect(controller.moreRows).toBe(true);
expect(controller.currentFilter).toBe(filter);
expect(controller.onRequestEnd).toHaveBeenCalledWith();
});
});
describe('onRemoteError()', () => {
it('should check the error', () => {
spyOn(controller, 'onRequestEnd');
let error;
try {
const newError = new Error('TestError');
controller.onRemoteError(newError);
} catch (e) {
error = e.message;
}
expect(controller.onRequestEnd).toHaveBeenCalledWith();
expect(error).toEqual('TestError');
});
});
});

View File

@ -37,6 +37,22 @@ export default class Popover extends Popup {
super.hide();
}
get parent() {
return this.__parent;
}
// Bug #2147 Popover loses parent location
set parent(value) {
this.__parent = value;
if (!value) return;
const parentRect = value.getBoundingClientRect();
this.parentRect = {};
for (let prop in parentRect)
this.parentRect[prop] = parentRect[prop];
}
/**
* Repositions the popover to a correct location relative to the parent.
*/
@ -55,7 +71,7 @@ export default class Popover extends Popup {
arrowStyle.top = '';
arrowStyle.bottom = '';
let parentRect = this.parent.getBoundingClientRect();
let parentRect = this.parentRect;
let popoverRect = this.windowEl.getBoundingClientRect();
let arrowRect = arrow.getBoundingClientRect();
let clamp = (value, min, max) => Math.min(Math.max(value, min), max);

View File

@ -63,15 +63,58 @@ export default class Controller extends Component {
show(data) {
this.actionHandler = data.actionHandler;
let shape = this.createShape(data);
let shape;
setTimeout(() =>
this.hide(shape), data.timeout || 3000);
const lastShape = this.lastShape;
const lastShapeData = lastShape && lastShape.data;
const isEqual = lastShape && (lastShapeData.shapeType == data.shapeType && lastShapeData.message == data.message);
if (lastShape && isEqual) {
shape = lastShape.element;
const shapeText = shape.querySelector('.text');
let chip = shapeText.querySelector('vn-chip');
if (chip) {
const text = chip.querySelector('span');
const number = parseInt(text.innerHTML);
text.innerHTML = number + 1;
} else {
chip = document.createElement('vn-chip');
chip.setAttribute('class', 'warning small');
let parent = document.createElement('div');
let span = document.createElement('span');
let text = document.createTextNode(1);
span.append(text);
parent.append(span);
chip.append(parent);
shapeText.appendChild(chip);
}
lastShape.element.classList.add('shown');
if (this.hideTimeout)
clearTimeout(this.hideTimeout);
} else {
shape = this.createShape(data);
setTimeout(() =>
shape.classList.add('shown'), 30);
}
this.hideTimeout = setTimeout(() => {
this.hide(shape);
this.lastShape = null;
}, data.timeout || 3000);
this.lastShape = {
data: data,
element: shape
};
}
/**
* Shows an error.
*

View File

@ -19,10 +19,16 @@ vn-snackbar .shape {
border-radius: .2em;
margin-bottom: 15px;
color: white;
padding: 1em;
padding: 0.8em;
&.text {
text-align: center
& > .text {
text-align: center;
vn-chip {
position: absolute;
left: -1em;
top: -1em;
}
}
&.shown {

View File

@ -0,0 +1,25 @@
const popover = {
show: () => {
return {
then: callback => {
callback();
}
};
},
hide: () => {
return {
then: callback => {
callback();
}
};
},
relocate: () => {
return {
then: callback => {
callback();
}
};
}
};
module.exports = popover;

View File

@ -26,4 +26,4 @@
"permission": "ALLOW"
}
]
}
}

View File

@ -26,8 +26,8 @@
<vn-th style="text-align:center">Description</vn-th>
<vn-th number>Quantity</vn-th>
<vn-th number>Price (PPU)</vn-th>
<vn-th number>New price (PPU)</vn-th>
<vn-th number>Price difference</vn-th>
<vn-th number>New (PPU)</vn-th>
<vn-th number>Difference</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>

View File

@ -1,3 +1,4 @@
Price (PPU): Precio (Ud.)
New price (PPU): Nuevo precio (Ud.)
Price difference: Diferencia de precio
New (PPU): Nuevo (Ud.)
Difference: Diferencia
Charge difference to: Cargar diferencia a

View File

@ -25,7 +25,7 @@
hide-contiguous="true"
has-events="$ctrl.hasEvents($day)"
get-class="$ctrl.getClass($day)"
on-selection="$ctrl.onSelection($days, $type, $weekday)"
on-selection="$ctrl.onSelection($event, $days, $type, $weekday)"
class="vn-pa-md"
style="min-width: 250px; flex: 1;">
</vn-calendar>

View File

@ -130,7 +130,7 @@ class Controller extends Component {
}
}
onSelection($days, $type, $weekday) {
onSelection($event, $days, $type, $weekday) {
let $events = [];
let $exclusions = [];
@ -141,6 +141,7 @@ class Controller extends Component {
}
this.emit('selection', {
$event,
$days,
$type,
$weekday,

View File

@ -1,6 +1,6 @@
import './index.js';
describe('Agency Component vnZoneCard', () => {
describe('Zone Component vnZoneCard', () => {
let controller;
let $httpBackend;
let data = {id: 1, name: 'fooName'};

View File

@ -1,7 +1,7 @@
import './index';
import watcher from 'core/mocks/watcher';
describe('Agency Component vnZoneCreate', () => {
describe('Zone Component vnZoneCreate', () => {
let $scope;
let $state;
let controller;

View File

@ -1,6 +1,7 @@
<div class="vn-w-md">
<vn-zone-calendar
data="data">
data="data"
on-selection="$ctrl.onSelection($event, $events)">
</vn-zone-calendar>
</div>
<vn-side-menu side="right">
@ -31,3 +32,11 @@
<vn-submit label="Query" class="vn-mt-sm"></vn-submit>
</form>
</vn-side-menu>
<!-- Zone Popover -->
<vn-popover vn-id="zoneEvents">
<div class="zoneEvents">
<div class="header vn-pa-sm" translate>Zones</div>
<vn-zone-index vn-id="zoneIndex"></vn-zone-index>
</div>
</vn-popover>

View File

@ -17,6 +17,27 @@ class Controller extends Section {
this.vnApp.showMessage(this.$t('No service for the specified zone'));
});
}
onSelection($event, $events) {
if (!$events.length) return;
const zones = [];
for (let event of $events)
zones.push(event.zoneFk);
this.$.zoneEvents.show($event.target);
const zoneIndex = this.$.zoneIndex;
const zoneModel = zoneIndex.$scope.model;
zoneModel.applyFilter({
include: {
relation: 'agencyMode',
scope: {fields: ['name']}
},
where: {
id: {inq: zones}
}
});
}
}
ngModule.component('vnZoneDeliveryDays', {

View File

@ -0,0 +1,92 @@
import './index.js';
import popover from 'core/mocks/popover';
import crudModel from 'core/mocks/crud-model';
describe('Zone Component vnZoneDeliveryDays', () => {
let $componentController;
let $httpBackend;
let controller;
let $element;
beforeEach(ngModule('zone'));
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$element = angular.element('<vn-zone-delivery-days></vn-zone-delivery-days');
controller = $componentController('vnZoneDeliveryDays', {$element});
controller.$.zoneEvents = popover;
controller.$.zoneIndex = {
$scope: {
model: crudModel
}
};
}));
describe('onSubmit()', () => {
it('should make an HTTP GET query and then call the showMessage() method', () => {
jest.spyOn(controller.vnApp, 'showMessage');
const expectedData = {events: []};
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
controller.onSubmit();
$httpBackend.flush();
expect(controller.$.data).toBeDefined();
expect(controller.$.data).toEqual(expectedData);
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No service for the specified zone');
});
it('should make an HTTP GET query and then set the data property', () => {
const expectedData = {events: [{zoneFk: 1}]};
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
controller.onSubmit();
$httpBackend.flush();
expect(controller.$.data).toBeDefined();
expect(controller.$.data).toEqual(expectedData);
});
});
describe('onSelection()', () => {
it('should not call the show popover method if events array is empty', () => {
jest.spyOn(controller.$.zoneEvents, 'show');
const event = new Event('click');
const target = document.createElement('div');
target.dispatchEvent(event);
const events = [];
controller.onSelection(event, events);
expect(controller.$.zoneEvents.show).not.toHaveBeenCalled();
});
it('should call the show() method and then call the applyFilter() method with the expected ids', () => {
const zoneModel = controller.$.zoneIndex.$scope.model;
jest.spyOn(controller.$.zoneEvents, 'show');
jest.spyOn(zoneModel, 'applyFilter');
const event = new Event('click');
const target = document.createElement('div');
target.dispatchEvent(event);
const events = [
{zoneFk: 1},
{zoneFk: 2},
{zoneFk: 8}
];
controller.onSelection(event, events);
const expectedFilter = {
include: {
relation: 'agencyMode',
scope: {fields: ['name']}
},
where: {
id: {inq: [1, 2, 8]}
}
};
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target);
expect(zoneModel.applyFilter).toHaveBeenCalledWith(expectedFilter);
});
});
});

View File

@ -1,3 +1,4 @@
@import "variables";
vn-zone-delivery-days {
vn-zone-calendar {
@ -14,3 +15,26 @@ vn-zone-delivery-days {
flex-direction: column;
}
}
.zoneEvents {
width: 700px;
max-height: 450px;
vn-float-button {
display: none
}
vn-data-viewer {
margin-bottom: 0;
vn-pagination {
padding: 0
}
}
& > .header {
background-color: $color-main;
color: white;
font-weight: bold;
text-align: center
}
}

View File

@ -4,7 +4,7 @@
filter="::$ctrl.filter"
limit="20"
data="zones"
auto-load="true">
auto-load="false">
</vn-crud-model>
<vn-auto-search
model="model"

View File

@ -1,6 +1,6 @@
import './index.js';
describe('Agency Component vnZoneIndex', () => {
describe('Zone Component vnZoneIndex', () => {
let $componentController;
let controller;