Skip to content

Instantly share code, notes, and snippets.

@antidiestro
Created October 8, 2015 17:06
Show Gist options
  • Save antidiestro/a39c01b077f4a3f81d5f to your computer and use it in GitHub Desktop.
Save antidiestro/a39c01b077f4a3f81d5f to your computer and use it in GitHub Desktop.
describe('Features Service', function() {
beforeEach(module('RD.services', function(RDConfigProvider) {
var fields = [
{ label: 'Marca', term: 'company', filterAs: 'collection', filter: 'humanize' },
{ label: 'Producto', term: 'product', filterAs: 'collection', filter: 'humanize' },
{ label: 'Fecha', term: 'date', filterAs: 'dateRange', filter: 'date', filterParam: 'mediumDate', preMadeFilters: 'date' },
{ label: 'Año', term: 'year', filterAs: 'collection' },
{ label: 'Mes', term: 'month', filterAs: 'collection' },
{ label: 'Día', term: 'wday', filter: 'weekDay' },
{ label: 'Region', term: 'region', filterAs: 'collection', filter: 'humanize' },
{ label: 'EDS', term: 'eds' },
{ label: 'Comuna', term: 'commune', filter: 'humanize', filterAs: 'collection' },
{ label: 'Dias sin cambios', term: 'unchanged', filterAs: 'numericRange' },
{ label: 'File', term: 'id_enex' },
{ label: 'Autoservicio', term: 'autoservice', filterAs: 'collection', filter: 'humanize', filterParam: 'boolean' },
{ label: 'Plataforma', term: 'platform', filterAs: 'collection', filter: 'humanize' },
{ label: 'Atención', term: 'attention', filterAs: 'collection', filter: 'humanize' },
{ label: 'Zona Precio', term: 'price_zone', filterAs: 'collection', filter: 'humanize' },
{ label: 'Area Precio', term: 'price_area', filterAs: 'collection', filter: 'humanize' },
{ label: 'Clasificación', term: 'classification', filterAs: 'collection', filter: 'humanize' },
{ label: 'Zona Venta', term: 'sale_zone', filterAs: 'collection', filter: 'humanize' }
];
var defaultHorizontalFields = ['product'];
var defaultVerticalFields = ['region'];
var metrics = [
{
label: 'Precio',
term: 'price',
aggregations: ['avg', 'min', 'max', 'value_count']
}
];
RDConfigProvider.setEsIndex('enex');
RDConfigProvider.setLibraryURL('highcharts','../dist/highcharts.js');
RDConfigProvider.setDefaultViewMode('table');
RDConfigProvider.setFields(fields);
RDConfigProvider.setDefaultFields(defaultHorizontalFields, defaultVerticalFields);
RDConfigProvider.setMetrics(metrics);
RDConfigProvider.setDefaultFilters([
{ term: 'date', filter: 'date.lastMonth' }
]);
RDConfigProvider.setFeaturedFilters(['date']);
}));
var RDConfig, FeaturesSrv, FieldsSrv;
beforeEach(inject(function(_RDConfig_, _FeaturesSrv_, _FieldsSrv_) {
RDConfig = _RDConfig_;
FeaturesSrv = _FeaturesSrv_;
FieldsSrv = _FieldsSrv_;
}));
var masterFields;
beforeEach(function() {
masterFields = [
{
'label': 'Marca',
'term': 'company',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [
'ABASTIBLE',
'APEX',
'ATT',
'AUTOGASCO',
'BALTOLU',
'CAVE',
'CHILIN',
'COC',
'Combustible Alhue',
'COMBUSTIBLES AMADE',
'Combustibles Endless.com',
'COMBUSTIBLES JCD',
'Combustibles Ortiz',
'COMERCIAL MAQUI',
'Coopeserau',
'COPEC',
'Cremaschi',
'CUSTOM SERVICE',
'DELPA',
'ECCO',
'ECOGREEN LTDA.',
'EL HUIQUE',
'ENERSUR S.A.',
'FACAZ',
'HN',
'HOLA!',
'J Allel',
'JLC',
'LIPIGAS',
'PETROBRAS',
'PETROJAC',
'PETRONEXT',
'PROGRESA S.A.',
'Puma Verde',
'Rafael Letelier Yañez y Cia Ltda',
'SERVICENTRO LEAL',
'SERVICENTRO SAN MIGUEL',
'SERVICENTROS RABALME',
'SESA',
'SHELL',
'Sin Bandera',
'SINHEL',
'SOCORRO',
'SUAREZ COMBUSTIBLES',
'SURENERGY',
'TERPEL',
'VIVA COMBUSTIBLES'
],
'$$hashKey': 'object:15'
},
{
'label': 'Producto',
'term': 'product',
'filterAs': 'collection',
'filter': 'humanize',
'isDefaultX': 1,
'enabled': true,
'values': [
'Gasolina 93',
'Gasolina 95',
'Gasolina 97',
'GLP Vehicular',
'GNC',
'Kerosene',
'Petroleo Diesel'
],
'$$hashKey': 'object:16'
},
{
'label': 'Fecha',
'term': 'date',
'filterAs': 'dateRange',
'filter': 'date',
'filterParam': 'mediumDate',
'preMadeFilters': [
{
'name': 'lastMonth',
'label': 'Mes Pasado',
'start': '2015-08-01',
'end': '2015-08-31'
},
{
'name': 'currentMonth',
'label': 'Este Mes',
'start': '2015-09-01',
'end': '2015-09-30'
},
{
'name': 'yesterday',
'label': 'Ayer',
'start': '2015-09-03',
'end': '2015-09-03'
},
{
'name': 'lastWeek',
'label': 'Semana pasada',
'start': '2015-08-24',
'end': '2015-08-30'
},
{
'name': '',
'label': 'Esta semana',
'start': '2015-08-31',
'end': '2015-09-06'
}
],
'enabled': true,
'defaultFilter': {
'name': 'lastMonth',
'label': 'Mes Pasado',
'start': '2015-08-01',
'end': '2015-08-31'
},
'$$hashKey': 'object:17'
},
{
'label': 'Año',
'term': 'year',
'filterAs': 'collection',
'enabled': true,
'values': [
2015
],
'$$hashKey': 'object:18'
},
{
'label': 'Mes',
'term': 'month',
'filterAs': 'collection',
'enabled': true,
'values': [
3,
4,
5,
6,
7
],
'$$hashKey': 'object:19'
},
{
'label': 'Día',
'term': 'wday',
'filter': 'weekDay',
'enabled': true,
'$$hashKey': 'object:20'
},
{
'label': 'Region',
'term': 'region',
'filterAs': 'collection',
'filter': 'humanize',
'isDefaultY': 1,
'enabled': true,
'values': [
'aisen',
'antofagasta',
'aracucania',
'arica_parinacota',
'atacama',
'bio_bio',
'coquimbo',
'los_lagos',
'los_rios',
'magallanes',
'maule',
'metropolitana',
'o_higgins',
'tarapaca',
'valparaiso'
],
'$$hashKey': 'object:21'
},
{
'label': 'EDS',
'term': 'eds',
'enabled': true,
'$$hashKey': 'object:22'
},
{
'label': 'Comuna',
'term': 'commune',
'filter': 'humanize',
'filterAs': 'collection',
'enabled': true,
'values': [
'Aisén',
'Algarrobo',
'Alhué',
'Alto Hospicio',
'Ancud',
'Andacollo',
'Angol',
'Antofagasta',
'Antuco',
'Arauco',
'Arica',
'Buin',
'Bulnes',
'Cabildo',
'Cabo de Hornos',
'Cabrero',
'Calama',
'Calbuco',
'Caldera',
'Calera',
'Calera de Tango',
'Calle Larga',
'Canela',
'Cañete',
'Carahue',
'Cartagena',
'Casablanca',
'Castro',
'Catemu',
'Cauquenes',
'Cerrillos',
'Cerro Navia',
'Chaitén',
'Chanco',
'Chañaral',
'Chépica',
'Chiguayante',
'Chile Chico',
'Chillán',
'Chillán Viejo',
'Chimbarongo',
'Chonchi',
'Cisnes',
'Cobquecura',
'Cochamó',
'Cochrane',
'Coelemu',
'Coihaique',
'Coihueco',
'Colbún',
'Colina',
'Collipulli',
'Coltauco',
'Combarbalá',
'Concepción',
'Conchalí',
'Concón',
'Constitución',
'Contulmo',
'Copiapó',
'Coquimbo',
'Coronel',
'Corral',
'Cunco',
'Curacautín',
'Curacaví',
'Curanilahue',
'Curarrehue',
'Curepto',
'Curicó',
'Dalcahue',
'Diego de Almagro',
'Doñihue',
'El Bosque',
'El Carmen',
'El Monte',
'El Quisco',
'El Tabo',
'Empedrado',
'Ercilla',
'Estación Central',
'Florida',
'Freire',
'Fresia',
'Frutillar',
'Futrono',
'Galvarino',
'Gorbea',
'Graneros',
'Hijuelas',
'Hualaihué',
'Hualañé',
'Hualpén',
'Huasco',
'Huechuraba',
'Illapel',
'Independencia',
'Iquique',
'Isla de Maipo',
'Isla de Pascua',
'La Cisterna',
'La Cruz',
'La Estrella',
'La Florida',
'La Granja',
'La Ligua',
'La Pintana',
'La Reina',
'La Serena',
'La Unión',
'Laja',
'Lampa',
'Lanco',
'Las Cabras',
'Las Condes',
'Lautaro',
'Lebu',
'Licantén',
'Limache',
'Linares',
'Litueche',
'Llaillay',
'Llanquihue',
'Lo Barnechea',
'Lo Espejo',
'Lo Prado',
'Lolol',
'Loncoche',
'Longaví',
'Lonquimay',
'Los Álamos',
'Los Andes',
'Los Ángeles',
'Los Lagos',
'Los Muermos',
'Los Sauces',
'Los Vilos',
'Lota',
'Lumaco',
'Machalí',
'Macul',
'Máfil',
'Maipú',
'Malloa',
'Marchihue',
'María Elena',
'María Pinto',
'Mariquina',
'Maule',
'Maullín',
'Mejillones',
'Melipeuco',
'Melipilla',
'Molina',
'Monte Patria',
'Mostazal',
'Mulchén',
'Nacimiento',
'Nancagua',
'Natales',
'Navidad',
'Negrete',
'Ninhue',
'Nogales',
'Nueva Imperial',
'Ñiquén',
'Ñuñoa',
'O’Higgins',
'OHiggins',
'Olivar',
'Olmué',
'Osorno',
'Ovalle',
'Padre Hurtado',
'Padre las Casas',
'Paillaco',
'Paine',
'Palena',
'Palmilla',
'Panguipulli',
'Panquehue',
'Papudo',
'Paredones',
'Parral',
'Pedro Aguirre Cerda',
'Pelarco',
'Pelluhue',
'Pemuco',
'Pencahue',
'Penco',
'Peñaflor',
'Peñalolén',
'Peralillo',
'Perquenco',
'Petorca',
'Peumo',
'Pica',
'Pichidegua',
'Pichilemu',
'Pinto',
'Pirque',
'Pitrufquén',
'Placilla',
'Porvenir',
'Pozo Almonte',
'Primavera',
'Providencia',
'Puchuncaví',
'Pucón',
'Pudahuel',
'Puente Alto',
'Puerto Montt',
'Puerto Octay',
'Puerto Varas',
'Pumanque',
'Punitaqui',
'Punta Arenas',
'Purén',
'Purranque',
'Putaendo',
'Puyehue',
'Queilén',
'Quellón',
'Quilicura',
'Quillón',
'Quillota',
'Quilpué',
'Quinchao',
'Quinta de Tilcoco',
'Quinta Normal',
'Quintero',
'Quirihue',
'Rancagua',
'Ránquil',
'Rauco',
'Recoleta',
'Renaico',
'Renca',
'Rengo',
'Requínoa',
'Retiro',
'Rinconada',
'Río Bueno',
'Río Claro',
'Río Ibáñez',
'Río Negro',
'Romeral',
'Saavedra',
'Sagrada Familia',
'Salamanca',
'San Antonio',
'San Bernardo',
'San Carlos',
'San Clemente',
'San Esteban',
'San Felipe',
'San Fernando',
'San Gregorio',
'San Ignacio',
'San Javier',
'San Joaquín',
'San José de Maipo',
'San Miguel',
'San Nicolás',
'San Pablo',
'San Pedro de Atacama',
'San Pedro de la Paz',
'San Rafael',
'San Ramón',
'San Vicente',
'Santa Bárbara',
'Santa Cruz',
'Santa Juana',
'Santa María',
'Santiago',
'Santo Domingo',
'Sierra Gorda',
'Talagante',
'Talca',
'Talcahuano',
'Taltal',
'Temuco',
'Teno',
'Teodoro Schmidt',
'Tierra Amarilla',
'Tiltil',
'Tirúa',
'Tocopilla',
'Toltén',
'Tomé',
'Traiguén',
'Tucapel',
'Valdivia',
'Vallenar',
'Valparaíso',
'Victoria',
'Vicuña',
'Vilcún',
'Villa Alegre',
'Villa Alemana',
'Villarrica',
'Viña del Mar',
'Vitacura',
'Yerbas Buenas',
'Yumbel',
'Yungay',
'Zapallar'
],
'$$hashKey': 'object:23'
},
{
'label': 'Dias sin cambios',
'term': 'unchanged',
'filterAs': 'numericRange',
'enabled': true,
'$$hashKey': 'object:24'
},
{
'label': 'File',
'term': 'id_enex',
'enabled': true,
'$$hashKey': 'object:25'
},
{
'label': 'Autoservicio',
'term': 'autoservice',
'filterAs': 'collection',
'filter': 'humanize',
'filterParam': 'boolean',
'enabled': true,
'values': [
'F',
'T'
],
'$$hashKey': 'object:26'
},
{
'label': 'Plataforma',
'term': 'platform',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [
'blanca',
'cldo',
'clrba',
'codo',
'corba',
'd61',
'dodo',
'new',
'punto',
'rba',
'shellcard'
],
'$$hashKey': 'object:27'
},
{
'label': 'Atención',
'term': 'attention',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [],
'$$hashKey': 'object:28'
},
{
'label': 'Zona Precio',
'term': 'price_zone',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [
'norte'
],
'$$hashKey': 'object:29'
},
{
'label': 'Area Precio',
'term': 'price_area',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [],
'$$hashKey': 'object:30'
},
{
'label': 'Clasificación',
'term': 'classification',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [],
'$$hashKey': 'object:31'
},
{
'label': 'Zona Venta',
'term': 'sale_zone',
'filterAs': 'collection',
'filter': 'humanize',
'enabled': true,
'values': [
0
],
'$$hashKey': 'object:32'
}
];
FieldsSrv.masterFields = masterFields;
});
describe('#resetFeatures', function() {
beforeEach(function() {
FeaturesSrv.addFeature('horizontal', _.findWhere(masterFields, { term: 'company' }));
FeaturesSrv.addFeature('vertical', _.findWhere(masterFields, { term: 'commune' }));
FeaturesSrv.resetFeatures();
});
it('removes all features', function() {
expect(FeaturesSrv.features.horizontal.length).toEqual(0);
expect(FeaturesSrv.features.vertical.length).toEqual(0);
});
it('makes all features available', function() {
var fields = FieldsSrv.masterFields;
var allFieldsEnabled = _.every(fields, function(field) {
return !!field.enabled;
});
expect(allFieldsEnabled).toBe(true);
});
});
describe('#addFeature', function() {
var horizontalField, verticalField;
beforeEach(function() {
horizontalField = _.findWhere(masterFields, { term: 'company' });
verticalField = _.findWhere(masterFields, { term: 'commune' });
});
it('adds field to horizontal features', function() {
FeaturesSrv.addFeature('horizontal', horizontalField);
expect(FeaturesSrv.features.horizontal[0]).toEqual(horizontalField);
});
it('adds field to vertical features', function() {
FeaturesSrv.addFeature('vertical', verticalField);
expect(FeaturesSrv.features.vertical[0]).toEqual(verticalField);
});
it('disables the field', function() {
FeaturesSrv.addFeature('horizontal', horizontalField);
expect(horizontalField.enabled).toBe(false);
});
});
describe('#removeFeature', function() {
var firstField, secondField;
beforeEach(function() {
firstField = _.findWhere(masterFields, { term: 'product' });
secondField = _.findWhere(masterFields, { term: 'company' });
FeaturesSrv.addFeature('horizontal', firstField);
FeaturesSrv.addFeature('horizontal', secondField);
});
it('removes field from horizontal features', function() {
FeaturesSrv.removeFeature('horizontal', 'product');
expect(FeaturesSrv.features.horizontal.indexOf(firstField)).toEqual(-1);
});
it('enables the field', function() {
expect(firstField.enabled).toEqual(false);
FeaturesSrv.removeFeature('horizontal', 'product');
expect(firstField.enabled).toEqual(true);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment