Skip to content

Commit bbe4ef1

Browse files
committed
test(e2e): fix pour pouvoir charger un chatbot qu'on définit dans le test lui-même, avec une docstring
1 parent bddbaef commit bbe4ef1

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

tests/e2e/.config/steps_file.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// in this file you can append custom step methods to 'I' object
22

3-
// on import la fonction decodeString depuis app/js/utils/strings.mjs
4-
const { encodeString } = require("../../../app/js/utils/strings.mjs");
5-
63
module.exports = function () {
74
return actor({
85
// Define custom steps here, use 'this' to access default methods of I.
@@ -12,13 +9,21 @@ module.exports = function () {
129
this.fillField("#user-input", txt);
1310
this.click("#send-button");
1411
},
15-
loadAchatbot: async function (src) {
12+
loadAchatbot: async function (src, isRaw = false) {
13+
if (isRaw) {
14+
const encodedSrc = Buffer.from(encodeURIComponent(src)).toString(
15+
"base64",
16+
);
17+
this.amOnPage(`#${encodedSrc}?raw=1`);
18+
return;
19+
}
20+
1621
if (src === "#") {
1722
this.amOnPage("");
1823
return;
1924
}
2025

21-
// Si la source commence par # suivi immédiatmeent d'un caractère qui n'est pas un espace
26+
// Si la source commence par # suivi immédiatement d'un caractère qui n'est pas un espace
2227
if (/^#\S/.test(src)) {
2328
this.amOnPage(src);
2429
return;
@@ -30,9 +35,7 @@ module.exports = function () {
3035
return;
3136
}
3237

33-
// Dernière possibilité : la source est un texte brut, on l'encode en base64 et on le passe en paramètre src)
34-
const decodedSrc = encodeString(src);
35-
this.amOnPage(decodedSrc);
38+
this.amOnPage("");
3639
},
3740
});
3841
};

tests/e2e/step_definitions/commons.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const { I } = inject();
22

3-
Given("Je lance ChatMD {string}", async (hash) => {
4-
const src = hash ? hash.trim() : "#";
5-
I.loadAchatbot(src);
3+
Given("Je lance ChatMD {string}", async (link, rawsource) => {
4+
const src = rawsource ? rawsource.content.trim() : link ? link.trim() : "#";
5+
const isRaw = rawsource && rawsource.content ? true : false;
6+
I.loadAchatbot(src, isRaw);
67
});
78

89
When("Je demande {string}", async (question) => {

0 commit comments

Comments
 (0)