Initial commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
var Backbone = require('backbone');
|
||||
var DataObservatoryColumnName = require('builder/data/data-observatory/column-name');
|
||||
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
|
||||
|
||||
describe('data/data-observatory/column-name', function () {
|
||||
beforeEach(function () {
|
||||
var configModel = new Backbone.Model({
|
||||
base_url: '/u/foo',
|
||||
user_name: 'foo',
|
||||
sql_api_template: 'foo',
|
||||
api_key: 'foo'
|
||||
});
|
||||
|
||||
this.nodeDefModel = new AnalysisDefinitionNodeModel({
|
||||
id: 'a1',
|
||||
type: 'data-observatory-multiple-measures',
|
||||
final_column: 'foo',
|
||||
source: 'a0'
|
||||
}, {
|
||||
configModel: configModel,
|
||||
collection: new Backbone.Collection()
|
||||
});
|
||||
|
||||
this.querySchemaModel = new Backbone.Model({
|
||||
query: 'select * from wadus'
|
||||
});
|
||||
|
||||
this.nodeDefModel.querySchemaModel = this.querySchemaModel;
|
||||
|
||||
this.columnName = new DataObservatoryColumnName({
|
||||
configModel: configModel,
|
||||
nodeDefModel: this.nodeDefModel
|
||||
});
|
||||
|
||||
spyOn(this.columnName.SQL, 'execute').and.callFake(function (query, vars, params) {
|
||||
params && params.success({
|
||||
rows: [
|
||||
{
|
||||
obs_getmeta: [{
|
||||
suggested_name: 'commuters_16_over_per_sq_km_2010_2014'
|
||||
}]
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
this.successCallback = jasmine.createSpy('successCallback');
|
||||
});
|
||||
|
||||
it('initial fetch state', function () {
|
||||
expect(this.columnName.isFetching).toBe(false);
|
||||
});
|
||||
|
||||
describe('fetch', function () {
|
||||
it('fetch without numer_id', function () {
|
||||
this.columnName.fetch({
|
||||
success: this.successCallback
|
||||
});
|
||||
|
||||
expect(this.successCallback).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('fetch with numer_id', function () {
|
||||
this.columnName.fetch({
|
||||
numer_id: 1,
|
||||
success: this.successCallback
|
||||
});
|
||||
|
||||
expect(this.successCallback).toHaveBeenCalledWith({
|
||||
rows: [
|
||||
{
|
||||
obs_getmeta: [{
|
||||
suggested_name: 'commuters_16_over_per_sq_km_2010_2014'
|
||||
}]
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('buildQueryOptions', function () {
|
||||
var options = this.columnName.buildQueryOptions({
|
||||
key: 'foo'
|
||||
});
|
||||
|
||||
expect(options).toEqual(jasmine.objectContaining({
|
||||
metadata: "'[" + JSON.stringify({key: 'foo'}) + "]'",
|
||||
query: 'select * from wadus'
|
||||
}));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
var Backbone = require('backbone');
|
||||
var FilterListView = require('builder/components/form-components/editors/data-observatory-measurements/filters-list-view');
|
||||
var FiltersCollection = require('builder/data/data-observatory/filters-collection');
|
||||
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
|
||||
|
||||
describe('data/data-observatory/filter-collection', function () {
|
||||
beforeEach(function () {
|
||||
var configModel = new Backbone.Model({
|
||||
base_url: '/u/foo',
|
||||
user_name: 'foo',
|
||||
sql_api_template: 'foo',
|
||||
api_key: 'foo'
|
||||
});
|
||||
|
||||
this.nodeDefModel = new AnalysisDefinitionNodeModel({
|
||||
id: 'a1',
|
||||
type: 'data-observatory-multiple-measures',
|
||||
final_column: 'foo',
|
||||
source: 'a0'
|
||||
}, {
|
||||
configModel: configModel,
|
||||
collection: new Backbone.Collection()
|
||||
});
|
||||
|
||||
this.querySchemaModel = new Backbone.Model({
|
||||
query: 'select * from wadus'
|
||||
});
|
||||
|
||||
this.nodeDefModel.querySchemaModel = this.querySchemaModel;
|
||||
|
||||
this.filtersCollection = new FiltersCollection([], {
|
||||
configModel: configModel,
|
||||
nodeDefModel: this.nodeDefModel
|
||||
});
|
||||
|
||||
spyOn(this.filtersCollection.SQL, 'execute').and.callFake(function (query, vars, params) {
|
||||
var payload = {
|
||||
rows: [
|
||||
{
|
||||
subsection_id: 'subsection/tags.age_gender',
|
||||
subsection_name: 'Age and Gender'
|
||||
},
|
||||
{
|
||||
subsection_id: 'subsection/us.census.acs.segments',
|
||||
subsection_name: 'US Population Segments'
|
||||
},
|
||||
{
|
||||
subsection_id: 'subsection/tags.housing',
|
||||
subsection_name: 'Housing'
|
||||
},
|
||||
{
|
||||
subsection_id: 'subsection/us.zillow.indexes',
|
||||
subsection_name: 'Zillow Home Value and Rental Indexes'
|
||||
}
|
||||
]
|
||||
};
|
||||
params && params.success(payload);
|
||||
});
|
||||
|
||||
this.filtersCollection.fetch({
|
||||
region: 'wadus'
|
||||
});
|
||||
|
||||
this.view = new FilterListView({
|
||||
filtersCollection: this.filtersCollection
|
||||
});
|
||||
|
||||
this.view.render();
|
||||
});
|
||||
|
||||
it('should render properly', function () {
|
||||
expect(this.view._listView).toBeDefined();
|
||||
expect(this.view.$('.js-back').length).toBe(1);
|
||||
});
|
||||
|
||||
it('should not have any leaks', function () {
|
||||
expect(this.view).toHaveNoLeaks();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
var Backbone = require('backbone');
|
||||
var MeasurementsCollection = require('builder/data/data-observatory/measurements-collection');
|
||||
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
|
||||
|
||||
describe('data/data-observatory/measurements-collection', function () {
|
||||
beforeEach(function () {
|
||||
var configModel = new Backbone.Model({
|
||||
base_url: '/u/foo',
|
||||
user_name: 'foo',
|
||||
sql_api_template: 'foo',
|
||||
api_key: 'foo'
|
||||
});
|
||||
|
||||
this.nodeDefModel = new AnalysisDefinitionNodeModel({
|
||||
id: 'a1',
|
||||
type: 'data-observatory-multiple-measures',
|
||||
final_column: 'foo',
|
||||
source: 'a0'
|
||||
}, {
|
||||
configModel: configModel,
|
||||
collection: new Backbone.Collection()
|
||||
});
|
||||
|
||||
this.querySchemaModel = new Backbone.Model({
|
||||
query: 'select * from wadus'
|
||||
});
|
||||
|
||||
this.nodeDefModel.querySchemaModel = this.querySchemaModel;
|
||||
|
||||
this.collection = new MeasurementsCollection([], {
|
||||
configModel: configModel,
|
||||
nodeDefModel: this.nodeDefModel
|
||||
});
|
||||
|
||||
spyOn(this.collection.SQL, 'execute').and.callFake(function (query, vars, params) {
|
||||
params && params.success({
|
||||
rows: [
|
||||
{
|
||||
numer_id: 'us.zillow.AllHomes_Zhvi',
|
||||
numer_name: 'Zillow Home Value Index for All homes',
|
||||
numer_tags: '{"subsection/tags.housing": "Housing", "license/us.zillow.zillow-license": "Zillow Terms of Use for Aggregate Data"}'
|
||||
},
|
||||
{
|
||||
numer_id: 'us.census.acs.B19083001',
|
||||
numer_name: 'Gini Index',
|
||||
numer_tags: '{"subsection/tags.income": "Income", "section/tags.united_states": "United States", "license/tags.no-restrictions": "Unrestricted"}'
|
||||
},
|
||||
{
|
||||
numer_id: 'us.census.acs.B01001002',
|
||||
numer_name: 'Male Population',
|
||||
numer_tags: '{"section/tags.united_states": "United States", "subsection/tags.age_gender": "Age and Gender", "license/tags.no-restrictions": "Unrestricted"}'
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
this.successCallback = jasmine.createSpy('successCallback');
|
||||
this.errorCallback = jasmine.createSpy('errorCallback');
|
||||
});
|
||||
|
||||
it('initial state', function () {
|
||||
expect(this.collection.getState()).toBe('unfetched');
|
||||
});
|
||||
|
||||
it('fetch', function () {
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
expect(this.successCallback).toHaveBeenCalled();
|
||||
expect(this.collection.length).toBe(3);
|
||||
expect(this.collection.getState()).toBe('fetched');
|
||||
});
|
||||
|
||||
it('model', function () {
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
var m = this.collection.at(0);
|
||||
expect(m.getValue()).toBe('us.zillow.AllHomes_Zhvi');
|
||||
expect(m.getName()).toBe('Zillow Home Value Index for All homes');
|
||||
expect(m.get('license')).toBe('Zillow Terms of Use for Aggregate Data');
|
||||
});
|
||||
|
||||
it('getSelected', function () {
|
||||
this.collection.fetch();
|
||||
|
||||
var m = this.collection.at(0);
|
||||
this.collection.setSelected(m.getValue());
|
||||
|
||||
var selected = this.collection.getSelectedItem();
|
||||
expect(selected.getValue()).toBe(m.getValue());
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
var Backbone = require('backbone');
|
||||
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
|
||||
var RegionsCollection = require('builder/data/data-observatory/regions-collection');
|
||||
|
||||
describe('data/data-observatory/regions-collection', function () {
|
||||
beforeEach(function () {
|
||||
var configModel = new Backbone.Model({
|
||||
base_url: '/u/foo',
|
||||
user_name: 'foo',
|
||||
sql_api_template: 'foo',
|
||||
api_key: 'foo'
|
||||
});
|
||||
|
||||
this.nodeDefModel = new AnalysisDefinitionNodeModel({
|
||||
id: 'a1',
|
||||
type: 'data-observatory-multiple-measures',
|
||||
final_column: 'foo',
|
||||
source: 'a0'
|
||||
}, {
|
||||
configModel: configModel,
|
||||
collection: new Backbone.Collection()
|
||||
});
|
||||
|
||||
this.nodeDefModel.queryGeometryModel = new Backbone.Model();
|
||||
this.nodeDefModel.queryGeometryModel.isFetched = function () { return true; };
|
||||
|
||||
this.querySchemaModel = new Backbone.Model({
|
||||
query: 'select * from wadus'
|
||||
});
|
||||
|
||||
var sourceNode = new Backbone.Model({
|
||||
type: 'source',
|
||||
table_name: 'wadus'
|
||||
});
|
||||
sourceNode.querySchemaModel = this.querySchemaModel;
|
||||
|
||||
this.collection = new RegionsCollection([], {
|
||||
configModel: configModel,
|
||||
nodeDefModel: this.nodeDefModel
|
||||
});
|
||||
|
||||
spyOn(this.collection.SQL, 'execute').and.callFake(function (query, vars, params) {
|
||||
params && params.success({
|
||||
rows: [
|
||||
{
|
||||
num_measurements: 2,
|
||||
region_id: 'section/tags.global',
|
||||
region_name: '"Global"'
|
||||
}, {
|
||||
num_measurements: 634,
|
||||
region_id: 'section/tags.united_states',
|
||||
region_name: '"United States"'
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
this.successCallback = jasmine.createSpy('successCallback');
|
||||
this.errorCallback = jasmine.createSpy('errorCallback');
|
||||
});
|
||||
|
||||
it('initial state', function () {
|
||||
expect(this.collection.getState()).toBe('unfetched');
|
||||
});
|
||||
|
||||
it('format quotes', function () {
|
||||
this.collection.fetch();
|
||||
expect(this.collection.at(1).getName()).toBe('United States');
|
||||
});
|
||||
|
||||
it('fetch', function () {
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
expect(this.successCallback).toHaveBeenCalled();
|
||||
expect(this.collection.length).toBe(2);
|
||||
expect(this.collection.getState()).toBe('fetched');
|
||||
});
|
||||
|
||||
it('model', function () {
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
var m = this.collection.at(0);
|
||||
expect(m.getValue()).toBe('section/tags.global');
|
||||
expect(m.getName()).toBe('Global');
|
||||
});
|
||||
|
||||
describe('setSelected', function () {
|
||||
beforeEach(function () {
|
||||
this.collection.fetch();
|
||||
});
|
||||
|
||||
it('single value', function () {
|
||||
this.collection.setSelected('section/tags.united_states');
|
||||
expect(this.collection.at(1).get('selected')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('getSelected', function () {
|
||||
this.collection.fetch();
|
||||
this.collection.setSelected('section/tags.united_states');
|
||||
var selected = this.collection.getSelectedItem();
|
||||
|
||||
expect(selected.get('selected')).toBe(true);
|
||||
expect(selected.getValue()).toBe('section/tags.united_states');
|
||||
expect(selected.getName()).toBe('United States');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
var Backbone = require('backbone');
|
||||
var TimeSpanCollection = require('builder/data/data-observatory/timespan-collection');
|
||||
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
|
||||
|
||||
describe('data/data-observatory/timespan-collection', function () {
|
||||
beforeEach(function () {
|
||||
var configModel = new Backbone.Model({
|
||||
base_url: '/u/foo',
|
||||
user_name: 'foo',
|
||||
sql_api_template: 'foo',
|
||||
api_key: 'foo'
|
||||
});
|
||||
|
||||
this.nodeDefModel = new AnalysisDefinitionNodeModel({
|
||||
id: 'a1',
|
||||
type: 'data-observatory-multiple-measures',
|
||||
final_column: 'foo',
|
||||
source: 'a0'
|
||||
}, {
|
||||
configModel: configModel,
|
||||
collection: new Backbone.Collection()
|
||||
});
|
||||
|
||||
this.querySchemaModel = new Backbone.Model({
|
||||
query: 'select * from wadus'
|
||||
});
|
||||
|
||||
this.nodeDefModel.querySchemaModel = this.querySchemaModel;
|
||||
|
||||
this.collection = new TimeSpanCollection([], {
|
||||
configModel: configModel,
|
||||
nodeDefModel: this.nodeDefModel
|
||||
});
|
||||
|
||||
spyOn(this.collection.SQL, 'execute').and.callFake(function (query, vars, params) {
|
||||
params && params.success({
|
||||
rows: [
|
||||
{
|
||||
timespan_id: '2010',
|
||||
timespan_name: '2010'
|
||||
},
|
||||
{
|
||||
timespan_id: '2015',
|
||||
timespan_name: '2015'
|
||||
},
|
||||
{
|
||||
timespan_id: '2017',
|
||||
timespan_name: '2017'
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
this.successCallback = jasmine.createSpy('successCallback');
|
||||
this.errorCallback = jasmine.createSpy('errorCallback');
|
||||
});
|
||||
|
||||
it('initial state', function () {
|
||||
expect(this.collection.getState()).toBe('unfetched');
|
||||
});
|
||||
|
||||
it('fetch', function () {
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
expect(this.successCallback).toHaveBeenCalled();
|
||||
expect(this.collection.length).toBe(3);
|
||||
expect(this.collection.getState()).toBe('fetched');
|
||||
});
|
||||
|
||||
it('first timespan as default', function () {
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
this.collection.selectFirstAsDefault();
|
||||
expect(this.collection.getSelectedItem().getValue()).toBe('2010');
|
||||
});
|
||||
|
||||
it('should not select the first item if empty', function () {
|
||||
this.collection.SQL.execute.and.callFake(function (query, vars, params) {
|
||||
params && params.success({
|
||||
rows: []
|
||||
});
|
||||
});
|
||||
|
||||
this.collection.fetch({
|
||||
success: this.successCallback,
|
||||
error: this.errorCallback
|
||||
});
|
||||
|
||||
this.collection.selectFirstAsDefault();
|
||||
expect(this.collection.getSelectedItem()).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user