Debug des scripts de test (d'où relecture du code)

This commit is contained in:
Fabrice PENHOËT 2021-10-07 12:43:29 +02:00
parent 519a3d7283
commit c8086135fe
10 changed files with 38 additions and 39 deletions

View File

@ -12,7 +12,7 @@ module.exports = function(config) {
frameworks: ["jasmine", "karma-typescript"], frameworks: ["jasmine", "karma-typescript"],
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ "src/*.ts", "tests/*.ts" , { pattern: 'tests/datas/*.csv', watched: true, included: false, served: true } ], files: [ "src/*.ts", "tests/*.ts" , { pattern: 'tests/datas/*', watched: true, included: false, served: true } ],
proxies: { "/datas/": "http://localhost:9876/base/tests/datas/" }, proxies: { "/datas/": "http://localhost:9876/base/tests/datas/" },

View File

@ -1,10 +1,10 @@
{ {
"name": "freedatas2html", "name": "freedatas2html",
"version": "0.7.0", "version": "0.7.1",
"description": "Visualization of data from various sources (CSV, API, HTML...) with filters, classification, pagination, etc.", "description": "Visualization of data from various sources (CSV, API, HTML...) with filters, classification, pagination, etc.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "karma start", "test": "clear && karma start",
"build": "webpack", "build": "webpack",
"start": "webpack serve" "start": "webpack serve"
}, },

View File

@ -185,7 +185,7 @@ export class FreeDatas2HTML
} }
} }
createDatas2Display(fields: string[], datas: any[]) : string private createDatas2Display(fields: string[], datas: any[]) : string
{ {
// Dois-je classer les données par rapport à un champ ? // Dois-je classer les données par rapport à un champ ?
if(this.datasSortedField !== undefined && this.datasSortedField.datasFieldNb !==undefined) if(this.datasSortedField !== undefined && this.datasSortedField.datasFieldNb !==undefined)

View File

@ -40,17 +40,19 @@ export class Render implements DatasRenders
if(this.settings.fieldsBegining !== undefined && this.settings.fieldDisplaying !== undefined && this.settings.fieldsEnding !== undefined ) if(this.settings.fieldsBegining !== undefined && this.settings.fieldDisplaying !== undefined && this.settings.fieldsEnding !== undefined )
{ {
datasHTML+=this.settings.fieldsBegining; datasHTML+=this.settings.fieldsBegining;
for (let i in this._converter.fields) for (let field of this._converter.fields)
datasHTML+=this.settings.fieldDisplaying.replace("#FIELDNAME", this._converter.fields[Number(i)]); datasHTML+=this.settings.fieldDisplaying.replace("#FIELDNAME", field);
datasHTML+=this.settings.fieldsEnding; datasHTML+=this.settings.fieldsEnding;
} }
datasHTML+=this.settings.linesBegining; datasHTML+=this.settings.linesBegining;
for (let row in datas) for (let row in datas)
{ {
datasHTML+=this.settings.lineBegining; datasHTML+=this.settings.lineBegining;
for(let field in datas[row]) for(let field in datas[row])
{ {
// On n'affiche que les champs attendus et signale les erreurs dans la console // On n'affiche que les champs attendus et signale les erreurs dans la console
/// REVOIR : IL FAUT QUE L'ON SOIT DANS LA BONNE COLONNE !!!!
if(this._converter.fields.indexOf(field) !== -1) if(this._converter.fields.indexOf(field) !== -1)
datasHTML+=this.settings.dataDisplaying.replace("#VALUE" , datas[row][field]).replace("#FIELDNAME" , field); datasHTML+=this.settings.dataDisplaying.replace("#VALUE" , datas[row][field]).replace("#FIELDNAME" , field);
else else

View File

@ -28,7 +28,7 @@ export class Selector implements Selectors
} }
// Ignore un séparateur de données vide // Ignore un séparateur de données vide
// Attention : pas de trim() ici, car l'espace peut être un séparateur // Attention : pas de trim(), car l'espace peut être un séparateur
set separator(separator: string|undefined) set separator(separator: string|undefined)
{ {
if(separator === "") if(separator === "")
@ -64,7 +64,7 @@ export class Selector implements Selectors
{ {
if(this._separator === undefined) if(this._separator === undefined)
{ {
let checkedValue=String(this._converter.datas[row][this.name]).trim(); // trim() nécessaire pour éviter problème de classement du tableau (sort) let checkedValue=String(this._converter.datas[row][this.name]);
if(checkedValue !== "" && this.values.indexOf(checkedValue) === -1) if(checkedValue !== "" && this.values.indexOf(checkedValue) === -1)
this.values.push(checkedValue); this.values.push(checkedValue);
} }
@ -73,7 +73,7 @@ export class Selector implements Selectors
let checkedValues=String(this._converter.datas[row][this.name]).split(this._separator); // String() car les données peuvent être des chiffres, etc. let checkedValues=String(this._converter.datas[row][this.name]).split(this._separator); // String() car les données peuvent être des chiffres, etc.
for(let i in checkedValues) for(let i in checkedValues)
{ {
let checkedValue=checkedValues[i].trim(); let checkedValue=checkedValues[i];
if(checkedValue !== "" && this.values.indexOf(checkedValue) === -1) if(checkedValue !== "" && this.values.indexOf(checkedValue) === -1)
this.values.push(checkedValue); this.values.push(checkedValue);
} }
@ -130,7 +130,7 @@ export class Selector implements Selectors
const selectedValueTxt=this.values[selectedValue] ; const selectedValueTxt=this.values[selectedValue] ;
if(this._separator === undefined) if(this._separator === undefined)
{ {
if(data[this.name].trim() !== selectedValueTxt) // retour du trim() utilisé pour créer la liste if(data[this.name] !== selectedValueTxt)
return false; return false;
else else
return true; return true;
@ -141,7 +141,7 @@ export class Selector implements Selectors
let checkedValues=String(data[this.name]).split(this._separator); let checkedValues=String(data[this.name]).split(this._separator);
for(let j in checkedValues) for(let j in checkedValues)
{ {
if(checkedValues[j].trim() === selectedValueTxt) if(checkedValues[j] === selectedValueTxt)
{ {
find=true; find=true;
break; break;

View File

@ -1,5 +1,5 @@
const { compare }= require('natural-orderby'); const { compare }=require('natural-orderby');
const errors = require("./errors.js"); const errors=require("./errors.js");
import { SortingFields } from "./freeDatas2HTMLInterfaces"; import { SortingFields } from "./freeDatas2HTMLInterfaces";
import { FreeDatas2HTML } from "./freeDatas2HTML"; import { FreeDatas2HTML } from "./freeDatas2HTML";
@ -8,10 +8,10 @@ export class SortingField implements SortingFields
_converter: FreeDatas2HTML; _converter: FreeDatas2HTML;
_fieldsDOMSelector: string; _fieldsDOMSelector: string;
_datasFieldNb: number; _datasFieldNb: number;
_order: "asc"|"desc"|undefined = undefined; _order: "asc"|"desc"|undefined=undefined;
// Injection de la classe principale, mais uniquement si le nom des champs ont été importés et affichés correctement // Injection de la classe principale, mais uniquement si le nom des champs ont été importés et affichés correctement
constructor(converter: FreeDatas2HTML, datasFieldNb: number, fieldsDOMSelector: string = "th") constructor(converter: FreeDatas2HTML, datasFieldNb: number, fieldsDOMSelector: string="th")
{ {
if(converter.fields === undefined) if(converter.fields === undefined)
throw new Error(errors.sortingFieldNeedDatas); throw new Error(errors.sortingFieldNeedDatas);
@ -28,7 +28,7 @@ export class SortingField implements SortingFields
{ {
this._converter=converter; this._converter=converter;
this._datasFieldNb=datasFieldNb; this._datasFieldNb=datasFieldNb;
this._fieldsDOMSelector= fieldsDOMSelector; this._fieldsDOMSelector=fieldsDOMSelector;
} }
} }
} }
@ -68,7 +68,7 @@ export class SortingField implements SortingFields
field._order="asc"; field._order="asc";
else else
field._order="desc"; field._order="desc";
field._converter.datasSortedField = field; field._converter.datasSortedField=field;
field._converter.refreshView(); field._converter.refreshView();
}); });
} }

View File

@ -3,7 +3,7 @@ import { FreeDatas2HTML, Pagination } from "../src/freeDatas2HTML";
const errors=require("../src/errors.js"); const errors=require("../src/errors.js");
const fixtures=require("./fixtures.js"); const fixtures=require("./fixtures.js");
xdescribe("Test de la pagination.", () => describe("Test de la pagination.", () =>
{ {
let converter: FreeDatas2HTML; let converter: FreeDatas2HTML;
let pagination: Pagination; let pagination: Pagination;

View File

@ -3,7 +3,7 @@ import { FreeDatas2HTML, Selector } from "../src/freeDatas2HTML";
const errors=require("../src/errors.js"); const errors=require("../src/errors.js");
const fixtures=require("./fixtures.js"); const fixtures=require("./fixtures.js");
xdescribe("Test des filtres de données", () => describe("Test des filtres de données", () =>
{ {
let converter: FreeDatas2HTML; let converter: FreeDatas2HTML;
let selector: Selector; let selector: Selector;
@ -59,10 +59,6 @@ xdescribe("Test des filtres de données", () =>
{ {
beforeEach( async () => beforeEach( async () =>
{ {
document.body.insertAdjacentHTML("afterbegin", fixtures.datasViewEltHTML);
converter=new FreeDatas2HTML("CSV","", { url:"http://localhost:9876/datas/datas1.csv"});
converter.datasViewElt={ id:"datas" };
await converter.run();
selector=new Selector(converter, 3, { id:"selector1" }); selector=new Selector(converter, 3, { id:"selector1" });
}); });

View File

@ -3,7 +3,7 @@ import { FreeDatas2HTML, Selector, SortingField } from "../src/freeDatas2HTML";
const errors=require("../src/errors.js"); const errors=require("../src/errors.js");
const fixtures=require("./fixtures.js"); const fixtures=require("./fixtures.js");
xdescribe("Test des champs de classement.", () => describe("Test des champs de classement.", () =>
{ {
let converter: FreeDatas2HTML; let converter: FreeDatas2HTML;
let sortingField: SortingField; let sortingField: SortingField;
@ -14,6 +14,7 @@ xdescribe("Test des champs de classement.", () =>
converter=new FreeDatas2HTML("CSV","", { url:"http://localhost:9876/datas/datas1.csv"}); converter=new FreeDatas2HTML("CSV","", { url:"http://localhost:9876/datas/datas1.csv"});
converter.datasViewElt={ id:"datas" }; converter.datasViewElt={ id:"datas" };
await converter.run(); await converter.run();
const fields=document.querySelectorAll("th");
}); });
afterEach( () => afterEach( () =>
@ -29,6 +30,13 @@ xdescribe("Test des champs de classement.", () =>
expect(() => { return new SortingField(converter, 0); }).toThrowError(errors.sortingFieldNeedDatas); expect(() => { return new SortingField(converter, 0); }).toThrowError(errors.sortingFieldNeedDatas);
}); });
it("Doit générer une erreur, si initialisé avec un numéro du champ de classement n'existant pas dans les données.", () =>
{
expect(() => { return new SortingField(converter, 9); }).toThrowError(errors.sortingFieldFieldNotFound);
expect(() => { return new SortingField(converter, -1); }).toThrowError(errors.sortingFieldFieldNotFound);
expect(() => { return new SortingField(converter, 1.1); }).toThrowError(errors.sortingFieldFieldNotFound);
});
it("Doit générer une erreur, si initialisé sans élements HTML textuels dans la page servant d'entêtes aux données.", () => it("Doit générer une erreur, si initialisé sans élements HTML textuels dans la page servant d'entêtes aux données.", () =>
{ {
expect(() => { return new SortingField(converter, 0, "th.cols"); }).toThrowError(errors.sortingsFieldNotInHTML); expect(() => { return new SortingField(converter, 0, "th.cols"); }).toThrowError(errors.sortingsFieldNotInHTML);
@ -39,13 +47,6 @@ xdescribe("Test des champs de classement.", () =>
expect(() => { return new SortingField(converter, 0, "td"); }).toThrowError(errors.sortingFieldsNbFail); expect(() => { return new SortingField(converter, 0, "td"); }).toThrowError(errors.sortingFieldsNbFail);
}); });
it("Doit générer une erreur, si initialiser avec un numéro du champ de classement n'existant pas dans les données.", () =>
{
expect(() => { return new SortingField(converter, 9); }).toThrowError(errors.sortingFieldFieldNotFound);
expect(() => { return new SortingField(converter, -1); }).toThrowError(errors.sortingFieldFieldNotFound);
expect(() => { return new SortingField(converter, 1.1); }).toThrowError(errors.sortingFieldFieldNotFound);
});
it("Si tous les paramètres sont ok, ils doivent être acceptés.", () => it("Si tous les paramètres sont ok, ils doivent être acceptés.", () =>
{ {
const sortingField=new SortingField(converter, 1, "th"); const sortingField=new SortingField(converter, 1, "th");