JSFiddle - React, Tailwind, and code Playground
by maciejgurban
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/kiddsoftware-jsfiddle/mocha-1.9.0.css">
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/mocha-1.9.0.js"></script>
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/chai-1.5.0.js"></script>
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/chai-jquery.js"></script>
<!-- No need to change this -->
<!-- Mocha test output goes here. -->
<div id="mocha"></div>
JavaScript
/* ACTUAL IMPLEMENTATION */
const responseToTimeseries = (response) => {
// your implementation goes here
return [];
};
// TESTS
// Configure Mocha, telling both it and chai to use BDD-style tests.
mocha.setup("bdd");
chai.should();
describe('responseToTimeseries()', () => {
describe('when receiving data for one point in time', () => {
it('returns the expected output', () => {
const input = [
{ data: [[1242362340000, 10], [1242362340001, 4]] },
];
const output = {
1242362340000: {
x: 1242362340000,
points: [10],
total: 10,
},
1242362340001: {
x: 1242362340001,
points: [4],
total: 4,
}
};
responseToTimeseries(input).should.deep.equal(output);
});
});
describe('when receiving data for multiple points in time', () => {
it('returns the expected output', () => {
const input = [
{ data: [[1242362340000, 10], [1242362340001, 4]] },
{ data: [[1242362340000, 6], [1242362340001, 9]] },
{ data: [[1242362340000, 11], [1242362340001, 13]] },
];
const output = {
1242362340000: {
x: 1242362340000,
points: [10, 6, 11],
total: 27,
},
1242362340001: {
x: 1242362340001,
points: [4, 9, 13],
total: 26,
}
};
responseToTimeseries(input).should.deep.equal(output);
});
});
describe('when some point is missing', () => {
it('returns the expected output', () => {
const input = [
{ data: [[1242362340000, 10], [1242362340001, 4], [1242362340002, 1]] },
{ data: [[1242362340000, 6], [1242362340001, 9]] },
{ data: [[1242362340000, 11], [1242362340001, 13], [1242362340002, 2]] },
];
const output = {
1242362340000: {
x: 1242362340000,
points: [10, 6, 11],
total: 27,
},
1242362340001: {
x:...