var specHelper = require('../../spec-helper'); var TorqueTimesSeriesContentView = require('../../../../../javascripts/deep-insights/widgets/time-series/torque-content-view'); var WidgetModel = require('../../../../../javascripts/deep-insights/widgets/widget-model'); var HistogramChartView = require('../../../../../javascripts/deep-insights/widgets/histogram/chart'); describe('widgets/time-series/torque-content-view', function () { var widgetModel, layerModel, dataviewModel, originalData, syncOptions; var nodeId = 'a0'; function provideData () { var timeOffset = 10000; var startTime = (new Date()).getTime() - timeOffset; dataviewModel.fetch(); syncOptions.success({ bins_start: startTime, bin_width: timeOffset, bins_count: 3 }); } var createViewFn = function (options) { var vis = specHelper.createDefaultVis(); var source = vis.analysis.findNodeById(nodeId); layerModel = vis.map.layers.first(); dataviewModel = vis.dataviews.createHistogramModel({ column: 'col', source: source }); dataviewModel.sync = function (method, model, options) { syncOptions = options; }; spyOn(dataviewModel, 'fetch').and.callThrough(); originalData = dataviewModel.getUnfilteredDataModel(); originalData.set({ data: [{ bin: 10 }, { bin: 3 }], start: 0, end: 256, bins: 2 }, { silent: true }); widgetModel = new WidgetModel({ normalized: false, show_source: false }, { dataviewModel: dataviewModel, layerModel: layerModel }); spyOn(HistogramChartView.prototype, '_setupFillColor').and.returnValue('red'); var view = new TorqueTimesSeriesContentView({ model: widgetModel }); return view; }; it('should not fetch new data until unfilteredData is loaded', function () { this.view = createViewFn(); expect(dataviewModel.fetch).not.toHaveBeenCalled(); originalData.trigger('change:data', originalData); expect(dataviewModel.fetch).toHaveBeenCalled(); }); describe('.render', function () { beforeEach(function () { this.view = createViewFn(); provideData(); this.view.render(); }); it('should render properly', function () { expect(this.view.$('.js-header').length).toBe(1); expect(this.view.$('.js-torque-header').length).toBe(1); expect(this.view.$('.CDB-Widget-content--torqueTimeSeries').length).toBe(1); expect(this.view.$('.CDB-Widget-info').length).toBe(0); expect(this.view._histogramView).toBeDefined(); expect(this.view._headerView).toBeDefined(); expect(this.view._dropdownView).toBeDefined(); expect(this.view._histogramView.options.displayShadowBars).toBe(true); expect(this.view._histogramView.options.normalized).toBe(false); }); it('should render the actions dropdown', function () { this.view.$('.js-actions').click(); expect(this.view.$('.js-header .CDB-Dropdown').length).toBe(1); }); }); describe('when widget has data', function () { beforeEach(function () { this.view = createViewFn(); provideData(); }); describe('.render', function () { it('should render properly', function () { this.view.render(); expect(this.view.$('.CDB-TimeSlider').length).toEqual(1); expect(this.view.render().$el.html()).toContain('