Skip to content

Commit

Permalink
test: ✅ add new e2e test for expert contact path
Browse files Browse the repository at this point in the history
  • Loading branch information
nutfdt committed Oct 31, 2024
1 parent 2864b87 commit a268ca7
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apt update && apt install -y \
curl \
gcc \
patch \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# install python libraries
Expand Down
99 changes: 99 additions & 0 deletions frontend/cypress/e2e/expert-contact-path.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
describe("Expert contact path", () => {
it("should simulate expert path for police", () => {
cy.session("police_user", () => {
cy.visit("/accueil");
cy.origin("http://localhost:8080", () => {
cy.visit(
"/realms/basegun/protocol/openid-connect/auth?client_id=basegun&redirect_uri=http%3A%2F%2Flocalhost%3A5173%2Fauth%2Fcallback",
);
cy.get("#username").type("police");
cy.get("#password").type("password");
cy.get("#kc-login").click();
});
});

cy.ExpertContactPath();

cy.getByDataTestid("select-file").as("fileInput");
cy.intercept("POST", "/api/upload").as("upload");
cy.get("@fileInput").selectFile("./cypress/images/arme-low.png", {
force: true,
});
cy.wait("@upload").then(({ response }) => {
expect(response.statusCode).to.eq(200);
});
cy.getByDataTestid("expert-path").click();
cy.url().should("include", "/guide-contact");
cy.contains("span", "Contacter un expert en arme");
cy.contains("h3", "Avertissement");
cy.getByDataTestid("back-home").click();
});

it("should simulate expert path for gendarme", () => {
cy.session("gendarmerie_user", () => {
cy.visit("/accueil");
cy.origin("http://localhost:8080", () => {
cy.visit(
"/realms/basegun/protocol/openid-connect/auth?client_id=basegun&redirect_uri=http%3A%2F%2Flocalhost%3A5173%2Fauth%2Fcallback",
);
cy.get("#username").type("gendarmerie");
cy.get("#password").type("password");
cy.get("#kc-login").click();
});
});

cy.ExpertContactPath();

cy.getByDataTestid("select-file").as("fileInput");
cy.intercept("POST", "/api/upload").as("upload");
cy.get("@fileInput").selectFile("./cypress/images/arme-low.png", {
force: true,
});
cy.wait("@upload").then(({ response }) => {
expect(response.statusCode).to.eq(200);
});
cy.getByDataTestid("expert-path").click();

cy.wait(1000);
cy.url().should("include", "/guide-contact");
cy.contains("span", "Contacter un expert de l'IRCGN");
cy.getByDataTestid("situation-urgente").click();
cy.contains("span", "00 00 00 00 00");
cy.getByDataTestid("previous").click();
cy.getByDataTestid("situation-non-urgente").click();
cy.getByDataTestid("confirm-button").click();
cy.getByDataTestid("nigend").type("12345");
cy.getByDataTestid("next-button").click();
cy.getByDataTestid("una-procedure-number").type("12345");
cy.getByDataTestid("next-button").click();
cy.getByDataTestid("confirm-button").click();
cy.getByDataTestid("left-picture").selectFile(
"./cypress/images/arme-low.png",
{
force: true,
},
);
cy.getByDataTestid("right-picture").selectFile(
"./cypress/images/arme-low.png",
{
force: true,
},
);
cy.getByDataTestid("markings-pictures").selectFile(
"./cypress/images/arme-low.png",
{
force: true,
},
);
cy.getByDataTestid("magazine-picture").selectFile(
"./cypress/images/arme-low.png",
{
force: true,
},
);
cy.getByDataTestid("next-button").click();
cy.contains("h3", "Le formulaire a été envoyé avec succès !");
cy.getByDataTestid("back-home").click();
cy.url().should("contain", "/accueil");
});
});
16 changes: 16 additions & 0 deletions frontend/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,19 @@ Cypress.Commands.add("IdentificationShotgun", (typeOfMunition) => {
cy.getByDataTestid("next-step").should("not.have.attr", "disabled");
cy.getByDataTestid("next-step").click();
});

Cypress.Commands.add("ExpertContactPath", () => {
cy.visit("/accueil", {
onBeforeLoad: (win) => {
Object.defineProperty(win.navigator, "userAgent", {
value: "SAID",
});
},
});
cy.getByDataTestid("identification")
.contains("J’ai déjà mis mon arme en sécurité, je veux l’identifier")
.click();
cy.url().should("contain", "/instructions");
cy.contains("h1", "Pour un résultat optimal");
cy.contains("span", "canon vers la droite");
});
1 change: 1 addition & 0 deletions frontend/src/components/ContactExpert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
href="#"
icon="ri-alert-line"
label="Contacter un expert"
data-testid="expert-path"
@click="$router.push({ name: 'ExpertSituation' })"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const routes: RouteRecordRaw[] = [
}
});
},
meta: { title: "Formulaire contact" },
},
{
path: "/auth",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const mgr = new UserManager({
post_logout_redirect_uri: `${FRONTEND_URL}`,
response_type: "code",
scope: "openid profile email",
disablePKCE: true,
});
11 changes: 11 additions & 0 deletions frontend/src/views/GuideAskingExpertise/ExpertiseForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
class="justify-center confirm-button flex !w-full"
icon="ri-checkbox-circle-line"
label="Je confirme avoir pris connaissance des consignes"
data-testid="confirm-button"
@click="showWarning = false"
/>
</div>
Expand Down Expand Up @@ -82,6 +83,7 @@
label="NIGEND"
label-visible
required="true"
data-testid="nigend"
/>
<DsfrInput
v-model="service"
Expand Down Expand Up @@ -126,6 +128,7 @@
label="UNA / Numéro de procédure"
label-visible
required="true"
data-testid="una-procedure-number"
/>
<DsfrSelect
v-model="gun_type"
Expand Down Expand Up @@ -238,6 +241,7 @@
class="justify-center flex !w-full"
icon="ri-checkbox-circle-line"
label="Je confirme avoir pris connaissance des consignes"
data-testid="confirm-button"
@click="showModalPhotos = false"
/>
</div>
Expand All @@ -260,6 +264,7 @@
hint="Formats acceptés : .jpg, .png"
:accept="['.jpg', '.png']"
@change="handleFileChange"
data-testid="left-picture"
/>
</div>

Expand All @@ -270,6 +275,7 @@
hint="Formats acceptés : .jpg, .png"
:accept="['.jpg', '.png']"
@change="handleFileChange"
data-testid="right-picture"
/>
</div>

Expand All @@ -280,6 +286,7 @@
hint="Formats acceptés : .jpg, .png"
:accept="['.jpg', '.png']"
@change="handleFileChange"
data-testid="markings-pictures"
/>
</div>

Expand All @@ -291,6 +298,7 @@
hint="Formats acceptés : .jpg, .png"
:accept="['.jpg', '.png']"
@change="handleFileChange"
data-testid="magazine-picture"
/>

<DsfrCheckbox
Expand Down Expand Up @@ -332,6 +340,7 @@
:secondary="true"
label="Précédent"
@click="routerFooter.back"
data-testid="previous-button"
/>
<DsfrButton
class="flex justify-center !w-full"
Expand All @@ -340,13 +349,15 @@
:disabled="!areRequiredFieldsFilled() || loading"
:icon-right="true"
@click="routerFooter.next"
data-testid="next-button"
/>
</template>
<template v-else>
<DsfrButton
class="flex justify-center w-100"
icon="ri-home-4-line"
label="Retour à l'accueil"
data-testid="back-home"
@click="$router.push({ name: 'StartPage' })"
/>
</template>
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/views/GuideContactExpert/ExpertSituation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const currentPhone = computed(() => {
class="m-1 flex justify-center"
icon="ri-home-4-line"
label="Retour à l'accueil"
data-testid="back-home"
@click="$router.push({ name: 'StartPage' })"
/>
</div>
Expand All @@ -92,13 +93,15 @@ const currentPhone = computed(() => {
<DsfrButton
class="w-100 mx-auto"
label="Situation urgente"
data-testid="situation-urgente"
@click="showIRCGNModal = true"
/>
</div>
<div class="fr-col-12 fr-col-lg-6 fr-p-1v">
<DsfrButton
class="w-100 mx-auto"
label="Situation non urgente"
data-testid="situation-non-urgente"
@click="$router.push({ name: 'ExpertiseForm' })"
/>
</div>
Expand Down Expand Up @@ -126,6 +129,7 @@ const currentPhone = computed(() => {
icon="ri-arrow-left-line"
label="Précédent"
@click="showIRCGNModal = false"
data-testid="previous"
/>
</div>
</div>
Expand Down Expand Up @@ -154,6 +158,7 @@ const currentPhone = computed(() => {
class="m-1 flex justify-center"
icon="ri-home-4-line"
label="Retour à l'accueil"
data-testid="back-home"
@click="$router.push({ name: 'StartPage' })"
/>
</div>
Expand Down

0 comments on commit a268ca7

Please sign in to comment.