Skip to content
Snippets Groups Projects
Commit f3da8de6 authored by Vasyl Kozyrenko's avatar Vasyl Kozyrenko
Browse files

MTA-3882: Create auto test to Close a Sales Order Paid with PayPal Payments Pro Hosted Solution

parents 25c61cba 813fad85
Branches
No related merge requests found
......@@ -167,38 +167,22 @@ define([
prepareDateTimeFormats: function () {
this.pickerDateTimeFormat = this.options.dateFormat;
this.momentFormat = this.options.dateFormat ?
this.convertToMomentFormat(this.options.dateFormat) : this.momentFormat;
utils.convertToMomentFormat(this.options.dateFormat) : this.momentFormat;
if (this.options.showsTime) {
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;
}
this.pickerDateTimeFormat = utils.normalizeDate(this.pickerDateTimeFormat);
this.pickerDateTimeFormat = utils.convertToMomentFormat(this.pickerDateTimeFormat);
if (this.dateFormat) {
this.inputDateFormat = this.dateFormat;
}
this.inputDateFormat = utils.normalizeDate(this.inputDateFormat);
this.outputDateFormat = utils.normalizeDate(this.outputDateFormat);
this.inputDateFormat = utils.convertToMomentFormat(this.inputDateFormat);
this.outputDateFormat = utils.convertToMomentFormat(this.outputDateFormat);
this.validationParams.dateFormat = this.outputDateFormat;
},
/**
* Converts PHP IntlFormatter format to moment format.
*
* @param {String} format - PHP format
* @returns {String} - moment compatible formatting
*/
convertToMomentFormat: function (format) {
var newFormat;
newFormat = format.replace(/yy|y/gi, 'YYYY'); // replace the year
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
newFormat = newFormat.replace(/mm|m/gi, 'MM'); //replace the month
return newFormat;
}
});
});
......@@ -53,7 +53,7 @@ define([
'setDate',
moment(
observable(),
utils.normalizeDate(
utils.convertToMomentFormat(
options.dateFormat + (options.showsTime ? ' ' + options.timeFormat : '')
)
).toDate()
......
......@@ -7,21 +7,32 @@ define([
'ko',
'jquery',
'moment',
'mageUtils',
'Magento_Ui/js/lib/knockout/bindings/datepicker'
], function (ko, $, moment) {
], function (ko, $, moment, utils) {
'use strict';
describe('Datepicker binding', function () {
var observable,
element;
element,
config;
beforeEach(function () {
element = $('<input />');
observable = ko.observable();
config = {
options : {
dateFormat: 'M/d/yy',
'storeLocale': 'en_US',
'timeFormat': 'h:mm: a'
},
storage:ko.observable(moment().format('MM/DD/YYYY'))
};
$(document.body).append(element);
ko.applyBindingsToNode(element[0], { datepicker: observable });
ko.applyBindingsToNode(element[0], { datepicker: config });
});
afterEach(function () {
......@@ -29,22 +40,18 @@ define([
});
it('writes picked date\'s value to assigned observable', function () {
var openBtn,
todayBtn,
todayDate,
dateFormat,
result;
var todayDate,
momentFormat,
result,
inputFormat;
dateFormat = element.datepicker('option', 'dateFormat');
todayDate = moment().format(dateFormat);
inputFormat = 'M/d/yy';
openBtn = $('img.ui-datepicker-trigger');
todayBtn = $('[data-handler="today"]');
momentFormat = utils.convertToMomentFormat(inputFormat);
openBtn.click();
todayBtn.click();
todayDate = moment().format(momentFormat);
result = moment(observable()).format(dateFormat);
result = $('input:last').val();
expect(todayDate).toEqual(result);
});
......
This diff is collapsed.
......@@ -207,6 +207,22 @@ define([
}
return formData;
},
/**
* Converts PHP IntlFormatter format to moment format.
*
* @param {String} format - PHP format
* @returns {String} - moment compatible formatting
*/
convertToMomentFormat: function (format) {
var newFormat;
newFormat = format.replace(/yy|y/gi, 'YYYY'); // replace the year
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
newFormat = newFormat.replace(/mm|m/gi, 'MM'); //replace the month
return newFormat;
}
};
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment