vnDialog bug fixes & front tests, workerTimeControl date fixes
gitea/salix/dev There was a failure building this commit Details

This commit is contained in:
Juan Ferrer 2019-10-31 15:24:28 +01:00
parent 38b4483edf
commit f759c1e11a
7 changed files with 105 additions and 23 deletions

View File

@ -5,7 +5,7 @@ vn-chip {
background-color: $color-bg; background-color: $color-bg;
color: $color-font; color: $color-font;
font-size: .9rem; font-size: .9rem;
margin: .25em 0; margin: .25em;
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
height: 2em; height: 2em;

View File

@ -4,7 +4,11 @@ import template from './index.html';
import './style.scss'; import './style.scss';
/** /**
* Dialog component. * Dialog component that allows to register function handlers for responses. If
* any of the handlers returns false or a promise that resolves to false,
* the dialog closing is cancelled. Also, if promise is returned, the dialog
* will wait until it is resolved by locking itself and displaying a loading
* animation.
* *
* @property {Function} onResponse Handler for dialog response * @property {Function} onResponse Handler for dialog response
* @property {Function} onAccept Shortcut handler for accept response * @property {Function} onAccept Shortcut handler for accept response
@ -44,6 +48,7 @@ export default class Dialog extends Popup {
* @param {String} response The response * @param {String} response The response
*/ */
hide(response) { hide(response) {
if (!this.shown) return;
this.showHandler = null; this.showHandler = null;
super.hide(); super.hide();
if (this.resolve) if (this.resolve)
@ -57,6 +62,9 @@ export default class Dialog extends Popup {
* @return {Boolean} The response handler return * @return {Boolean} The response handler return
*/ */
respond(response) { respond(response) {
if (!this.shown)
return this.$q.resolve();
let handlerArgs = { let handlerArgs = {
$response: response, $response: response,
$data: this.data $data: this.data

View File

@ -1,30 +1,106 @@
describe('Component vnDialog', () => { describe('Component vnDialog', () => {
let $element; let $element;
let $scope;
let controller; let controller;
beforeEach(ngModule('vnCore')); beforeEach(ngModule('vnCore'));
beforeEach(angular.mock.inject(($rootScope, $compile) => { beforeEach(angular.mock.inject(($rootScope, $compile) => {
$element = $compile('<vn-dialog><tpl-body>Body</tpl-body></vn-dialog>')($rootScope); $scope = $rootScope.$new();
$element = $compile('<vn-dialog><tpl-body>Body</tpl-body></vn-dialog>')($scope);
controller = $element.controller('vnDialog'); controller = $element.controller('vnDialog');
controller.emit = jasmine.createSpy('emit'); controller.emit = jasmine.createSpy('emit');
})); }));
describe('respond()', () => { afterEach(() => {
it(`should call onResponse() if it's defined in the controller`, () => { $scope.$destroy();
$element.remove();
});
describe('show()', () => {
it(`should call the show handler when response is given`, () => {
let called;
let showHandler = () => called = true;
controller.show(showHandler);
controller.respond();
expect(called).toBeTruthy();
});
it(`should hide the dialog when response is given`, () => {
controller.show();
spyOn(controller, 'hide');
controller.respond('answer');
expect(controller.hide).toHaveBeenCalledWith('answer');
});
it(`should not hide the dialog when false is returned from response handler`, () => {
controller.show(() => false);
spyOn(controller, 'hide');
controller.respond('answer');
expect(controller.hide).not.toHaveBeenCalled();
});
});
describe('hide()', () => {
it(`should do nothing if it's already hidden`, () => {
controller.onResponse = () => {}; controller.onResponse = () => {};
spyOn(controller, 'onResponse'); spyOn(controller, 'onResponse');
controller.hide();
expect(controller.onResponse).not.toHaveBeenCalledWith();
});
});
describe('respond()', () => {
it(`should do nothing if dialog is already hidden`, () => {
controller.onResponse = () => {};
spyOn(controller, 'onResponse');
controller.respond();
expect(controller.onResponse).not.toHaveBeenCalledWith();
});
it(`should call onResponse() if it's defined`, () => {
controller.onResponse = () => {};
spyOn(controller, 'onResponse');
controller.show();
controller.respond(); controller.respond();
expect(controller.onResponse).toHaveBeenCalledWith(jasmine.any(Object)); expect(controller.onResponse).toHaveBeenCalledWith(jasmine.any(Object));
}); });
it(`should call onResponse() with a response`, () => { it(`should call onResponse() with the response`, () => {
controller.onResponse = () => {}; controller.onResponse = () => {};
spyOn(controller, 'onResponse'); spyOn(controller, 'onResponse');
controller.respond('answer');
expect(controller.onResponse).toHaveBeenCalledWith({$response: 'answer'}); controller.show();
controller.respond('response');
expect(controller.onResponse).toHaveBeenCalledWith({$response: 'response'});
});
it(`should call onAccept() when accept response is given`, () => {
controller.onAccept = () => {};
spyOn(controller, 'onAccept');
controller.show();
controller.respond('accept');
expect(controller.onAccept).toHaveBeenCalledWith({$response: 'accept'});
});
it(`should resolve the promise returned by show() with response`, () => {
let response;
controller.show().then(res => response = res);
controller.respond('response');
$scope.$apply();
expect(response).toEqual('response');
}); });
}); });
}); });

View File

@ -60,9 +60,9 @@ class Controller extends Component {
if (this.events) { if (this.events) {
let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
for (event of this.events) { for (event of this.events) {
event.wdays = [];
if (!event.weekDays) continue; if (!event.weekDays) continue;
let weekDays = event.weekDays.split(','); let weekDays = event.weekDays.split(',');
event.wdays = [];
for (let wday of weekDays) { for (let wday of weekDays) {
let index = codes.indexOf(wday); let index = codes.indexOf(wday);
if (index !== -1) event.wdays[index] = true; if (index !== -1) event.wdays[index] = true;

View File

@ -80,10 +80,12 @@ class Controller {
getAvailableAgencies() { getAvailableAgencies() {
this.order.agencyModeFk = null; this.order.agencyModeFk = null;
if (this.order.landed && this.order.addressFk) { if (this.order.landed && this.order.addressFk) {
let filter = {addressFk: this.order.addressFk, landed: this.order.landed}; let filter = {
filter = encodeURIComponent(JSON.stringify(filter)); addressFk: this.order.addressFk,
let query = `Agencies/landsThatDay?filter=${filter}`; landed: this.order.landed
this.$http.get(query).then(res => { };
this.$http.get(`Agencies/landsThatDay`, {params: {filter}})
.then(res => {
this._availableAgencies = res.data; this._availableAgencies = res.data;
}); });
} }

View File

@ -9,7 +9,7 @@ class Controller {
async onSubmit() { async onSubmit() {
let newOrderID = await this.$.card.createOrder(); let newOrderID = await this.$.card.createOrder();
this.$state.go("order.card.summary", {id: newOrderID}); this.$state.go('order.card.summary', {id: newOrderID});
} }
} }
Controller.$inject = ['$scope', '$http', '$state']; Controller.$inject = ['$scope', '$http', '$state'];

View File

@ -137,14 +137,10 @@ class Controller {
} }
showAddTimeDialog(weekday) { showAddTimeDialog(weekday) {
const timed = new Date(weekday.dated); const timed = new Date(weekday.dated.getTime());
const now = new Date(); timed.setHours(0, 0, 0, 0);
now.setMonth(timed.getMonth()); this.newTime = timed;
now.setDate(timed.getDate());
now.setHours(0, 0, 0, 0);
this.newTime = now;
this.selectedWeekday = weekday; this.selectedWeekday = weekday;
this.$.addTimeDialog.show(); this.$.addTimeDialog.show();
} }