Skip to content
Snippets Groups Projects
Commit f9045f8c authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #264 - better error messages on file loading error

parent 032045f9
No related branches found
No related tags found
No related merge requests found
import { AppPage } from "./app.po";
import { Navbar } from "./navbar.po";
import { SideNav } from "./sidenav.po";
import { browser, element, by } from "protractor";
/**
* Load 4 malformed session files :
* - one having an format version too old
* - one having an empty list of modules
* - one having missing mandatory data (ex: parameter symbol)
* - one having malformed JSON syntax
* @WARNING error messages are tested in french
*/
describe("ngHyd − load malformed session files − ", () => {
let startPage: AppPage;
let navbar: Navbar;
let sidenav: SideNav;
function init() {
startPage = new AppPage();
navbar = new Navbar();
sidenav = new SideNav();
}
beforeEach(init);
it("when loading session-bad-syntax.json, displayed error should be relevant", async () => {
await startPage.navigateTo();
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-bad-syntax.json");
const err = element(by.css(".file-problem .mat-list-item-content"));
expect(await err.getText()).toContain("La syntaxe du fichier semble incorrecte");
});
it("when loading session-missing-info.json, displayed error should be relevant", async () => {
await startPage.navigateTo();
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-missing-info.json");
const err = element(by.css(".file-problem .mat-list-item-content"));
expect(await err.getText()).toContain("La syntaxe du fichier semble incorrecte");
});
it("when loading session-empty-modules-list.json, displayed error should be relevant", async () => {
await startPage.navigateTo();
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-empty-modules-list.json");
const err = element(by.css(".file-problem .mat-list-item-content"));
expect(await err.getText()).toContain("Le fichier ne contient aucun module");
});
it("when loading session-format-too-old.json, displayed error should be relevant", async () => {
await startPage.navigateTo();
await navbar.clickMenuButton();
await browser.sleep(200);
await sidenav.clickLoadSessionButton();
await browser.sleep(200);
await sidenav.loadSessionFile("./session/session-format-too-old.json", false);
const err = element(by.css(".file-problem .mat-list-item-content"));
expect(await err.getText()).toContain("Mauvaise version du format de fichier");
});
});
{
"header": {
"source": "jalhyd",
"format_version": "1.1",
"created": "2019-08-21T13:20:54.284Z"
},
"session": [
{
"children": [
{
"uid": "NnF4NT",
"props": {
"calcType": "Structure",
"structureType": "SeuilRectangulaire",
"loiDebit": "WeirSubmergedLarinier"
},
"children": [],
"parameters": [
"symbol": "h1",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "L",
"mode": "MINMAX",
"min": 0.1,
"max": 0.4,
"step": 0.015000000000000003,
"extensionStrategy": 0
},
{
"symbol": "CdWSL",
"mode": "SINGLE",
"value": 0.65
}
]
},
{
"uid": "c3ZreG",
"props": {
"calcType": "Structure",
"structureType": "SeuilRectangulaire",
"loiDebit": "WeirSubmergedLarinier"
},
"children": [],
"parameters": [
{
"symbol": "h1",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "L",
"mode": "MINMAX",
"min": 1.1,
"max": 1.4,
"step": 0.015,
"extensionStrategy": 0
},
{
"symbol": "CdWSL",
"mode": "SINGLE",
"value": 0.65
}
]
}
],
"parameters": [
{
"symbol": "Q",
"mode": "CALCUL"
},
{
"symbol": "Z1",
"mode": "SINGLE",
"value": 102
},
{
"value": 10
},
{
"symbol": "BB",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "PB",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "DH",
"mode": "MINMAX",
"min": 0.25,
"max": 1,
"step": 0.0375,
"extensionStrategy": 0
}
]
}
]
}
\ No newline at end of file
{
"header": {
"source": "jalhyd",
"format_version": "1.1",
"created": "2019-08-21T13:20:54.284Z"
},
"session": [
]
}
\ No newline at end of file
{
"header": {
"source": "jalhyd",
"format_version": "1.0.3b",
"created": "2019-08-21T13:20:54.284Z"
},
"session": [
{
"uid": "emU1Nm",
"props": {
"calcType": "Cloisons"
},
"meta": {
"title": "Cloisons"
},
"children": [
{
"uid": "NnF4NT",
"props": {
"calcType": "Structure",
"structureType": "SeuilRectangulaire",
"loiDebit": "WeirSubmergedLarinier"
},
"children": [],
"parameters": [
{
"symbol": "h1",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "L",
"mode": "MINMAX",
"min": 0.1,
"max": 0.4,
"step": 0.015000000000000003,
"extensionStrategy": 0
},
{
"symbol": "CdWSL",
"mode": "SINGLE",
"value": 0.65
}
]
},
{
"uid": "c3ZreG",
"props": {
"calcType": "Structure",
"structureType": "SeuilRectangulaire",
"loiDebit": "WeirSubmergedLarinier"
},
"children": [],
"parameters": [
{
"symbol": "h1",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "L",
"mode": "MINMAX",
"min": 1.1,
"max": 1.4,
"step": 0.015,
"extensionStrategy": 0
},
{
"symbol": "CdWSL",
"mode": "SINGLE",
"value": 0.65
}
]
}
],
"parameters": [
{
"symbol": "Q",
"mode": "CALCUL"
},
{
"symbol": "Z1",
"mode": "SINGLE",
"value": 102
},
{
"symbol": "LB",
"mode": "SINGLE",
"value": 10
},
{
"symbol": "BB",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "PB",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "DH",
"mode": "MINMAX",
"min": 0.25,
"max": 1,
"step": 0.0375,
"extensionStrategy": 0
}
]
}
]
}
\ No newline at end of file
{
"header": {
"source": "jalhyd",
"format_version": "1.1",
"created": "2019-08-21T13:20:54.284Z"
},
"session": [
{
"children": [
{
"uid": "NnF4NT",
"props": {
"calcType": "Structure",
"structureType": "SeuilRectangulaire",
"loiDebit": "WeirSubmergedLarinier"
},
"children": [],
"parameters": [
{
"symbol": "h1",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "L",
"mode": "MINMAX",
"min": 0.1,
"max": 0.4,
"step": 0.015000000000000003,
"extensionStrategy": 0
},
{
"symbol": "CdWSL",
"mode": "SINGLE",
"value": 0.65
}
]
},
{
"uid": "c3ZreG",
"props": {
"calcType": "Structure",
"structureType": "SeuilRectangulaire",
"loiDebit": "WeirSubmergedLarinier"
},
"children": [],
"parameters": [
{
"symbol": "h1",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "L",
"mode": "MINMAX",
"min": 1.1,
"max": 1.4,
"step": 0.015,
"extensionStrategy": 0
},
{
"symbol": "CdWSL",
"mode": "SINGLE",
"value": 0.65
}
]
}
],
"parameters": [
{
"symbol": "Q",
"mode": "CALCUL"
},
{
"symbol": "Z1",
"mode": "SINGLE",
"value": 102
},
{
"value": 10
},
{
"symbol": "BB",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "PB",
"mode": "SINGLE",
"value": 1
},
{
"symbol": "DH",
"mode": "MINMAX",
"min": 0.25,
"max": 1,
"step": 0.0375,
"extensionStrategy": 0
}
]
}
]
}
\ No newline at end of file
......@@ -21,10 +21,12 @@ export class SideNav {
await ncb.click();
}
async loadSessionFile(file: string) {
async loadSessionFile(file: string, click: boolean = true) {
const absolutePath = path.resolve(__dirname, file);
const input = this.getFileInput();
await input.sendKeys(absolutePath);
await this.getFileLoadButton().click();
if (click) {
await this.getFileLoadButton().click();
}
}
}
......@@ -16,7 +16,7 @@ exports.config = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--window-size=1024x768" ],
// args: [ "--headless", "--window-size=1024x768" ],
prefs: {
download: {
prompt_for_download: false,
......
......@@ -28,10 +28,10 @@
</button>
</div>
<div class="format-problem" *ngIf="fileFormatVersionProblem">
<div class="file-problem" *ngIf="fileProblem">
<mat-list role="list">
<mat-list-item role="listitem">
<mat-icon color="warn">error_outline</mat-icon> {{ uitextFileFormatVersionProblem }}
<mat-icon color="warn">error_outline</mat-icon> {{ uitextFileProblem }}
</mat-list-item>
</mat-list>
</div>
......
......@@ -18,11 +18,11 @@ mat-form-field {
}
}
.format-problem {
.file-problem {
margin-bottom: 1em;
}
.dependencies-problems, .format-problem {
.dependencies-problems, .file-problem {
.mat-list-base {
padding-top: 0;
......
......@@ -31,6 +31,12 @@ export class DialogLoadSessionComponent {
public emptyCurrentSession = false;
/** flag showing that a file loading attempt has failed */
private loadingError = false;
/** flag showing that a file loading attempt has succeeded */
private loadingComplete = false;
constructor(
public dialogRef: MatDialogRef<DialogLoadSessionComponent>,
private intlService: I18nService,
......@@ -135,6 +141,12 @@ export class DialogLoadSessionComponent {
public onFileSelected(event: any) {
if (event.target.files && event.target.files.length) {
this.file = event.target.files[0];
// reinit file infos
this.calculators = [];
this.fileFormatVersion = "";
// reinit flags
this.loadingError = false;
this.loadingComplete = false;
const formService = ServiceFactory.instance.formulaireService;
formService.calculatorInfosFromSessionFile(this.file).then(
......@@ -148,8 +160,12 @@ export class DialogLoadSessionComponent {
n.title = decode(formService.getLocalisedShortTitleFromCalculatorType(n.type));
}
}
this.loadingComplete = true;
}
);
).catch((err) => {
console.error(err);
this.loadingError = true;
});
}
}
......@@ -169,10 +185,27 @@ export class DialogLoadSessionComponent {
return ok;
}
public get fileFormatVersionProblem(): boolean {
/**
* @returns true if any problem occurred during file loading
*/
public get fileProblem(): boolean {
return (
this.loadingError
||
this.fileFormatVersionProblem()
||
this.fileIsEmpty()
);
}
private fileFormatVersionProblem(): boolean {
return this.fileFormatVersion && (this.fileFormatVersion !== this.libFormatVersion);
}
private fileIsEmpty(): boolean {
return this.loadingComplete && this.calculators.length === 0;
}
public get uitextLoad() {
return this.intlService.localizeText("INFO_OPTION_LOAD");
}
......@@ -205,11 +238,19 @@ export class DialogLoadSessionComponent {
return this.intlService.localizeText("INFO_DIALOG_EMPTY_CURRENT_SESSION");
}
public get uitextFileFormatVersionProblem() {
return sprintf(
this.intlService.localizeText("INFO_DIALOG_FORMAT_VERSIONS_MISMATCH"),
this.fileFormatVersion,
this.libFormatVersion
);
public get uitextFileProblem() {
if (this.loadingError) {
return this.intlService.localizeText("INFO_DIALOG_ERROR_LOADING_FILE");
}
if (this.fileFormatVersionProblem()) {
return sprintf(
this.intlService.localizeText("INFO_DIALOG_FORMAT_VERSIONS_MISMATCH"),
this.fileFormatVersion,
this.libFormatVersion
);
}
if (this.fileIsEmpty()) {
return this.intlService.localizeText("INFO_DIALOG_FILE_IS_EMPTY");
}
}
}
......@@ -78,6 +78,8 @@
"INFO_DIALOG_EDIT_PAB_OPTION_INTERPOLATE": "Interpolate",
"INFO_DIALOG_EDIT_PAB_TITLE": "Edit values",
"INFO_DIALOG_EMPTY_CURRENT_SESSION": "Empty current session",
"INFO_DIALOG_ERROR_LOADING_FILE": "File syntax seems incorrect",
"INFO_DIALOG_FILE_IS_EMPTY": "File contains no module",
"INFO_DIALOG_FIX_MISSING_DEPENDENCIES": "Fix missing dependencies",
"INFO_DIALOG_FORMAT_VERSIONS_MISMATCH": "File format versions mismatch (file: %s, jalhyd: %s)",
"INFO_DIALOG_LOAD_SESSION_FILENAME": "Choose a file",
......
......@@ -78,6 +78,8 @@
"INFO_DIALOG_EDIT_PAB_OPTION_INTERPOLATE": "Interpoler",
"INFO_DIALOG_EDIT_PAB_TITLE": "Modifier les valeurs",
"INFO_DIALOG_EMPTY_CURRENT_SESSION": "Vider la session courante",
"INFO_DIALOG_ERROR_LOADING_FILE": "La syntaxe du fichier semble incorrecte",
"INFO_DIALOG_FILE_IS_EMPTY": "Le fichier ne contient aucun module",
"INFO_DIALOG_FIX_MISSING_DEPENDENCIES": "Résoudre les dépendances",
"INFO_DIALOG_FORMAT_VERSIONS_MISMATCH": "Mauvaise version du format de fichier (fichier: %s, jalhyd: %s)",
"INFO_DIALOG_LOAD_SESSION_FILENAME": "Choisir un fichier",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment