vnDialog bug fixes & front tests, workerTimeControl date fixes
gitea/salix/dev There was a failure building this commit
Details
gitea/salix/dev There was a failure building this commit
Details
This commit is contained in:
parent
38b4483edf
commit
f759c1e11a
|
@ -5,7 +5,7 @@ vn-chip {
|
|||
background-color: $color-bg;
|
||||
color: $color-font;
|
||||
font-size: .9rem;
|
||||
margin: .25em 0;
|
||||
margin: .25em;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 2em;
|
||||
|
|
|
@ -4,7 +4,11 @@ import template from './index.html';
|
|||
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} onAccept Shortcut handler for accept response
|
||||
|
@ -44,6 +48,7 @@ export default class Dialog extends Popup {
|
|||
* @param {String} response The response
|
||||
*/
|
||||
hide(response) {
|
||||
if (!this.shown) return;
|
||||
this.showHandler = null;
|
||||
super.hide();
|
||||
if (this.resolve)
|
||||
|
@ -57,6 +62,9 @@ export default class Dialog extends Popup {
|
|||
* @return {Boolean} The response handler return
|
||||
*/
|
||||
respond(response) {
|
||||
if (!this.shown)
|
||||
return this.$q.resolve();
|
||||
|
||||
let handlerArgs = {
|
||||
$response: response,
|
||||
$data: this.data
|
||||
|
|
|
@ -1,30 +1,106 @@
|
|||
describe('Component vnDialog', () => {
|
||||
let $element;
|
||||
let $scope;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('vnCore'));
|
||||
|
||||
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.emit = jasmine.createSpy('emit');
|
||||
}));
|
||||
|
||||
describe('respond()', () => {
|
||||
it(`should call onResponse() if it's defined in the controller`, () => {
|
||||
afterEach(() => {
|
||||
$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 = () => {};
|
||||
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();
|
||||
|
||||
expect(controller.onResponse).toHaveBeenCalledWith(jasmine.any(Object));
|
||||
});
|
||||
|
||||
it(`should call onResponse() with a response`, () => {
|
||||
it(`should call onResponse() with the response`, () => {
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -60,9 +60,9 @@ class Controller extends Component {
|
|||
if (this.events) {
|
||||
let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
||||
for (event of this.events) {
|
||||
event.wdays = [];
|
||||
if (!event.weekDays) continue;
|
||||
let weekDays = event.weekDays.split(',');
|
||||
event.wdays = [];
|
||||
for (let wday of weekDays) {
|
||||
let index = codes.indexOf(wday);
|
||||
if (index !== -1) event.wdays[index] = true;
|
||||
|
|
|
@ -80,12 +80,14 @@ class Controller {
|
|||
getAvailableAgencies() {
|
||||
this.order.agencyModeFk = null;
|
||||
if (this.order.landed && this.order.addressFk) {
|
||||
let filter = {addressFk: this.order.addressFk, landed: this.order.landed};
|
||||
filter = encodeURIComponent(JSON.stringify(filter));
|
||||
let query = `Agencies/landsThatDay?filter=${filter}`;
|
||||
this.$http.get(query).then(res => {
|
||||
this._availableAgencies = res.data;
|
||||
});
|
||||
let filter = {
|
||||
addressFk: this.order.addressFk,
|
||||
landed: this.order.landed
|
||||
};
|
||||
this.$http.get(`Agencies/landsThatDay`, {params: {filter}})
|
||||
.then(res => {
|
||||
this._availableAgencies = res.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class Controller {
|
|||
|
||||
async onSubmit() {
|
||||
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'];
|
||||
|
|
|
@ -137,14 +137,10 @@ class Controller {
|
|||
}
|
||||
|
||||
showAddTimeDialog(weekday) {
|
||||
const timed = new Date(weekday.dated);
|
||||
const now = new Date();
|
||||
const timed = new Date(weekday.dated.getTime());
|
||||
timed.setHours(0, 0, 0, 0);
|
||||
|
||||
now.setMonth(timed.getMonth());
|
||||
now.setDate(timed.getDate());
|
||||
now.setHours(0, 0, 0, 0);
|
||||
|
||||
this.newTime = now;
|
||||
this.newTime = timed;
|
||||
this.selectedWeekday = weekday;
|
||||
this.$.addTimeDialog.show();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue