Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active August 29, 2015 14:17
"use strict";
describe("chartsWidgetFactory", function () {
var chartData = {
speed_graphics: {
units: {
distance: "km",
speed: "km/h",
time: "min"
},
with_respect_to_distance: [
],
with_respect_to_time: [
]
},
elevations_graphics: {
units: {
distance: "km",
elevation: "m",
time: "min"
},
with_respect_to_distance: [
],
with_respect_to_time: [
]
}
},
fakeTrackWithCharts = {
graphics: {
data: chartData
}
},
chartsWidgetFactory,
chartPoints,
trackMethods,
charts;
beforeEach(module("agora"));
beforeEach(function () {
module(function ($provide) {
$provide.constant('Charts', {
'defaultOptions': {
},
'descriptions': {
'elevations_graphics': 'charts.elevations_graphics',
'speed_graphics': 'charts.speed_graphics'
},
defaultXAxis: 'with_respect_to_distance',
defaultChartTypes: [
'elevations_graphics',
'speed_graphics',
'blabla1_graphics_that_it_is_not_in_track',
'blabla2_graphics_that_it_is_not_in_track'
],
xAxisInDistanceUnits: "with_respect_to_distance",
xAxisInTimeUnits: "with_respect_to_time"
});
});
});
beforeEach(
inject(function (_chartsWidgetFactory_, _chartPoints_, _trackMethods_) {
chartsWidgetFactory = _chartsWidgetFactory_;
chartPoints = _chartPoints_;
trackMethods = _trackMethods_;
_.extend(fakeTrackWithCharts, trackMethods);
charts = chartsWidgetFactory.create(fakeTrackWithCharts);
})
);
it("initializes its xAxis property with the value of Charts.defaultXAxis",
inject(function (Charts) {
expect(charts.xAxis).toBe(Charts.defaultXAxis);
})
);
it("initializes the chart types to only those chart types from Charts.defaultChartTypes " +
"that are included in the track charts", function () {
expect(charts.types).toEqual([
'elevations_graphics',
'speed_graphics'
]);
});
it("gets the y axis units of a given chart", function () {
expect(charts.yUnits('speed_graphics')).toBe('km/h');
expect(charts.yUnits('elevations_graphics')).toBe('m');
});
it("gets the x axis units of a given chart by delegating on track " +
"(which is augmented with trackMethods)",
inject(function (Charts) {
spyOn(fakeTrackWithCharts, "getXAxisUnits");
charts.xUnits('elevations_graphics');
expect(fakeTrackWithCharts.getXAxisUnits)
.toHaveBeenCalledWith(
'elevations_graphics',
Charts.defaultXAxis
);
})
);
it("can set the x axis property of the charts",
inject(function (Charts) {
expect(charts.xAxis).toBe(Charts.defaultXAxis);
charts.xAxisInTimeUnits();
expect(charts.xAxis).toBe(Charts.xAxisInTimeUnits);
charts.xAxisInDistanceUnits();
expect(charts.xAxis).toBe(Charts.xAxisInDistanceUnits);
})
);
it("has queries for the value of the x axis property of the charts", function () {
charts.xAxisInTimeUnits();
expect(charts.hasXAxisTimeUnits()).toBeTruthy();
expect(charts.hasXAxisDistanceUnits()).toBeFalsy();
charts.xAxisInDistanceUnits();
expect(charts.hasXAxisTimeUnits()).toBeFalsy();
expect(charts.hasXAxisDistanceUnits()).toBeTruthy();
});
it("gets the description of a given chart type",
inject(function (Charts) {
_.each(
charts.types,
function (chartType) {
expect(charts.descriptionFor(chartType))
.toBe(Charts.descriptions[chartType])
}
);
})
);
it("delegates on chartPoints to extract the points of a given chart",
inject(function (Charts) {
spyOn(chartPoints, "extractFrom");
charts.extractPointsFor('speed_graphics');
expect(chartPoints.extractFrom)
.toHaveBeenCalledWith(
fakeTrackWithCharts,
'speed_graphics',
Charts.defaultXAxis
);
})
);
it("can initialize the charts options with a given object", function () {
var someArbitraryOptions = {
whateverOption: "whatever"
},
otherCharts = chartsWidgetFactory.create(
fakeTrackWithCharts, someArbitraryOptions
);
expect(otherCharts.options).toEqual(someArbitraryOptions);
});
it("initializes the charts options to an empty object when no options are passed", function () {
expect(charts.options).toEqual({});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment