bookingsync-calendar-widget
Advanced tools
Comparing version
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## [0.1.0] - 2017-02-20 | ||
### Added | ||
- Display currency from maps request. | ||
- Locale based price and currency format. | ||
- Currency to locale (as fallback). | ||
- `onSelectionCompleted` callback. | ||
- Prices are rounded now. | ||
- Better Logger. | ||
- Tests. | ||
### Changed | ||
- Scripts for mocks. | ||
- Styles for rates: | ||
- smaller font, | ||
- month min-width was increased to 27rem to accommodate prices. | ||
## [0.0.17] - 2017-02-14 | ||
@@ -5,0 +21,0 @@ ### Added |
{ | ||
"rental": { | ||
"maps.json": { | ||
"data": [ | ||
@@ -9,5 +9,6 @@ { | ||
"minimum_stays": "3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", | ||
"nightly_rates": "40,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", | ||
"nightly_rates": "40.12,100,155,1000.1288,1955,100,1755.13,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155,100,155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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", | ||
"availability": "3333333333333333333033333000333311111111111111000000000033330000000000000000000000033333333333333000000000000000000000033330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"start_date": "2017-02-10" | ||
"start_date": "2017-02-10", | ||
"currency": "HKD" | ||
} | ||
@@ -14,0 +15,0 @@ } |
{ | ||
"name": "bookingsync-calendar-widget", | ||
"version": "0.0.17", | ||
"version": "0.1.0", | ||
"description": "BookingSync Calendar Widget", | ||
@@ -12,8 +12,10 @@ "main": "dist/bookingsync-calendar-widget.js", | ||
"start": "webpack-dev-server --inline --hot --env=development --host 0.0.0.0", | ||
"mock-server": "json-server db.json" | ||
"mock-server": "node json-server.js" | ||
}, | ||
"dependencies": { | ||
"chai": "3.4.1", | ||
"widget-utils": "0.0.12", | ||
"tether-drop": "1.4.2" | ||
"sinon": "2.0.0-pre.4", | ||
"widget-utils": "0.0.14", | ||
"tether-drop": "1.4.2", | ||
"currency-symbol-map": "3.1.0" | ||
}, | ||
@@ -20,0 +22,0 @@ "devDependencies": { |
@@ -75,2 +75,3 @@ # Calendar Widget [](https://circleci.com/gh/BookingSync/calendar-widget) | ||
* `onSelectEnd(ISO String, Date)` | ||
* `onSelectionCompleted(ISO String, ISO String)` | ||
@@ -77,0 +78,0 @@ see `index.html` for more examples. |
@@ -15,2 +15,3 @@ /* global document, module, VERSION */ | ||
if (options.el.dataset.rentalId) { | ||
cal.autoSpawed = true; | ||
cal.loadMaps(options.el.dataset.rentalId); | ||
@@ -17,0 +18,0 @@ } |
@@ -14,4 +14,5 @@ /* global VERSION, Node, NODE_ENV, CSS_PREFIX, document, require */ | ||
import locales from './locales'; | ||
import { reset } from './styles/reset.scss'; | ||
import { formatDate, dateToIso, isLater, validationOfRange, tFormatter, currencyFormatter } from './utils'; | ||
import { | ||
@@ -23,47 +24,10 @@ calendar, chunky, highlighted, invalid, | ||
import { reset } from './styles/reset.scss'; | ||
const { documentElement: { lang } } = document; | ||
const formatDate = (format, year, month, day) => { | ||
function pad(number) { | ||
if (number < 10) { | ||
return `0${number}`; | ||
} | ||
return number; | ||
} | ||
return format | ||
.replace('dd', pad(day)) | ||
.replace('mm', pad(month + 1)) | ||
.replace('yyyy', year); | ||
}; | ||
const dateToIso = (year, month, day, isString = false) => { | ||
function pad(number) { | ||
if (number < 10) { | ||
return `0${number}`; | ||
} | ||
return number; | ||
} | ||
if (isString) { | ||
return `${year}-${pad(month + 1)}-${pad(day)}`; | ||
} | ||
return new Date(year, month, day); | ||
}; | ||
const isLater = (start, end) => dateToIso(...start) < dateToIso(...end); | ||
const validationOfRange = (cell, index, range) => { | ||
if (index === range.length - 1) { | ||
return cell.getAttribute('data-available-out') !== ''; | ||
} | ||
return cell.getAttribute('data-disabled') === ''; | ||
}; | ||
const tFormatter = (value, str) => str.replace('%number', value); | ||
export default class Calendar extends Emitter { | ||
constructor(opts, maps) { | ||
super(); | ||
this.name = 'BookingSync Calendar Widget'; | ||
this.name = config.name; | ||
this.VERSION = VERSION; | ||
@@ -73,3 +37,3 @@ | ||
if (!opts.el) { | ||
console.error('el must be HTML element'); | ||
this.logger('el must be HTML element', 'error'); | ||
return; | ||
@@ -97,3 +61,3 @@ } | ||
this.opts.lang = Calendar.widgetLang(this.opts.lang, lang); | ||
this.opts.lang = this.widgetLang(this.opts.lang, lang); | ||
this.locale = locales[this.opts.lang || 'en']; | ||
@@ -133,3 +97,8 @@ this.opts.startOfWeek = this.opts.startOfWeek || this.locale.startOfWeek; | ||
this.addBtnsEvents(); | ||
console.log(`[BookingSync Calendar Widget ${VERSION}] inited`); | ||
if (!this.autoSpawed && this.opts.rentalId) { | ||
this.loadMaps(this.opts.rentalId); | ||
} | ||
this.logger('inited'); | ||
this.emit('init'); | ||
@@ -281,4 +250,7 @@ } | ||
if (this.opts.isDropDown && this.selectionEnd && this.selectionStart) { | ||
if (this.selectionEnd && this.selectionStart) { | ||
this.completeSelection(isEndFirst, dateValue, cell); | ||
if (this.opts.isDropDown && this.calDrop) { | ||
this.closeDrop(null, true); | ||
} | ||
} | ||
@@ -413,2 +385,6 @@ } | ||
/** Resets selection, removes highlights | ||
* @public | ||
* @returns {Calendar} | ||
*/ | ||
resetSelection() { | ||
@@ -575,34 +551,3 @@ this.removeHighlight(); | ||
if ((dayCounter >= weekShiftCorrected) && dayOfMonth <= daysInMonth) { | ||
let rate = this.opts.showRates ? this.cTree.getDayProperty(year, month, dayOfMonth, 'rate') : null; | ||
const minStay = this.opts.showMinStay ? this.cTree.getDayProperty(year, month, dayOfMonth, 'minStay') : null; | ||
let isDisabled = this.cTree.isDayDisabled(year, month, dayOfMonth); | ||
let isOutAvailable = this.cTree.getDayProperty(year, month, dayOfMonth, 'isOutAvailable'); | ||
let isDisabledStart = this.cTree.getDayProperty(year, month, dayOfMonth, 'isMorningBlocked'); | ||
const cDate = this.opts.currDate; | ||
// if rate is float, then display 2 digits after point. | ||
rate = isNumeric(rate) && rate % 1 !== 0 ? rate.toFixed(2) : rate; | ||
// in the past any availability does not make sense | ||
if (isLater( | ||
[year, month, dayOfMonth], | ||
[cDate.getUTCFullYear(), cDate.getUTCMonth(), cDate.getDate()])) { | ||
isDisabled = true; | ||
isDisabledStart = undefined; | ||
isOutAvailable = undefined; | ||
} | ||
if (!this.opts.rentalId) { | ||
isDisabled = false; | ||
isOutAvailable = true; | ||
isDisabledStart = false; | ||
} | ||
week.push(tpls.weekDay( | ||
dayOfMonth, isDisabled, isDisabledStart, isOutAvailable, rate, minStay, | ||
tFormatter(rate, this.locale.rate), | ||
tFormatter(minStay, this.locale.minStay) | ||
)); | ||
week.push(this.dayTplString(year, month, dayOfMonth)); | ||
dayOfMonth += 1; | ||
@@ -625,4 +570,40 @@ // pushing placeholders instead of days | ||
dayTplString(year, month, dayOfMonth) { | ||
const cTree = this.cTree; | ||
const rate = this.opts.showRates ? cTree.getDayProperty(year, month, dayOfMonth, 'rate') : 0; | ||
const minStay = this.opts.showMinStay ? cTree.getDayProperty(year, month, dayOfMonth, 'minStay') : 0; | ||
let isDisabled = cTree.isDayDisabled(year, month, dayOfMonth); | ||
let isOutAvailable = cTree.getDayProperty(year, month, dayOfMonth, 'isOutAvailable'); | ||
let isDisabledStart = cTree.getDayProperty(year, month, dayOfMonth, 'isMorningBlocked'); | ||
const cDate = this.opts.currDate; | ||
// in the past any availability does not make sense | ||
if (isLater( | ||
[year, month, dayOfMonth], | ||
[cDate.getUTCFullYear(), cDate.getUTCMonth(), cDate.getDate()])) { | ||
isDisabled = true; | ||
isDisabledStart = undefined; | ||
isOutAvailable = undefined; | ||
} | ||
// if there is not rentalId and no maps, just render plain calendar | ||
if (!this.opts.rentalId) { | ||
isDisabled = false; | ||
isOutAvailable = true; | ||
isDisabledStart = false; | ||
} | ||
return tpls.weekDay( | ||
dayOfMonth, isDisabled, isDisabledStart, isOutAvailable, rate, minStay, | ||
currencyFormatter( | ||
Math.round(rate), this.opts.lang, this.opts.currency || this.locale.currency | ||
), | ||
tFormatter(minStay, this.locale.minStay) | ||
); | ||
} | ||
destroyMonths() { | ||
this.dom.months.map(m => destroyElement(m)); | ||
if (this.dom && isArray(this.dom.months)) { | ||
this.dom.months.map(m => destroyElement(m)); | ||
} | ||
} | ||
@@ -636,10 +617,12 @@ | ||
this.toggleLoading(); | ||
const onSuccess = (rental) => { | ||
const onSuccess = (maps) => { | ||
this.toggleLoading(); | ||
if (isArray(rental.data) && rental.data[0].attributes) { | ||
this.emit('maps-loaded', rental); | ||
this.addMaps(rental.data[0].attributes); | ||
if (isArray(maps.data) && maps.data[0].attributes) { | ||
this.opts.currency = maps.data[0].attributes.currency || this.opts.currency; | ||
this.emit('maps-loaded', maps); | ||
this.addMaps(maps.data[0].attributes); | ||
this.mapsLoaded = true; | ||
} else { | ||
console.error('expects json-api data format'); | ||
this.logger('expects json-api data format', 'error'); | ||
} | ||
@@ -651,8 +634,6 @@ }; | ||
this.emit('maps-error'); | ||
console.error('Server error happened'); | ||
this.logger('Server error happened', 'error'); | ||
}; | ||
if (NODE_ENV !== 'test') { | ||
ajax(this.opts.rentalUrl(id), onSuccess, onError); | ||
} | ||
ajax(this.opts.rentalUrl(id), onSuccess, onError); | ||
} | ||
@@ -662,3 +643,7 @@ | ||
this.emit('selection-completed', this.selectionStart, this.selectionEnd); | ||
this.closeDrop(null, true); | ||
if (isFunction(this.opts.onSelectionCompleted)) { | ||
this.opts.onSelectionCompleted( | ||
dateToIso(this.selectionStart, true), dateToIso(this.selectionEnd, true) | ||
); | ||
} | ||
} | ||
@@ -755,3 +740,3 @@ | ||
static widgetLang(elLang, documentLang) { | ||
widgetLang(elLang, documentLang) { | ||
let langFallback = elLang || documentLang; | ||
@@ -762,3 +747,3 @@ | ||
if (Object.keys(locales).indexOf(langFallback) === -1) { | ||
console.warn('this language is not supported yet, locale set to English'); | ||
this.logger('this language is not supported yet, locale set to English', 'error'); | ||
langFallback = 'en'; | ||
@@ -769,2 +754,12 @@ } | ||
} | ||
toString() { | ||
return `[${this.name} ${this.VERSION}] `; | ||
} | ||
logger(msg, type = 'log') { | ||
if (console && console[type]) { | ||
console[type](this.toString() + msg); | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ /* global NODE_ENV, Date */ | ||
export default { | ||
name: 'Calendar Widget', | ||
name: 'BookingSync Calendar Widget', | ||
apiHost: NODE_ENV === 'development' ? 'http://localhost:3000' : 'https://www.bookingsync.com', | ||
@@ -13,3 +13,3 @@ apiNamespace: '/api/v2/public', | ||
const route = this.apiMapsRoute.replace('{params}', ids); | ||
return NODE_ENV === 'development' ? `${this.apiHost}/rental` : `${this.apiHost}${this.apiNamespace}${route}`; | ||
return `${this.apiHost}${this.apiNamespace}${route}`; | ||
}, | ||
@@ -16,0 +16,0 @@ |
export default { | ||
en: { | ||
en: { | ||
weekdaysLabels: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'), | ||
months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'), | ||
rate: '€%number', | ||
currency: 'USD', | ||
minStay: '%number+ nights', | ||
startOfWeek: 0, | ||
startOfWeek: 0, | ||
}, | ||
@@ -12,41 +12,41 @@ 'en-gb': { | ||
months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'), | ||
rate: '€%number', | ||
currency: 'GBP', | ||
minStay: '%number+ nights', | ||
startOfWeek: 1, | ||
startOfWeek: 1, | ||
}, | ||
fr: { | ||
fr: { | ||
weekdaysLabels: 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'), | ||
months: 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'), | ||
rate: '€%number', | ||
currency: 'EUR', | ||
minStay: '%number+ nuits', | ||
startOfWeek: 1, | ||
startOfWeek: 1, | ||
}, | ||
de: { | ||
de: { | ||
weekdaysLabels: 'So_Mo_Di_Mi_Do_Fr_Sa'.split('_'), | ||
months: 'Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'), | ||
rate: '€%number', | ||
currency: 'EUR', | ||
minStay: '%number+ Nächte', | ||
startOfWeek: 1, | ||
startOfWeek: 1, | ||
}, | ||
sv: { | ||
sv: { | ||
weekdaysLabels: 'sö_må_ti_on_to_fr_lö'.split('_'), | ||
months: 'januari_februari_mars_april_maj_juni_juli_augusti_september_oktober_november_december'.split('_'), | ||
rate: '€%number', | ||
currency: 'EUR', | ||
minStay: '%number+ nätter', | ||
startOfWeek: 1, | ||
startOfWeek: 1, | ||
}, | ||
it: { | ||
it: { | ||
weekdaysLabels: 'Dom_Lun_Mar_Mer_Gio_Ven_Sab'.split('_'), | ||
months: 'gennaio_febbraio_marzo_aprile_maggio_giugno_luglio_agosto_settembre_ottobre_novembre_dicembre'.split('_'), | ||
rate: '€%number', | ||
currency: 'EUR', | ||
minStay: '%number+ notti.', | ||
startOfWeek: 1, | ||
startOfWeek: 1, | ||
}, | ||
es: { | ||
es: { | ||
weekdaysLabels: 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'), | ||
months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'), | ||
rate: '€%number', | ||
currency: 'EUR', | ||
minStay: '%number+ Noches', | ||
startOfWeek: 1, | ||
startOfWeek: 1, | ||
}, | ||
}; |
@@ -7,3 +7,3 @@ import s from './styles/calendar.scss'; | ||
export const month = `<div class="${s.mCell}"> | ||
export const month = `<div class="${s.mCell} js-month"> | ||
<table class="${s.month}" role="month"> | ||
@@ -10,0 +10,0 @@ <caption class="${s.caption}"></caption> |
@@ -20,8 +20,5 @@ /* global describe, module, it, before, after, document, xit, beforeEach, afterEach */ | ||
const div1 = stubElement('div', { | ||
'data-bookingsync-calendar-widget': true, | ||
'data-rental-id': 833, | ||
}); | ||
const div1 = stubElement('div', { 'data-bookingsync-calendar-widget': true }); | ||
const div2 = stubElement('div', { 'data-bookingsync-calendar-widget': true }); | ||
const div2 = stubElement('div', { 'data-bookingsync-calendar-widget': true }); | ||
describe('BookingSync Calendar renders on containers with auto-init', () => { | ||
@@ -28,0 +25,0 @@ before(() => { |
/* global describe, module, it, before, after, document, xit */ | ||
import chai from 'chai'; | ||
import sinon from 'sinon'; | ||
import s from '../../src/styles/calendar.scss'; | ||
import Calendar from '../../src/calendar'; | ||
@@ -8,5 +10,8 @@ | ||
const expect = chai.expect; | ||
const { keys } = Object; | ||
const expect = chai.expect; | ||
const { keys } = Object; | ||
const { stringify } = JSON; | ||
let server; | ||
const stubElement = (name, attrs) => { | ||
@@ -19,2 +24,19 @@ const params = attrs || {}; | ||
const maps = { | ||
data: [ | ||
{ | ||
id: 833, | ||
type: 'maps', | ||
attributes: { | ||
minimum_stays: '5,3,1', | ||
nightly_rates: '10,20,30', | ||
availability: '1,1,1', | ||
start_date: '2017-02-10', | ||
currency: 'HKD', | ||
}, | ||
}, | ||
], | ||
}; | ||
describe('sense checks', () => { | ||
@@ -28,7 +50,7 @@ let widget; | ||
widget = new Calendar({ | ||
el: rootElement, | ||
monthStart: 2, | ||
widget = new Calendar({ | ||
el: rootElement, | ||
monthStart: 1, | ||
displayMonths: 1, | ||
yearStart: 2017, | ||
yearStart: 2017, | ||
}); | ||
@@ -45,5 +67,61 @@ }); | ||
it('renders 3 empty days in February 2017, 01/02/2017 is We', () => { | ||
expect(document.querySelectorAll('.js-body-row-0 td:empty').length).to.be.deep.equal(3); | ||
it('renders 3 (Su first) empty days in February 2017, 01/02/2017 is We', () => { | ||
expect(document.querySelectorAll('.js-body-row-0 td:empty').length).to.be.equal(3); | ||
}); | ||
it('renders 1 month', () => { | ||
expect(document.querySelectorAll('.js-month').length).to.be.equal(1); | ||
}); | ||
}); | ||
describe('Loads maps and display correct currency, rates and min stay', () => { | ||
let widget; | ||
let rootElement; | ||
before(() => { | ||
server = sinon.fakeServer.create(); | ||
server.autoRespond = true; | ||
server.respondImmediately = true; | ||
server.respondWith('GET', new RegExp('maps.json'), stringify(maps)); | ||
rootElement = stubElement('div'); | ||
document.body.appendChild(rootElement); | ||
widget = new Calendar({ | ||
el: rootElement, | ||
monthStart: 1, | ||
displayMonths: 1, | ||
showRates: true, | ||
showMinStay: true, | ||
rentalId: 833, | ||
yearStart: 2017, | ||
lang: 'es', | ||
}); | ||
}); | ||
after(() => { | ||
widget.destroy(); | ||
server.restore(); | ||
}); | ||
it('renders', () => { | ||
expect(widget.el).to.be.deep.equal(rootElement); | ||
}); | ||
it('renders 2 (Mo first) empty days in February 2017, 01/02/2017 is We', () => { | ||
expect(document.querySelectorAll('.js-body-row-0 td:empty').length).to.be.equal(2); | ||
}); | ||
it('10 of February has rates, currency and min stay', () => { | ||
const cell = document.querySelector('[data-value="10"]'); | ||
expect(cell.querySelector(`.${s.cnt}`).innerText).to.be.equal('10'); | ||
expect(cell.querySelector(`.${s.info}`).innerText).to.be.equal('10 HKD'); | ||
expect(cell.querySelector(`.${s.infoExtra}`).innerText).to.be.equal('5+ Noches'); | ||
}); | ||
it('on 13 there is no information about rates..', () => { | ||
expect(document.querySelector('[data-value="13"]').innerText).to.be.equal('13'); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
362367
2.52%31
6.9%1837
8.44%128
0.79%5
66.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
Updated