diff --git a/tests/fixtures.js b/tests/fixtures.js
new file mode 100644
index 0000000..0289f8f
--- /dev/null
+++ b/tests/fixtures.js
@@ -0,0 +1,5 @@
+module.exports =
+{
+ datasViewEltHTML: '
',
+ datasHTML : 'Z (numéro atomique) | Élément | Symbole | Famille | Abondance des éléments dans la croûte terrestre (μg/k) |
---|
1 | Hydrogène | H | Non-métal | 1400000 |
2 | Hélium | He | Gaz noble | 8 |
3 | Lithium | Li | Métal alcalin | 20000 |
4 | Béryllium | Be | Métal alcalino-terreux | 2800 |
5 | Bore | B | Métalloïde | 10000 |
6 | Carbone | C | Non-métal | 200000 |
7 | Azote | N | Non-métal | 19000 |
8 | Oxygène | O | Non-métal | 461000000 |
9 | Fluor | F | Halogène | 585000 |
10 | Néon | Ne | Gaz noble | 5 |
11 | Sodium | Na | Métal alcalin | 23600000 |
12 | Magnésium | Mg | Métal alcalino-terreux | 23300000 |
13 | Aluminium | Al | Métal pauvre | 82300000 |
14 | Silicium | Si | Métalloïde | 282000000 |
15 | Phosphore | P | Non-métal | 1050000 |
16 | Soufre | S | Non-métal | 350000 |
17 | Chlore | Cl | Halogène | 145000 |
18 | Argon | Ar | Gaz noble | 3500 |
19 | Potassium | K | Métal alcalin | 20900000 |
20 | Calcium | Ca | Métal alcalino-terreux | 41500000 |
21 | Scandium | Sc | Métal de transition | 22000 |
22 | Titane | Ti | Métal de transition | 5650000 |
23 | Vanadium | V | Métal de transition | 120000 |
24 | Chrome | Cr | Métal de transition | 102000 |
25 | Manganèse | Mn | Métal de transition | 950000 |
26 | Fer | Fe | Métal de transition | 56300000 |
27 | Cobalt | Co | Métal de transition | 25000 |
28 | Nickel | Ni | Métal de transition | 84000 |
29 | Cuivre | Cu | Métal de transition | 60000 |
30 | Zinc | Zn | Métal pauvre | 70000 |
31 | Gallium | Ga | Métal pauvre | 19000 |
32 | Germanium | Ge | Métalloïde | 1500 |
33 | Arsenic | As | Métalloïde | 1800 |
34 | Sélénium | Se | Non-métal | 50 |
35 | Brome | Br | Halogène | 2400 |
36 | Krypton | Kr | gaz rare | 0,1 |
37 | Rubidium | Rb | Métal alcalin | 90000 |
38 | Strontium | Sr | Métal alcalino-terreux | 370000 |
39 | Yttrium | Y | Métal de transition | 33000 |
40 | Zirconium | Zr | Métal de transition | 165000 |
41 | Niobium | Nb | Métal de transition | 20000 |
42 | Molybdène | Mo | Métal de transition | 1200 |
43 | Technétium | Tc | Métal de transition | Traces |
44 | Ruthénium | Ru | Métal de transition | 1 |
45 | Rhodium | Rh | Métal de transition | 1 |
46 | Palladium | Pd | Métal de transition | 15 |
47 | Argent | Ag | Métal de transition | 75 |
48 | Cadmium | Cd | Métal pauvre | 150 |
49 | Indium | In | Métal pauvre | 250 |
50 | Étain | Sn | Métal pauvre | 2300 |
51 | Antimoine | Sb | Métalloïde | 200 |
52 | Tellure | Te | Métalloïde | 1 |
53 | Iode | I | Halogène | 450 |
54 | Xénon | Xe | gaz rare | 0,03 |
55 | Césium | Cs | Métal alcalin | 3000 |
56 | Baryum | Ba | Métal alcalino-terreux | 425000 |
57 | Lanthane | La | Lanthanide | 39000 |
58 | Cérium | Ce | Lanthanide | 66500 |
59 | Praséodyme | Pr | Lanthanide | 9200 |
60 | Néodyme | Nd | Lanthanide | 41500 |
61 | Prométhium | Pm | Lanthanide | Traces |
62 | Samarium | Sm | Lanthanide | 7050 |
63 | Europium | Eu | Lanthanide | 2000 |
64 | Gadolinium | Gd | Lanthanide | 6200 |
65 | Terbium | Tb | Lanthanide | 1200 |
66 | Dysprosium | Dy | Lanthanide | 5200 |
67 | Holmium | Ho | Lanthanide | 1300 |
68 | Erbium | Er | Lanthanide | 3500 |
69 | Thulium | Tm | Lanthanide | 520 |
70 | Ytterbium | Yb | Lanthanide | 3200 |
71 | Lutécium | Lu | Lanthanide | 800 |
72 | Hafnium | Hf | Métal de transition | 3000 |
73 | Tantale | Ta | Métal de transition | 2000 |
74 | Tungstène | W | Métal de transition | 1250 |
75 | Rhénium | Re | Métal de transition | 0,7 |
76 | Osmium | Os | Métal de transition | 1,5 |
77 | Iridium | Ir | Métal de transition | 1 |
78 | Platine | Pt | Métal de transition | 5 |
79 | Or | Au | Métal de transition | 4 |
80 | Mercure | Hg | Métal pauvre | 85 |
81 | Thallium | Tl | Métal pauvre | 850 |
82 | Plomb | Pb | Métal pauvre | 14000 |
83 | Bismuth | Bi | Métal pauvre | 8,5 |
84 | Polonium | Po | Métal pauvre | 200×10−9 |
85 | Astate | At | Métalloïde | Traces |
86 | Radon | Rn | Gaz noble | 400×10−12 |
87 | Francium | Fr | Métal alcalin | Traces |
88 | Radium | Ra | Métal alcalino-terreux | 900×10−6 |
89 | Actinium | Ac | Actinide | 550×10−9 |
90 | Thorium | Th | Actinide | 9600 |
91 | Protactinium | Pa | Actinide | 1,4×10−3 |
92 | Uranium | U | Actinide | 2700 |
93 | Neptunium | Np | Actinide | Traces |
94 | Plutonium | Pu | Actinide | Traces |
95 | Américium | Am | Actinide | — |
96 | Curium | Cm | Actinide | — |
97 | Berkélium | Bk | Actinide | — |
98 | Californium | Cf | Actinide | — |
99 | Einsteinium | Es | Actinide | — |
100 | Fermium | Fm | Actinide | — |
101 | Mendélévium | Md | Actinide | — |
102 | Nobélium | No | Actinide | — |
103 | Lawrencium | Lr | Actinide | — |
104 | Rutherfordium | Rf | Métal de transition | — |
105 | Dubnium | Db | Métal de transition | — |
106 | Seaborgium | Sg | Métal de transition | — |
107 | Bohrium | Bh | Métal de transition | — |
108 | Hassium | Hs | Métal de transition | — |
109 | Meitnérium | Mt | Indéfinie | — |
110 | Darmstadtium | Ds | Indéfinie | — |
111 | Roentgenium | Rg | Indéfinie | — |
112 | Copernicium | Cn | Métal de transition | — |
113 | Nihonium | Nh | Indéfinie | — |
114 | Flérovium | Fl | Indéfinie | — |
115 | Moscovium | Mc | Indéfinie | — |
116 | Livermorium | Lv | Indéfinie | — |
117 | Tennesse | Ts | Indéfinie | — |
118 | Oganesson | Og | Indéfinie | — |
',
+}
\ No newline at end of file
diff --git a/tests/freeCSV2HTMLSpec.ts b/tests/freeCSV2HTMLSpec.ts
index 9e7c397..00fe89b 100644
--- a/tests/freeCSV2HTMLSpec.ts
+++ b/tests/freeCSV2HTMLSpec.ts
@@ -1,47 +1,116 @@
import { freeCSV2HTML } from "../src/freeCSV2HTML";
const errors=require("../src/errors.js");
+const fixtures=require("./fixtures.js");
-describe("freeCSV2HTML", function()
+describe("freeCSV2HTML", () =>
{
let converter: freeCSV2HTML;
- const fixture="";
- beforeEach(function()
+ beforeEach( () =>
{
converter=new freeCSV2HTML();
- document.body.insertAdjacentHTML('afterbegin', fixture);
+ document.body.insertAdjacentHTML('afterbegin', fixtures.datasViewEltHTML);
});
- afterEach(function()
+ afterEach( () =>
{
document.body.removeChild(document.getElementById('fixture'));
});
- it("Doit être une instance de freeCSV2HTML", function()
+ it("Doit avoir créé une instance de freeCSV2HTML", () =>
{
expect(converter).toBeInstanceOf(freeCSV2HTML);
});
- describe("Setting freeCSV2HTML", function()
+ describe("Setting freeCSV2HTML", () =>
{
- it("Doit générer une erreur s'il n'y a pas d'élément dans la page pour l'id fourni pour recevoir les données.", function()
+ it("Doit générer une erreur s'il n'y a pas d'élément dans la page pour l'id fourni pour afficher les données.", () =>
{
- expect(function() { return converter.datasEltId="dontExistId"; }).toThrowError(errors.elementNotFound+"dontExistId");
+ expect( () => { return converter.datasViewElt={ id:"dontExistId" }; }).toThrowError(errors.elementNotFound+"dontExistId");
});
- it("Ne doit pas générer une erreur s'il y a un élément dans la page pour l'id fourni pour recevoir les données.", function()
+ it("Ne doit pas générer une erreur s'il y a bien un élément dans la page pour l'id fourni pour afficher les données.", () =>
{
- expect(function() { return converter.datasEltId="datas"; }).not.toThrowError();
+ expect( () => { return converter.datasViewElt={ id:"datas" }; }).not.toThrowError();
});
- it("Doit générer une erreur s'il n'y a pas d'éléments dans la page pour les ids fournis pour recevoir les sélecteurs.", function()
+ it("Doit générer une erreur s'il n'y a pas d'éléments dans la page pour chaque id fourni pour afficher un des sélecteurs.", () =>
{
- expect(function() { return converter.datasSelectors=[{ colCSV:2, idElt:"selector2"},{ colCSV:3, idElt:"selector3"}]; }).toThrowError(errors.elementNotFound+"selector3");
+ expect( () =>{ return converter.datasSelectors=[{ colCSV:2, id:"selector2"},{ colCSV:3, id:"selector3"}]; }).toThrowError(errors.elementNotFound+"selector3");
});
- it("Ne doit pas générer une erreur s'il y a bien un élément dans la page pour chaque id fourni pour recevoir un sélecteur.", function()
+ it("Doit générer une erreur si tous les numéros de colonne des sélecteurs ne sont pas des nombres naturels.", () =>
{
- expect(function() { return converter.datasSelectors=[{ colCSV:2, idElt:"selector1"},{ colCSV:3, idElt:"selector2"}]; }).not.toThrowError();
+ expect( () => { return converter.datasSelectors=[{ colCSV:2.3, id:"selector1"},{ colCSV:3, id:"selector2"}]; }).toThrowError(errors.needNaturalNumber);
+ expect( () => { return converter.datasSelectors=[{ colCSV:2, id:"selector1"},{ colCSV:-1, id:"selector2"}]; }).toThrowError(errors.needNaturalNumber);
+ });
+
+ it("Ne doit pas générer une erreur si les informations fournies pour les sélecteurs sont correctes.", () =>
+ {
+ expect( () => { return converter.datasSelectors=[{ colCSV:0, id:"selector1"},{ colCSV:3, id:"selector2"}]; }).not.toThrowError();
+ });
+
+ it("Doit générer une erreur si l'url fournie pour le fichier de données est vide.", () =>
+ {
+ expect( () => { return converter.datasSourceUrl=" "; }).toThrowError(errors.needUrl);
+ });
+ });
+
+ describe("Running freeCSV2HTML", () =>
+ {
+ it("Doit générer une erreur si au moins un des deux paramètres nécessaires au fonctionnement n'est pas fourni.", async () =>
+ {
+ await expectAsync( converter.run()).toBeRejectedWith(new Error(errors.needDatasElt));
+ converter.datasViewElt={ id:"datas" };
+ await expectAsync( converter.run()).toBeRejectedWith(new Error(errors.needUrl));
+ });
+
+ it("Doit générer une erreur si la lecture du fichier échoue.", async () =>
+ {
+ converter.datasViewElt={ id:"datas" };
+ converter.datasSourceUrl="http://localhost:9876/datas/fake.csv";
+ await expectAsync( converter.parse()).toBeRejectedWith(new Error(errors.parserFail));
+ });
+
+ it("Ne doit pas générer d'erreur si les deux paramètres fournis sont ok.", async () =>
+ {
+ converter.datasViewElt={ id:"datas" };
+ converter.datasSourceUrl="http://localhost:9876/datas/elements-chimiques.csv";
+ await expectAsync( converter.run()).toBeResolved();
+ });
+
+ it("Doit enregistrer la liste des erreurs rencontrées en parsant le fichier.", async () =>
+ {
+ converter.datasViewElt={ id:"datas" };
+ converter.datasSourceUrl="http://localhost:9876/datas/elements-chimiques-erreurs.csv";
+ await converter.parse();
+ expect(converter.parseErrors.length).toBeGreaterThan(0);
+ });
+
+ it("Ne doit enregistrer aucune erreur de lecture si le fichier est ok.", async () =>
+ {
+ converter.datasViewElt={ id:"datas" };
+ converter.datasSourceUrl="http://localhost:9876/datas/elements-chimiques.csv";
+ await converter.parse();
+ expect(converter.parseErrors.length).toEqual(0);
+ });
+
+ it("Doit afficher une erreur dans la page si aucune donnée n'a été trouvée dans le fichier.", async () =>
+ {
+ converter.datasViewElt={ id:"datas" };
+ converter.datasSourceUrl="http://localhost:9876/datas/elements-chimiques-vide.csv";
+ await converter.run();
+ let txtDatasViewsElt=document.getElementById("datas").innerHTML;
+ expect(txtDatasViewsElt).toEqual(errors.datasNotFound);
+ });
+
+ it("Doit afficher un tableau correspondant aux données du fichier csv", async () =>
+ {
+ converter.datasViewElt={ id:"datas" };
+ converter.datasSourceUrl="http://localhost:9876/datas/elements-chimiques.csv";
+ await converter.run();
+ let txtDatasViewsElt=document.getElementById("datas").innerHTML;
+ expect(txtDatasViewsElt).toEqual(fixtures.datasHTML);
});
});
});
\ No newline at end of file