Skip to content

Commit

Permalink
Tests para constructores de links del grafico, y restauro components.…
Browse files Browse the repository at this point in the history
…html
  • Loading branch information
pepeciavirella committed Sep 23, 2019
1 parent 3b09273 commit 7577be5
Show file tree
Hide file tree
Showing 2 changed files with 315 additions and 1 deletion.
209 changes: 208 additions & 1 deletion public/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,219 @@ <h3>Graphic: mínimo</h3></div>
window.onload = function() {
// componentes de series de tiempo

TSComponents.Card.render('ipc-card', {
serieId: '116.4_TCRZE_2015_D_36_4',
color: '#F9A822',
hasChart: 'small',
title: "Indice de Precios al Consumidor Nacional"
})

TSComponents.Card.render('exportaciones-card', {
serieId: '74.3_IET_0_M_16:percent_change_a_year_ago',
explicitSign: true,
hasChart: 'small',
title: "Exportaciones"
})

TSComponents.Card.render('superavit-card', {
serieId: '372.6_SUPERAVIT_017__23_67',
hasChart: 'small',
title: "Resultado Primario del Sector Público No Fin."
})


TSComponents.Card.render('desempleo-card', {
serieId: '42.3_EPH_PUNTUATAL_0_M_30',
color: '#EC407A',
hasChart: 'small',
title: "Desocupación"
})

TSComponents.Card.render('ipc-card-links2', {
serieId: '148.3_INIVELNAL_DICI_M_26:percent_change',
color: '#F9A822',
hasChart: 'small',
links: "small",
title: "Indice de Precios al Consumidor Nacional"
})

TSComponents.Card.render('exportaciones-card-links2', {
serieId: '74.3_IET_0_M_16:percent_change_a_year_ago',
explicitSign: true,
hasChart: 'small',
links: "small",
title: "Exportaciones"
})

TSComponents.Card.render('superavit-card-links2', {
serieId: '372.6_SUPERAVIT_017__23_67',
hasChart: 'small',
links: "small",
title: "Resultado Primario del Sector Público No Fin."
})

TSComponents.Card.render('desempleo-card-links2', {
serieId: '42.3_EPH_PUNTUATAL_0_M_30',
color: '#EC407A',
hasChart: 'small',
links: "small",
title: "Desocupación"
})

TSComponents.Card.render('ipc-card-med', {
serieId: '148.3_INIVELNAL_DICI_M_26:percent_change',
color: '#F9A822',
hasChart: 'small',
links: "none",
title: "Indice de Precios al Consumidor Nacional"
})

TSComponents.Card.render('exportaciones-card-med', {
serieId: '74.3_IET_0_M_16:percent_change_a_year_ago',
explicitSign: true,
hasChart: 'small',
links: "none",
title: "Exportaciones"
})

TSComponents.Card.render('superavit-card-med', {
serieId: '372.6_SUPERAVIT_017__23_67',
hasChart: 'small',
links: "none",
title: "Resultado Primario del Sector Público No Fin."
})

TSComponents.Card.render('desempleo-card-med', {
serieId: '42.3_EPH_PUNTUATAL_0_M_30',
color: '#EC407A',
hasChart: 'small',
links: "none",
title: "Desocupación"
})

TSComponents.Card.render('ipc-card-min', {
serieId: '148.3_INIVELNAL_DICI_M_26:percent_change',
color: '#F9A822',
links: 'none',
hasChart: "none",
title: "Indice de Precios al Consumidor Nacional"
})

TSComponents.Card.render('exportaciones-card-min', {
serieId: '74.3_IET_0_M_16:percent_change_a_year_ago',
explicitSign: true,
links: 'none',
hasChart: "none",
title: "Exportaciones"
})

TSComponents.Card.render('superavit-card-min', {
serieId: '372.6_SUPERAVIT_017__23_67',
links: 'none',
hasChart: "none",
title: "Resultado Primario del Sector Público No Fin."
})

TSComponents.Card.render('desempleo-card-min', {
serieId: '42.3_EPH_PUNTUATAL_0_M_30',
color: '#EC407A',
links: 'none',
hasChart: "none",
title: "Desocupación"
})

TSComponents.Card.render('ipc-card-min-xtreme', {
serieId: '148.3_INIVELNAL_DICI_M_26:percent_change',
links: 'none',
hasChart: "none",
title: "",
units: "",
source: ""
})

TSComponents.Card.render('exportaciones-card-min-xtreme', {
serieId: '74.3_IET_0_M_16:percent_change_a_year_ago',
explicitSign: true,
links: 'none',
hasChart: "none",
title: "",
units: "",
source: ""
})

TSComponents.Card.render('superavit-card-min-xtreme', {
serieId: '372.6_SUPERAVIT_017__23_67',
links: 'none',
hasChart: "none",
title: "",
units: "",
source: ""
})

TSComponents.Card.render('desempleo-card-min-xtreme', {
serieId: '42.3_EPH_PUNTUATAL_0_M_30',
color: '#EC407A',
links: 'none',
hasChart: "none",
title: "",
units: "",
source: ""
})

TSComponents.Graphic.render('tcrm-graphic', {
graphicUrl: 'https://apis.datos.gob.ar/series/api/series/?metadata=full&ids=143.3_NO_PR_2004_A_21:percent_change_a_year_ago,116.4_TCRZE_2015_D_36_4&limit=1000&start=0',
title: "Nivel de actividad y tipo de cambio real",
source: "Fuente: Instituto Nacional de Estadística y Censos (INDEC)",
chartTypes: { '143.3_NO_PR_2004_A_21:percent_change_a_year_ago': 'column' },
navigator: true,
seriesAxis: { '143.3_NO_PR_2004_A_21:percent_change_a_year_ago': 'right', '116.4_TCRZE_2015_D_36_4': 'right' },
decimalTooltip: 3
})

TSComponents.Graphic.render('emae-graphic-without-filters', {
graphicUrl: 'https://apis.datos.gob.ar/series/api/series/?metadata=full&ids=defensa_FAA_0006,99.3_IR_2008_0_9&limit=1000&start=0&format=json',
chartOptions: { // Override highstock configs. See https://api.highcharts.com/highstock/
},
source: "Fuente: Instituto Nacional de Estadística y Censos (INDEC)",
datePickerEnabled: false,
navigator: false,
title: "Estimador Mensual de Actividad Económica (EMAE)",
chartTypes: { 'defensa_FAA_0006': 'area', '99.3_IR_2008_0_9': 'area' },
legendLabel: { 'defensa_FAA_0006': "Fuerza Aérea", '99.3_IR_2008_0_9': "IPC" },
seriesAxis: { 'defensa_FAA_0006': 'left', '99.3_IR_2008_0_9': 'right' }
})

TSComponents.Graphic.render('ica-graphic-without-filters', {
graphicUrl: 'https://apis.datos.gob.ar/series/api/series/?ids=74.3_IET_0_M_16,74.3_IIT_0_M_25,74.3_ISC_0_M_19,307.2_SERVICIOS_IOS_0_T_51_87&collapse=year&collapse_aggregation=sum',
chartTypes: { '74.3_IET_0_M_16': 'line', '74.3_IIT_0_M_25': 'line', '74.3_ISC_0_M_19': 'column', '307.2_SERVICIOS_IOS_0_T_51_87': 'line' },
title: "Intercambio Comercial Argentino (ICA)",
navigator: false,
datePickerEnabled: false,
source: "Fuente: Instituto Nacional de Estadística y Censos (INDEC)",
seriesAxis: { '74.3_IET_0_M_16': 'left', '74.3_IIT_0_M_25': 'left', '74.3_ISC_0_M_19': 'right', '307.2_SERVICIOS_IOS_0_T_51_87': 'right'}
})

TSComponents.Graphic.render('ipc-graphic-min', {
graphicUrl: 'https://apis.datos.gob.ar/series/api/series/?ids=148.3_INIVELNAL_DICI_M_26:percent_change_a_year_ago',
navigator: false,
datePickerEnabled: false,
title: "Inflación interanual (nivel general)"
})

TSComponents.Graphic.render('rem-graphic-min', {
graphicUrl: 'https://apis.datos.gob.ar/series/api/series/?ids=430.1_MEDIANA_IP_12_M_0_0_27_96',
navigator: false,
datePickerEnabled: false,
title: "REM mediana de expectativas de inflación a 12 meses"
})

TSComponents.Graphic.render('tcbna-graphic-min', {
graphicUrl: 'https://apis.datos.gob.ar/series/api/series/?ids=168.1_T_CAMBIOR_D_0_0_26',
navigator: false,
datePickerEnabled: false,
title: "Tipo de Cambio Vendedor (BNA)"
})


}
</script>
<script type='text/javascript' src='assets/js/components.js'></script>
Expand Down
107 changes: 107 additions & 0 deletions src/tests/components/helpers/GraphicLinkBuilders.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { urlToString, cleanUrl, csvShareURL, jsonShareURL } from "../../../helpers/graphic/graphicLinkBuilders";

describe('Link building functions for Dropdown components of the Card component', () => {

describe('Conversion of URL ASCII keys to characters upon it', () => {

let url: string;
let expectedString: string;

it("Replacement for the ',' character", () => {
url = "https://datos.gob.ar/series/api/series/?ids=tmi_arg%2C116.4_TCRZE_2015_D_36_4";
expectedString = "https://datos.gob.ar/series/api/series/?ids=tmi_arg,116.4_TCRZE_2015_D_36_4";
expect(urlToString(url)).toEqual(expectedString);
});
it("Replacement for the ':' character", () => {
url = "https%3A//datos.gob.ar/series/api/series/?ids=tmi_arg%3Apercent_change";
expectedString = "https://datos.gob.ar/series/api/series/?ids=tmi_arg:percent_change";
expect(urlToString(url)).toEqual(expectedString);
});
it("Replacement for the '/' character", () => {
url = "https:%2F%2Fdatos.gob.ar%2Fseries%2Fapi/series";
expectedString = "https://datos.gob.ar/series/api/series";
expect(urlToString(url)).toEqual(expectedString);
});
it("Replacement for the '?' character", () => {
url = "https://datos.gob.ar/series/api/series/%3Fids=105.1_I2QS_2016_M_20&metadata=full";
expectedString = "https://datos.gob.ar/series/api/series/?ids=105.1_I2QS_2016_M_20&metadata=full";
expect(urlToString(url)).toEqual(expectedString);
});
it("Replacement for multiple characters at a time", () => {
url = "https%3A/%2Fdatos.gob.ar/series%2Fapi/series%2F%3Fids=tmi_arg%2C116.4_TCRZE_2015_D_36_4";
expectedString = "https://datos.gob.ar/series/api/series/?ids=tmi_arg,116.4_TCRZE_2015_D_36_4";
expect(urlToString(url)).toEqual(expectedString);
});


})

describe('Removal of the chartType from an URL, in order to clean it', () => {

let originalURL: string;
let cleanedUrl: string;

beforeAll(() => {
cleanedUrl = "https://datos.gob.ar/series/api/series/?ids=Automotriz_patentamiento_67YQ7B&representation_mode=change";
})

it("If the URL has no chartType, there is no cleaning at all", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=Automotriz_patentamiento_67YQ7B&representation_mode=change";
expect(cleanUrl(originalURL)).toEqual(cleanedUrl);
});
it("If the URL has a chartType query param, it is removed", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=Automotriz_patentamiento_67YQ7B&chartType=area&representation_mode=change";
expect(cleanUrl(originalURL)).toEqual(cleanedUrl);
});

})

describe('Generation of the CSV file link to be shared', () => {

let originalURL: string;
let csvURL: string;

beforeAll(() => {
csvURL = "https://datos.gob.ar/series/api/series/?ids=tmi_arg&format=csv";
})

it("If the original URL has a metadata query param, it is removed", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=tmi_arg&metadata=full";
expect(csvShareURL(originalURL)).toEqual(csvURL);
});
it("If the URL has a start query param, it is removed", () => {
originalURL = "https://datos.gob.ar/series/api/series/?start=0&ids=tmi_arg";
expect(csvShareURL(originalURL)).toEqual(csvURL);
});
it("If the original URL has a chartType query param, it is removed", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=tmi_arg&chartType=column";
expect(csvShareURL(originalURL)).toEqual(csvURL);
});
it("If the original URL has no removable query param, only the format is appended", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=tmi_arg";
expect(csvShareURL(originalURL)).toEqual(csvURL);
});

})

describe('Generation of the JSON file link to be shared', () => {

let originalURL: string;
let jsonURL: string;

beforeAll(() => {
jsonURL = "https://datos.gob.ar/series/api/series/?ids=440.1_ADMI_PUBLIRIA_2004_0_52_35&format=json";
})

it("If the original URL has a chartType query param, it is removed", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=440.1_ADMI_PUBLIRIA_2004_0_52_35&chartType=column";
expect(jsonShareURL(originalURL)).toEqual(jsonURL);
});
it("If the original URL has no removable query param, only the format is appended", () => {
originalURL = "https://datos.gob.ar/series/api/series/?ids=440.1_ADMI_PUBLIRIA_2004_0_52_35";
expect(jsonShareURL(originalURL)).toEqual(jsonURL);
});

})

})

0 comments on commit 7577be5

Please sign in to comment.