Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
101
gaia/apps/calendar/test/unit/service/helper.js
Executable file
101
gaia/apps/calendar/test/unit/service/helper.js
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
define(function(require, exports, module) {
|
||||
'use strict';
|
||||
|
||||
var IcalRecurExpansion = require('service/ical_recur_expansion');
|
||||
|
||||
function request(file, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/test/unit/' + file + '?' + Date.now(), true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status !== 200) {
|
||||
cb(new Error('file not found or other error (' + file + ')', xhr));
|
||||
} else {
|
||||
cb(null, xhr.responseText);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function camelize(string) {
|
||||
var out = string.replace(/(?:^|[-_])(\w)/g, function(_, c) {
|
||||
return c ? c.toUpperCase() : '';
|
||||
});
|
||||
|
||||
return out[0].toLowerCase() + out.slice(1);
|
||||
}
|
||||
|
||||
const ICAL_ROOT = 'fixtures/caldav/ical/';
|
||||
|
||||
var Handlers = {
|
||||
/**
|
||||
* Load and parse an ical sample
|
||||
*
|
||||
* @param {String} file location of ical file.
|
||||
* @param {Function} node style callback: err, contents.
|
||||
*/
|
||||
ical: function icalLoader(file, callback) {
|
||||
request(ICAL_ROOT + file + '.ics', function(err, text) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, text);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function Fixtures(type) {
|
||||
var pending = 0;
|
||||
var self = this;
|
||||
var handler = Handlers[type];
|
||||
|
||||
function next() {
|
||||
if (!(--pending)) {
|
||||
if (self._error) {
|
||||
throw self._error;
|
||||
}
|
||||
self.onready();
|
||||
}
|
||||
}
|
||||
|
||||
this.load = function loadFixture(file) {
|
||||
pending++;
|
||||
handler(file, function(err, contents) {
|
||||
if (err) {
|
||||
self._error = err;
|
||||
} else {
|
||||
self[camelize(file)] = contents;
|
||||
}
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
var Helper = {
|
||||
Fixtures: Fixtures,
|
||||
|
||||
_originalExpansionLimit: null,
|
||||
|
||||
resetExpansionLimit: function() {
|
||||
if (!Helper._originalExpansionLimit) {
|
||||
IcalRecurExpansion.forEachLimit = Helper._originalExpansionLimit;
|
||||
}
|
||||
},
|
||||
|
||||
setExpansionLimit: function(newLimit) {
|
||||
if (!Helper._originalExpansionLimit) {
|
||||
Helper._originalExpansionLimit = IcalRecurExpansion.forEachLimit;
|
||||
}
|
||||
|
||||
IcalRecurExpansion.forEachLimit = newLimit;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Helper;
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue