diff --git a/cypress/e2e/account.cy.ts b/cypress/e2e/account.cy.ts deleted file mode 100644 index efae7b169..000000000 --- a/cypress/e2e/account.cy.ts +++ /dev/null @@ -1,502 +0,0 @@ -import * as auditJson from "../fixtures/audit.json"; - -describe("Account", () => { - describe("Account management", () => { - describe("User can create a new account", () => { - beforeEach(() => { - const email = `john-doe-${Math.random()}@example.com`; - cy.wrap(email).as("email"); - - cy.visit("http://localhost:3000"); - cy.contains("a", "Créer un compte").click(); - cy.getByLabel("Adresse e-mail").type(email); - cy.getByLabel("Mot de passe").type("pouetpouetpouet"); - cy.contains("button", "Valider").click(); - cy.contains("h1", "Consultez votre boite de réception"); - cy.contains( - "Un lien pour confirmer votre adresse e-mail vient de vous être envoyé à l’adresse" - ); - cy.contains(email); - }); - - it("(verification link)", () => { - cy.get("@email").then((email) => { - // Simulate receiving the verification link by email. - cy.request( - "POST", - "http://localhost:3000/api/tests/verification-token", - { - username: email - } - ) - .its("body") - .then((verificationToken) => { - const verificationLink = `http://localhost:3000/compte/validation?token=${verificationToken}`; - cy.visit(verificationLink); - }); - - cy.contains("Votre compte a bien été créé"); - cy.getByLabel("Adresse e-mail").should("have.value", email); - }); - }); - - it("(same tab, account verified elsewhere)", () => { - cy.get("@email").then((email) => { - // Simulate the account being verified in another tab - cy.request( - "POST", - "http://localhost:3000/api/tests/verification-token", - { - username: email - } - ) - .its("body") - .then((verificationToken) => { - cy.request("POST", "/api/auth/verify", { - token: verificationToken - }); - }); - - cy.contains("h1", "Votre compte a bien été créé", { - timeout: 8000 - }); - - cy.contains("a", "Aller à la page de connexion").click(); - cy.contains("Votre compte a bien été créé"); - cy.getByLabel("Adresse e-mail").should("have.value", email); - }); - }); - }); - - it("User can not create account with already taken email", () => { - cy.createTestAccount().then(({ username }) => { - cy.visit("http://localhost:3000"); - cy.contains("a", "Créer un compte").click(); - cy.getByLabel("Adresse e-mail").type(username); - cy.getByLabel("Mot de passe").type("blablablablablabla"); - cy.contains("button", "Valider").click(); - cy.contains( - "Cette adresse e-mail est déjà associée à un compte. Connectez-vous." - ); - cy.getByLabel("Adresse e-mail").should("have.focus"); - }); - }); - - it("User can not create account with expired verification token", () => { - cy.visit("http://localhost:3000/compte/validation?token=pouet"); - cy.contains("h1", "Désolé, votre lien n’est plus valide"); - }); - - it("User can sign in with their account", () => { - cy.createTestAccount().then(({ username, password }) => { - cy.visit("http://localhost:3000/compte/connexion"); - cy.getByLabel("Adresse e-mail").type(username); - cy.getByLabel("Mot de passe").type(password); - cy.contains("button", "Se connecter").click(); - cy.contains("h1", "Mes audits"); - }); - }); - - it("User can update their user profile infos", () => { - cy.createTestAccount({ login: true }).then(({ username }) => { - cy.createTestAudit({ auditorEmail: username, isComplete: true }); - - cy.visit("http://localhost:3000/compte"); - cy.contains("button", username).click(); - cy.contains("a", "Mon compte").click(); - - cy.getByLabel("Prénom et nom (optionnel)").type("John Doe"); - cy.contains("Mettre à jour").click(); - - cy.contains("Profil mis à jour avec succès"); - - // Check that user audits have updated auditorName - cy.contains("a", "Mes audits").click(); - cy.contains("button", "Actions").click(); - cy.contains("a", "Consulter le rapport").invoke("removeAttr", "target").click(); - cy.contains("Auditeur ou auditrice : John Doe"); - }); - }); - - it("User can update their password", () => { - cy.createTestAccount({ login: true }).then(({ username, password }) => { - cy.visit("http://localhost:3000/compte/parametres"); - - const newPassword = "totototototo"; - - cy.contains("button", "Changer de mot de passe").click(); - cy.getByLabel("Mot de passe actuel").type(password); - cy.getByLabel("Nouveau mot de passe").type(newPassword); - cy.contains("button", "Changer de mot de passe").click(); - - cy.contains("Votre mot de passe a été mis à jour avec succès"); - - cy.contains("button", username).click(); - cy.contains("button", "Me déconnecter").click(); - - cy.contains("Vous avez été deconnecté avec succès."); - - cy.getByLabel("Adresse e-mail").type(username); - cy.getByLabel("Mot de passe").type(password); - cy.contains("button", "Se connecter").click(); - - cy.contains("L’adresse e-mail ou le mot de passe saisi est incorrect. Vérifiez vos saisies."); - - cy.getByLabel("Adresse e-mail").clear().type(username); - cy.getByLabel("Mot de passe").clear().type(newPassword); - cy.contains("button", "Se connecter").click(); - - cy.contains("h1", "Mes audits"); - }); - }); - - it("User can reset their password", () => { - cy.createTestAccount().then(({ username, password }) => { - cy.visit("http://localhost:3000/compte/connexion"); - cy.contains("a", "Mot de passe oublié").click(); - cy.getByLabel("Adresse e-mail").type(username); - cy.contains("button", "Valider").click(); - cy.contains( - `Un lien pour réinitialiser votre mot de passe vient de vous être envoyé par e-mail à l’adresse :` - ); - cy.contains(username); - - cy.request( - "POST", - "http://localhost:3000/api/tests/password-reset-verification-token", - { username } - ).then((resp) => { - const verificationLink = `http://localhost:3000/compte/reinitialiser-mot-de-passe?token=${resp.body}`; - cy.visit(verificationLink); - - const newPassword = "blablablabla"; - - cy.contains("h1", "Changer de mot de passe"); - cy.getByLabel("Mot de passe").type(newPassword); - cy.contains("button", "Changer de mot de passe").click(); - - cy.contains("Votre mot de passe a été mis à jour avec succès"); - - // Try login with old password - cy.getByLabel("Mot de passe").type(password); - cy.contains("button", "Se connecter").click(); - cy.contains("L’adresse e-mail ou le mot de passe saisi est incorrect. Vérifiez vos saisies."); - - // Login with new password - cy.getByLabel("Mot de passe").clear().type(newPassword); - cy.contains("button", "Se connecter").click(); - cy.contains("h1", "Mes audits"); - }); - }); - }); - - it("User can reset their password (logged in)", () => { - cy.createTestAccount({ login: true }).then(({ username }) => { - cy.visit("http://localhost:3000/compte/parametres"); - cy.contains("Changer de mot de passe").click(); - cy.contains("Mot de passe oublié ?").click(); - - cy.contains( - "Un lien pour réinitialiser votre mot de passe vient de vous être envoyé par e-mail à l’adresse :" - ); - cy.contains(username); - - cy.request( - "POST", - "http://localhost:3000/api/tests/password-reset-verification-token", - { username } - ).then((resp) => { - const verificationLink = `http://localhost:3000/compte/reinitialiser-mot-de-passe?token=${resp.body}`; - cy.visit(verificationLink); - - const newPassword = "blablablabla"; - - cy.contains("h1", "Changer de mot de passe"); - cy.getByLabel("Mot de passe").type(newPassword); - cy.contains("button", "Changer de mot de passe").click(); - - cy.location("pathname").should("eq", "/compte"); - cy.contains("Votre mot de passe a été mis à jour avec succès"); - }); - }); - }); - - it("User can update their email address", () => { - cy.createTestAccount({ login: true }).then(({ password, uid }) => { - cy.visit("http://localhost:3000/compte/parametres"); - - const newEmail = `john-smith${Math.random()}@example.com`; - cy.contains("button", "Changer d’adresse e-mail").click(); - cy.getByLabel("Mot de passe").type(password); - cy.getByLabel("Nouvelle adresse e-mail").type(newEmail); - cy.contains("button", "Changer d’adresse e-mail").click(); - - cy.contains( - `Un lien pour confirmer votre nouvelle adresse e-mail vient de vous être envoyé à l’adresse suivante : ${newEmail}` - ); - - // Simulate receiving the verification link by email. - cy.request( - "POST", - "http://localhost:3000/api/tests/email-update-verification-token", - { uid } - ).then((resp) => { - const verificationLink = `http://localhost:3000/compte/email-update-validation?token=${resp.body.token}`; - cy.visit(verificationLink); - - cy.contains(`Votre adresse email : ${newEmail}`); - cy.contains("Votre adresse e-mail a été mise à jour"); - }); - }); - }); - - it("User can delete their account", () => { - cy.createTestAccount({ login: true }).then(({ username, password }) => { - cy.createTestAudit({ auditorEmail: username }).then(({ editId }) => { - cy.visit("http://localhost:3000/compte/parametres"); - - // Delete account form - cy.contains("button", "Supprimer mon compte").click(); - cy.getByLabel( - "Saisissez la phrase suivante pour confirmer la suppression de votre compte : je confirme vouloir supprimer mon compte" - ).type("je confirme vouloir supprimer mon compte"); - cy.getByLabel("Mot de passe").type(password); - cy.contains("button", "Supprimer mon compte").click(); - cy.contains( - "Vous avez été déconnecté et votre compte a été supprimé avec succès" - ); - - // FIXME: make this work locally - // Submit feedback form - // cy.getByLabel( - // "Pourriez-vous nous donner la raison de votre départ ?" - // ).type("Quoi ? Ça n’est pas un outil d’audit automatique ⁈"); - // cy.contains("button", "Envoyer mon avis").click(); - // cy.contains("Votre avis a bien été envoyé"); - - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.contains("Désolé, l’audit que vous cherchez a été supprimé."); - }); - }); - }); - }); - - describe("Audits list", () => { - // Create an logged in account and 4 associated audits (1 completed, 1 pristine and 2 in progress) - beforeEach(() => { - cy.createTestAccount({ login: true }).then(({ username }) => { - cy.createTestAudit({ auditorEmail: username, isComplete: true, fillStatement: true }); - cy.createTestAudit({ auditorEmail: username, isPristine: true }); - cy.createTestAudit({ auditorEmail: username }); - cy.createTestAudit({ auditorEmail: username }).as("audit"); - cy.visit("http://localhost:3000/compte"); - }); - }); - it("User can access all their audits", () => { - cy.contains("En cours (3)"); - cy.contains("Terminé (1)"); - - const expectedLabels = [ - "Continuer l’audit", - "Continuer l’audit", - "Commencer l’audit", - "Accéder à l’audit" - ]; - - cy.get(".audit-main-action").each(($el, i) => { - expect($el.text()).to.contain(expectedLabels[i]); - }); - }); - - it("User can start audit with prefilled infos", () => { - // FIXME: export function? - function fillPageField( - pageIndex: number, - field: string, - content: string - ) { - cy.contains(`Page ${pageIndex}`) - .parent() - .parent() - .contains(field) - .parent() - .find("input") - .clear() - .type(content); - } - - // Create a new audit but auditor email field should not be present - cy.contains("a", "Démarrer un nouvel audit").click(); - - cy.contains("106 critères").click(); - - cy.contains("Nom du site ou du service à auditer") - .parent() - .find("input") - .type(auditJson.procedureName); - - cy.contains("button", "Étape suivante").click(); - cy.contains("button", "Ajouter une page").click(); - - fillPageField(1, "Nom de la page", auditJson.pages[0].name); - fillPageField(1, "URL de la page", auditJson.pages[0].url); - fillPageField(2, "Nom de la page", auditJson.pages[1].name); - fillPageField(2, "URL de la page", auditJson.pages[1].url); - fillPageField(3, "Nom de la page", auditJson.pages[2].name); - fillPageField(3, "URL de la page", auditJson.pages[2].url); - fillPageField(4, "Nom de la page", auditJson.pages[3].name); - fillPageField(4, "URL de la page", auditJson.pages[3].url); - fillPageField(5, "Nom de la page", auditJson.pages[4].name); - fillPageField(5, "URL de la page", auditJson.pages[4].url); - fillPageField(6, "Nom de la page", auditJson.pages[5].name); - fillPageField(6, "URL de la page", auditJson.pages[5].url); - fillPageField(7, "Nom de la page", auditJson.pages[6].name); - fillPageField(7, "URL de la page", auditJson.pages[6].url); - fillPageField(8, "Nom de la page", auditJson.pages[7].name); - fillPageField(8, "URL de la page", auditJson.pages[7].url); - - cy.contains("button", "Étape suivante").click(); - - cy.contains("button", "Ignorer cette étape").click(); - - cy.getByLabel("Prénom et nom (optionnel)").type(auditJson.auditorName); - - cy.contains("button", "Valider les paramètres").click(); - - cy.contains("h1", auditJson.procedureName); - - // Create new audit but in only 2 steps (step 3 auto-filled) - cy.contains("a", "Mes audits").click(); - - cy.contains("a", "Démarrer un nouvel audit").click(); - - cy.contains("106 critères").click(); - - cy.contains("Nom du site ou du service à auditer") - .parent() - .find("input") - .type(auditJson.procedureName); - - cy.contains("button", "Étape suivante").click(); - cy.contains("button", "Ajouter une page").click(); - - fillPageField(1, "Nom de la page", auditJson.pages[0].name); - fillPageField(1, "URL de la page", auditJson.pages[0].url); - fillPageField(2, "Nom de la page", auditJson.pages[1].name); - fillPageField(2, "URL de la page", auditJson.pages[1].url); - fillPageField(3, "Nom de la page", auditJson.pages[2].name); - fillPageField(3, "URL de la page", auditJson.pages[2].url); - fillPageField(4, "Nom de la page", auditJson.pages[3].name); - fillPageField(4, "URL de la page", auditJson.pages[3].url); - fillPageField(5, "Nom de la page", auditJson.pages[4].name); - fillPageField(5, "URL de la page", auditJson.pages[4].url); - fillPageField(6, "Nom de la page", auditJson.pages[5].name); - fillPageField(6, "URL de la page", auditJson.pages[5].url); - fillPageField(7, "Nom de la page", auditJson.pages[6].name); - fillPageField(7, "URL de la page", auditJson.pages[6].url); - fillPageField(8, "Nom de la page", auditJson.pages[7].name); - fillPageField(8, "URL de la page", auditJson.pages[7].url); - - cy.contains("button", "Étape suivante").click(); - - cy.contains("button", "Valider les paramètres").click(); - - cy.contains("h1", "Audit"); - }); - - it("User can duplicate audit", () => { - cy.contains("button", "Actions").click(); - cy.contains("button", "Dupliquer l’audit").click(); - - cy.getByLabel("Nom de la copie").type("Audit de mon petit site (2)"); - cy.get("dialog").contains("button", "Dupliquer l’audit").click(); - - cy.contains("Audit « Audit de mon petit site (2) » créé", { timeout: 50_000 }); - cy.contains("button", "Accéder à l’audit").click(); - - cy.contains("h1 + p", "Audit de mon petit site (2)"); - }); - - it("User can copy report link", () => { - cy.contains("button", "Actions").click(); - cy.contains("button", "Copier le lien du rapport").click(); - cy.get("@audit").then((audit) => { - cy.assertClipboardValue( - // @ts-ignore - // TODO: remove `@ts-ignore` when the following issue is fixed: - // "feat: [Add Typescript support for Aliases #8762"](https://github.com/cypress-io/cypress/issues/8762) - `http://localhost:3000/rapport/${audit.reportId}` - ); - cy.contains("span", "Lien du rapport copié"); - }); - }); - - it("User can copy statement link", () => { - cy.visit("http://localhost:3000/compte"); - - cy.get(".dropdown-container:last").contains("button", "Actions").click(); - cy.contains("button", "Copier le lien de la déclaration").click(); - - cy.get("@audit").then((audit) => { - cy.assertClipboardValue( - // @ts-ignore - // TODO: remove `@ts-ignore` when the following issue is fixed: - // "feat: [Add Typescript support for Aliases #8762"](https://github.com/cypress-io/cypress/issues/8762) - `http://localhost:3000/declaration/${audit.reportId}` - ); - cy.contains("span", "Lien de la déclaration copié"); - }); - }); - - it("User can download audit", () => { - cy.exec("rm -rf cypress/downloads"); - - cy.contains("Actions").click(); - cy.contains("Télécharger l’audit").click(); - - cy.readFile("cypress/downloads/audit-audit-de-mon-petit-site.csv"); - }); - - it("User can delete audit", () => { - cy.contains("Actions").click(); - cy.contains("Supprimer l’audit").click(); - - cy.get("dialog").contains("button", "Supprimer définitivement l’audit").click(); - - cy.contains("Audit « Audit de mon petit site » supprimé"); - }); - - it("User can transfer an audit", () => { - const newEmail = "example@domain.com"; - - cy.contains("button", "Actions").click(); - cy.contains("button", "Transférer l’audit").click(); - - // Fill form - cy.getByLabel("Adresse e-mail du destinataire") - .clear() - .type(newEmail); - cy.getByLabel("Confirmer e-mail du destinataire") - .clear() - .type(newEmail); - cy.contains("button[type='submit']", "Transférer l’audit").click(); - - // Assert audit is gone (3 audits left) - cy.get(".audits-list .audit-name").should("have.length", 3); - cy.contains("a", "Audit de mon petit site").should("be.focused"); - cy.contains("Audit « Audit de mon petit site » transféré"); - cy.contains(`Lien d’accès envoyé à ${newEmail}`); - - // Logout and check auditorEmail in audit parameters - cy.get(".account-header button[aria-expanded]").click(); - cy.contains("button", "Me déconnecter").click(); - cy.get("@audit").then(audit => { - // @ts-ignore - // TODO: remove `@ts-ignore` when the following issue is fixed: - // "feat: [Add Typescript support for Aliases #8762"](https://github.com/cypress-io/cypress/issues/8762) - cy.visit(`http://localhost:3000/audits/${audit.editId}/parametres`); - cy.getByLabel("Adresse e-mail").should("have.value", newEmail); - }); - }); - }); -}); diff --git a/cypress/e2e/account/account-management.cy.ts b/cypress/e2e/account/account-management.cy.ts new file mode 100644 index 000000000..1dbe5b9c0 --- /dev/null +++ b/cypress/e2e/account/account-management.cy.ts @@ -0,0 +1,279 @@ +describe("Account management", () => { + describe("User can create a new account", () => { + beforeEach(() => { + const email = `john-doe-${Math.random()}@example.com`; + cy.wrap(email).as("email"); + + cy.visit("http://localhost:3000"); + cy.contains("a", "Créer un compte").click(); + cy.getByLabel("Adresse e-mail").type(email); + cy.getByLabel("Mot de passe").type("pouetpouetpouet"); + cy.contains("button", "Valider").click(); + cy.contains("h1", "Consultez votre boite de réception"); + cy.contains( + "Un lien pour confirmer votre adresse e-mail vient de vous être envoyé à l’adresse" + ); + cy.contains(email); + }); + + it("(verification link)", () => { + cy.get("@email").then((email) => { + // Simulate receiving the verification link by email. + cy.request( + "POST", + "http://localhost:3000/api/tests/verification-token", + { + username: email + } + ) + .its("body") + .then((verificationToken) => { + const verificationLink = `http://localhost:3000/compte/validation?token=${verificationToken}`; + cy.visit(verificationLink); + }); + + cy.contains("Votre compte a bien été créé"); + cy.getByLabel("Adresse e-mail").should("have.value", email); + }); + }); + + it("(same tab, account verified elsewhere)", () => { + cy.get("@email").then((email) => { + // Simulate the account being verified in another tab + cy.request( + "POST", + "http://localhost:3000/api/tests/verification-token", + { + username: email + } + ) + .its("body") + .then((verificationToken) => { + cy.request("POST", "/api/auth/verify", { + token: verificationToken + }); + }); + + cy.contains("h1", "Votre compte a bien été créé", { + timeout: 8000 + }); + + cy.contains("a", "Aller à la page de connexion").click(); + cy.contains("Votre compte a bien été créé"); + cy.getByLabel("Adresse e-mail").should("have.value", email); + }); + }); + }); + + it("User can not create account with already taken email", () => { + cy.createTestAccount().then(({ username }) => { + cy.visit("http://localhost:3000"); + cy.contains("a", "Créer un compte").click(); + cy.getByLabel("Adresse e-mail").type(username); + cy.getByLabel("Mot de passe").type("blablablablablabla"); + cy.contains("button", "Valider").click(); + cy.contains( + "Cette adresse e-mail est déjà associée à un compte. Connectez-vous." + ); + cy.getByLabel("Adresse e-mail").should("have.focus"); + }); + }); + + it("User can not create account with expired verification token", () => { + cy.visit("http://localhost:3000/compte/validation?token=pouet"); + cy.contains("h1", "Désolé, votre lien n’est plus valide"); + }); + + it("User can sign in with their account", () => { + cy.createTestAccount().then(({ username, password }) => { + cy.visit("http://localhost:3000/compte/connexion"); + cy.getByLabel("Adresse e-mail").type(username); + cy.getByLabel("Mot de passe").type(password); + cy.contains("button", "Se connecter").click(); + cy.contains("h1", "Mes audits"); + }); + }); + + it("User can update their user profile infos", () => { + cy.createTestAccount({ login: true }).then(({ username }) => { + cy.createTestAudit({ auditorEmail: username, isComplete: true }); + + cy.visit("http://localhost:3000/compte"); + cy.contains("button", username).click(); + cy.contains("a", "Mon compte").click(); + + cy.getByLabel("Prénom et nom (optionnel)").type("John Doe"); + cy.contains("Mettre à jour").click(); + + cy.contains("Profil mis à jour avec succès"); + + // Check that user audits have updated auditorName + cy.contains("a", "Mes audits").click(); + cy.contains("button", "Actions").click(); + cy.contains("a", "Consulter le rapport").invoke("removeAttr", "target").click(); + cy.contains("Auditeur ou auditrice : John Doe"); + }); + }); + + it("User can update their password", () => { + cy.createTestAccount({ login: true }).then(({ username, password }) => { + cy.visit("http://localhost:3000/compte/parametres"); + + const newPassword = "totototototo"; + + cy.contains("button", "Changer de mot de passe").click(); + cy.getByLabel("Mot de passe actuel").type(password); + cy.getByLabel("Nouveau mot de passe").type(newPassword); + cy.contains("button", "Changer de mot de passe").click(); + + cy.contains("Votre mot de passe a été mis à jour avec succès"); + + cy.contains("button", username).click(); + cy.contains("button", "Me déconnecter").click(); + + cy.contains("Vous avez été deconnecté avec succès."); + + cy.getByLabel("Adresse e-mail").type(username); + cy.getByLabel("Mot de passe").type(password); + cy.contains("button", "Se connecter").click(); + + cy.contains("L’adresse e-mail ou le mot de passe saisi est incorrect. Vérifiez vos saisies."); + + cy.getByLabel("Adresse e-mail").clear().type(username); + cy.getByLabel("Mot de passe").clear().type(newPassword); + cy.contains("button", "Se connecter").click(); + + cy.contains("h1", "Mes audits"); + }); + }); + + it("User can reset their password", () => { + cy.createTestAccount().then(({ username, password }) => { + cy.visit("http://localhost:3000/compte/connexion"); + cy.contains("a", "Mot de passe oublié").click(); + cy.getByLabel("Adresse e-mail").type(username); + cy.contains("button", "Valider").click(); + cy.contains( + `Un lien pour réinitialiser votre mot de passe vient de vous être envoyé par e-mail à l’adresse :` + ); + cy.contains(username); + + cy.request( + "POST", + "http://localhost:3000/api/tests/password-reset-verification-token", + { username } + ).then((resp) => { + const verificationLink = `http://localhost:3000/compte/reinitialiser-mot-de-passe?token=${resp.body}`; + cy.visit(verificationLink); + + const newPassword = "blablablabla"; + + cy.contains("h1", "Changer de mot de passe"); + cy.getByLabel("Mot de passe").type(newPassword); + cy.contains("button", "Changer de mot de passe").click(); + + cy.contains("Votre mot de passe a été mis à jour avec succès"); + + // Try login with old password + cy.getByLabel("Mot de passe").type(password); + cy.contains("button", "Se connecter").click(); + cy.contains("L’adresse e-mail ou le mot de passe saisi est incorrect. Vérifiez vos saisies."); + + // Login with new password + cy.getByLabel("Mot de passe").clear().type(newPassword); + cy.contains("button", "Se connecter").click(); + cy.contains("h1", "Mes audits"); + }); + }); + }); + + it("User can reset their password (logged in)", () => { + cy.createTestAccount({ login: true }).then(({ username }) => { + cy.visit("http://localhost:3000/compte/parametres"); + cy.contains("Changer de mot de passe").click(); + cy.contains("Mot de passe oublié ?").click(); + + cy.contains( + "Un lien pour réinitialiser votre mot de passe vient de vous être envoyé par e-mail à l’adresse :" + ); + cy.contains(username); + + cy.request( + "POST", + "http://localhost:3000/api/tests/password-reset-verification-token", + { username } + ).then((resp) => { + const verificationLink = `http://localhost:3000/compte/reinitialiser-mot-de-passe?token=${resp.body}`; + cy.visit(verificationLink); + + const newPassword = "blablablabla"; + + cy.contains("h1", "Changer de mot de passe"); + cy.getByLabel("Mot de passe").type(newPassword); + cy.contains("button", "Changer de mot de passe").click(); + + cy.location("pathname").should("eq", "/compte"); + cy.contains("Votre mot de passe a été mis à jour avec succès"); + }); + }); + }); + + it("User can update their email address", () => { + cy.createTestAccount({ login: true }).then(({ password, uid }) => { + cy.visit("http://localhost:3000/compte/parametres"); + + const newEmail = `john-smith${Math.random()}@example.com`; + cy.contains("button", "Changer d’adresse e-mail").click(); + cy.getByLabel("Mot de passe").type(password); + cy.getByLabel("Nouvelle adresse e-mail").type(newEmail); + cy.contains("button", "Changer d’adresse e-mail").click(); + + cy.contains( + `Un lien pour confirmer votre nouvelle adresse e-mail vient de vous être envoyé à l’adresse suivante : ${newEmail}` + ); + + // Simulate receiving the verification link by email. + cy.request( + "POST", + "http://localhost:3000/api/tests/email-update-verification-token", + { uid } + ).then((resp) => { + const verificationLink = `http://localhost:3000/compte/email-update-validation?token=${resp.body.token}`; + cy.visit(verificationLink); + + cy.contains(`Votre adresse email : ${newEmail}`); + cy.contains("Votre adresse e-mail a été mise à jour"); + }); + }); + }); + + it("User can delete their account", () => { + cy.createTestAccount({ login: true }).then(({ username, password }) => { + cy.createTestAudit({ auditorEmail: username }).then(({ editId }) => { + cy.visit("http://localhost:3000/compte/parametres"); + + // Delete account form + cy.contains("button", "Supprimer mon compte").click(); + cy.getByLabel( + "Saisissez la phrase suivante pour confirmer la suppression de votre compte : je confirme vouloir supprimer mon compte" + ).type("je confirme vouloir supprimer mon compte"); + cy.getByLabel("Mot de passe").type(password); + cy.contains("button", "Supprimer mon compte").click(); + cy.contains( + "Vous avez été déconnecté et votre compte a été supprimé avec succès" + ); + + // FIXME: make this work locally + // Submit feedback form + // cy.getByLabel( + // "Pourriez-vous nous donner la raison de votre départ ?" + // ).type("Quoi ? Ça n’est pas un outil d’audit automatique ⁈"); + // cy.contains("button", "Envoyer mon avis").click(); + // cy.contains("Votre avis a bien été envoyé"); + + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.contains("Désolé, l’audit que vous cherchez a été supprimé."); + }); + }); + }); +}); diff --git a/cypress/e2e/account/audits-list.cy.ts b/cypress/e2e/account/audits-list.cy.ts new file mode 100644 index 000000000..a618decdf --- /dev/null +++ b/cypress/e2e/account/audits-list.cy.ts @@ -0,0 +1,220 @@ +import * as auditJson from "../../fixtures/audit.json"; + +describe("Audits list", () => { + // Create an logged in account and 4 associated audits (1 completed, 1 pristine and 2 in progress) + beforeEach(() => { + cy.createTestAccount({ login: true }).then(({ username }) => { + cy.createTestAudit({ auditorEmail: username, isComplete: true, fillStatement: true }); + cy.createTestAudit({ auditorEmail: username, isPristine: true }); + cy.createTestAudit({ auditorEmail: username }); + cy.createTestAudit({ auditorEmail: username }).as("audit"); + cy.visit("http://localhost:3000/compte"); + }); + }); + it("User can access all their audits", () => { + cy.contains("En cours (3)"); + cy.contains("Terminé (1)"); + + const expectedLabels = [ + "Continuer l’audit", + "Continuer l’audit", + "Commencer l’audit", + "Accéder à l’audit" + ]; + + cy.get(".audit-main-action").each(($el, i) => { + expect($el.text()).to.contain(expectedLabels[i]); + }); + }); + + it("User can start audit with prefilled infos", () => { + // FIXME: export function? + function fillPageField( + pageIndex: number, + field: string, + content: string + ) { + cy.contains(`Page ${pageIndex}`) + .parent() + .parent() + .contains(field) + .parent() + .find("input") + .clear() + .type(content); + } + + // Create a new audit but auditor email field should not be present + cy.contains("a", "Démarrer un nouvel audit").click(); + + cy.contains("106 critères").click(); + + cy.contains("Nom du site ou du service à auditer") + .parent() + .find("input") + .type(auditJson.procedureName); + + cy.contains("button", "Étape suivante").click(); + cy.contains("button", "Ajouter une page").click(); + + fillPageField(1, "Nom de la page", auditJson.pages[0].name); + fillPageField(1, "URL de la page", auditJson.pages[0].url); + fillPageField(2, "Nom de la page", auditJson.pages[1].name); + fillPageField(2, "URL de la page", auditJson.pages[1].url); + fillPageField(3, "Nom de la page", auditJson.pages[2].name); + fillPageField(3, "URL de la page", auditJson.pages[2].url); + fillPageField(4, "Nom de la page", auditJson.pages[3].name); + fillPageField(4, "URL de la page", auditJson.pages[3].url); + fillPageField(5, "Nom de la page", auditJson.pages[4].name); + fillPageField(5, "URL de la page", auditJson.pages[4].url); + fillPageField(6, "Nom de la page", auditJson.pages[5].name); + fillPageField(6, "URL de la page", auditJson.pages[5].url); + fillPageField(7, "Nom de la page", auditJson.pages[6].name); + fillPageField(7, "URL de la page", auditJson.pages[6].url); + fillPageField(8, "Nom de la page", auditJson.pages[7].name); + fillPageField(8, "URL de la page", auditJson.pages[7].url); + + cy.contains("button", "Étape suivante").click(); + + cy.contains("button", "Ignorer cette étape").click(); + + cy.getByLabel("Prénom et nom (optionnel)").type(auditJson.auditorName); + + cy.contains("button", "Valider les paramètres").click(); + + cy.contains("h1", auditJson.procedureName); + + // Create new audit but in only 2 steps (step 3 auto-filled) + cy.contains("a", "Mes audits").click(); + + cy.contains("a", "Démarrer un nouvel audit").click(); + + cy.contains("106 critères").click(); + + cy.contains("Nom du site ou du service à auditer") + .parent() + .find("input") + .type(auditJson.procedureName); + + cy.contains("button", "Étape suivante").click(); + cy.contains("button", "Ajouter une page").click(); + + fillPageField(1, "Nom de la page", auditJson.pages[0].name); + fillPageField(1, "URL de la page", auditJson.pages[0].url); + fillPageField(2, "Nom de la page", auditJson.pages[1].name); + fillPageField(2, "URL de la page", auditJson.pages[1].url); + fillPageField(3, "Nom de la page", auditJson.pages[2].name); + fillPageField(3, "URL de la page", auditJson.pages[2].url); + fillPageField(4, "Nom de la page", auditJson.pages[3].name); + fillPageField(4, "URL de la page", auditJson.pages[3].url); + fillPageField(5, "Nom de la page", auditJson.pages[4].name); + fillPageField(5, "URL de la page", auditJson.pages[4].url); + fillPageField(6, "Nom de la page", auditJson.pages[5].name); + fillPageField(6, "URL de la page", auditJson.pages[5].url); + fillPageField(7, "Nom de la page", auditJson.pages[6].name); + fillPageField(7, "URL de la page", auditJson.pages[6].url); + fillPageField(8, "Nom de la page", auditJson.pages[7].name); + fillPageField(8, "URL de la page", auditJson.pages[7].url); + + cy.contains("button", "Étape suivante").click(); + + cy.contains("button", "Valider les paramètres").click(); + + cy.contains("h1", "Audit"); + }); + + it("User can duplicate audit", () => { + cy.contains("button", "Actions").click(); + cy.contains("button", "Dupliquer l’audit").click(); + + cy.getByLabel("Nom de la copie").type("Audit de mon petit site (2)"); + cy.get("dialog").contains("button", "Dupliquer l’audit").click(); + + cy.contains("Audit « Audit de mon petit site (2) » créé", { timeout: 50_000 }); + cy.contains("button", "Accéder à l’audit").click(); + + cy.contains("h1 + p", "Audit de mon petit site (2)"); + }); + + it("User can copy report link", () => { + cy.contains("button", "Actions").click(); + cy.contains("button", "Copier le lien du rapport").click(); + cy.get("@audit").then((audit) => { + cy.assertClipboardValue( + // @ts-ignore + // TODO: remove `@ts-ignore` when the following issue is fixed: + // "feat: [Add Typescript support for Aliases #8762"](https://github.com/cypress-io/cypress/issues/8762) + `http://localhost:3000/rapport/${audit.reportId}` + ); + cy.contains("span", "Lien du rapport copié"); + }); + }); + + it("User can copy statement link", () => { + cy.visit("http://localhost:3000/compte"); + + cy.get(".dropdown-container:last").contains("button", "Actions").click(); + cy.contains("button", "Copier le lien de la déclaration").click(); + + cy.get("@audit").then((audit) => { + cy.assertClipboardValue( + // @ts-ignore + // TODO: remove `@ts-ignore` when the following issue is fixed: + // "feat: [Add Typescript support for Aliases #8762"](https://github.com/cypress-io/cypress/issues/8762) + `http://localhost:3000/declaration/${audit.reportId}` + ); + cy.contains("span", "Lien de la déclaration copié"); + }); + }); + + it("User can download audit", () => { + cy.exec("rm -rf cypress/downloads"); + + cy.contains("Actions").click(); + cy.contains("Télécharger l’audit").click(); + + cy.readFile("cypress/downloads/audit-audit-de-mon-petit-site.csv"); + }); + + it("User can delete audit", () => { + cy.contains("Actions").click(); + cy.contains("Supprimer l’audit").click(); + + cy.get("dialog").contains("button", "Supprimer définitivement l’audit").click(); + + cy.contains("Audit « Audit de mon petit site » supprimé"); + }); + + it("User can transfer an audit", () => { + const newEmail = "example@domain.com"; + + cy.contains("button", "Actions").click(); + cy.contains("button", "Transférer l’audit").click(); + + // Fill form + cy.getByLabel("Adresse e-mail du destinataire") + .clear() + .type(newEmail); + cy.getByLabel("Confirmer e-mail du destinataire") + .clear() + .type(newEmail); + cy.contains("button[type='submit']", "Transférer l’audit").click(); + + // Assert audit is gone (3 audits left) + cy.get(".audits-list .audit-name").should("have.length", 3); + cy.contains("a", "Audit de mon petit site").should("be.focused"); + cy.contains("Audit « Audit de mon petit site » transféré"); + cy.contains(`Lien d’accès envoyé à ${newEmail}`); + + // Logout and check auditorEmail in audit parameters + cy.get(".account-header button[aria-expanded]").click(); + cy.contains("button", "Me déconnecter").click(); + cy.get("@audit").then(audit => { + // @ts-ignore + // TODO: remove `@ts-ignore` when the following issue is fixed: + // "feat: [Add Typescript support for Aliases #8762"](https://github.com/cypress-io/cypress/issues/8762) + cy.visit(`http://localhost:3000/audits/${audit.editId}/parametres`); + cy.getByLabel("Adresse e-mail").should("have.value", newEmail); + }); + }); +}); diff --git a/cypress/e2e/audit.cy.ts b/cypress/e2e/audit.cy.ts deleted file mode 100644 index b314f4a97..000000000 --- a/cypress/e2e/audit.cy.ts +++ /dev/null @@ -1,1059 +0,0 @@ -import { TabSlug } from "../../confiture-web-app/src/enums"; -import { slugify } from "../../confiture-web-app/src/utils"; -import * as auditJson from "../fixtures/audit.json"; -import * as statementJson from "../fixtures/statement.json"; -import { testTabReachByURL, testTabsWithPrevNext } from "./common"; - -describe("Audit", () => { - it("User can create an audit", () => { - function fillPageField(pageIndex: number, field: string, content: string) { - cy.contains(`Page ${pageIndex}`) - .parent() - .parent() - .contains(field) - .parent() - .find("input") - .clear() - .type(content); - } - - cy.visit("http://localhost:3000"); - - // Navigate to new audit page - cy.contains("a", "Je réalise un audit").click(); - - // Fill fields - cy.contains("106 critères").click(); - - cy.contains("Nom du site ou du service à auditer") - .parent() - .find("input") - .type(auditJson.procedureName); - - cy.contains("button", "Étape suivante").click(); - cy.contains("button", "Ajouter une page").click(); - - fillPageField(1, "Nom de la page", auditJson.pages[0].name); - fillPageField(1, "URL de la page", auditJson.pages[0].url); - fillPageField(2, "Nom de la page", auditJson.pages[1].name); - fillPageField(2, "URL de la page", auditJson.pages[1].url); - fillPageField(3, "Nom de la page", auditJson.pages[2].name); - fillPageField(3, "URL de la page", auditJson.pages[2].url); - fillPageField(4, "Nom de la page", auditJson.pages[3].name); - fillPageField(4, "URL de la page", auditJson.pages[3].url); - fillPageField(5, "Nom de la page", auditJson.pages[4].name); - fillPageField(5, "URL de la page", auditJson.pages[4].url); - fillPageField(6, "Nom de la page", auditJson.pages[5].name); - fillPageField(6, "URL de la page", auditJson.pages[5].url); - fillPageField(7, "Nom de la page", auditJson.pages[6].name); - fillPageField(7, "URL de la page", auditJson.pages[6].url); - fillPageField(8, "Nom de la page", auditJson.pages[7].name); - fillPageField(8, "URL de la page", auditJson.pages[7].url); - - cy.contains("button", "Étape suivante").click(); - - cy.contains("button", "Ignorer cette étape").click(); - - // Fill auditor informations - cy.contains("Adresse e-mail") - .parent() - .find("input") - .type(auditJson.auditorEmail); - - cy.contains("Prénom et nom (optionnel)") - .parent() - .find("input") - .type(auditJson.auditorName); - - // Submit new audit form - cy.contains("Valider les paramètres").click(); - - // Check user is redirect to audit generation page - cy.get("h1").contains(auditJson.procedureName); - }); - - it("User can create an audit with prefilled NA topics", () => { - function fillPageField(pageIndex: number, field: string, content: string) { - cy.contains("Page " + pageIndex) - .parent() - .parent() - .contains(field) - .parent() - .find("input") - .clear() - .type(content); - } - - cy.visit("http://localhost:3000"); - - // Navigate to new audit page - cy.contains("a", "Je réalise un audit").click(); - - // Fill fields - cy.contains("106 critères").click(); - - cy.contains("Nom du site ou du service à auditer") - .parent() - .find("input") - .type(auditJson.procedureName); - - cy.contains("button", "Étape suivante").click(); - cy.contains("button", "Ajouter une page").click(); - - fillPageField(1, "Nom de la page", auditJson.pages[0].name); - fillPageField(1, "URL de la page", auditJson.pages[0].url); - fillPageField(2, "Nom de la page", auditJson.pages[1].name); - fillPageField(2, "URL de la page", auditJson.pages[1].url); - fillPageField(3, "Nom de la page", auditJson.pages[2].name); - fillPageField(3, "URL de la page", auditJson.pages[2].url); - fillPageField(4, "Nom de la page", auditJson.pages[3].name); - fillPageField(4, "URL de la page", auditJson.pages[3].url); - fillPageField(5, "Nom de la page", auditJson.pages[4].name); - fillPageField(5, "URL de la page", auditJson.pages[4].url); - fillPageField(6, "Nom de la page", auditJson.pages[5].name); - fillPageField(6, "URL de la page", auditJson.pages[5].url); - fillPageField(7, "Nom de la page", auditJson.pages[6].name); - fillPageField(7, "URL de la page", auditJson.pages[6].url); - fillPageField(8, "Nom de la page", auditJson.pages[7].name); - fillPageField(8, "URL de la page", auditJson.pages[7].url); - - cy.contains("button", "Étape suivante").click(); - - cy.get(".checkboxes .checkbox-wrapper").last().click(); - - cy.contains("button", "Étape suivante").click(); - - // Fill auditor informations - cy.contains("Adresse e-mail") - .parent() - .find("input") - .type(auditJson.auditorEmail); - - cy.contains("Prénom et nom (optionnel)") - .parent() - .find("input") - .type(auditJson.auditorName); - - // Submit new audit form - cy.contains("Valider les paramètres").click(); - - // Check user is redirect to audit generation page - cy.get("h1").contains(auditJson.procedureName); - - cy.contains("a", "Continuer").click(); - - // Check NA criteria: 2 criteria on 9 pages = 18 - cy.contains("Non applicable (18)"); - - // Check topic "Cadres" completion is 100% - cy.get(".topic-filter-item").eq(1).contains("Cadres"); - cy.get(".topic-filter-item").eq(1).contains("100%"); - - cy.get(".audit-progress-label").contains("Progression de l’audit"); - }); - - it("User can go to settings page from audit", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.contains("Actions").click(); - cy.contains("Modifier les paramètres de l’audit").click(); - cy.get("h1").contains("Paramètres de l’audit"); - cy.url().should( - "eq", - `http://localhost:3000/audits/${editId}/parametres` - ); - }); - }); - - it("User can edit procedure name", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/parametres`); - - cy.getByLabel("Nom du site ou du service audité").should( - "have.value", - "Audit de mon petit site" - ); - - cy.getByLabel("Nom du site ou du service audité") - .clear() - .type("Audit de mon gros site"); - - cy.contains("Enregistrer les modifications").click(); - - cy.url().should( - "eq", - `http://localhost:3000/audits/${editId}/synthese` - ); - cy.get("h1").contains("Audit de mon gros site"); - }); - }); - - it("User can display the audit at a given tab directly thanks to a URL slug", () => { - cy.createTestAudit().then(({ editId }) => { - const slug = slugify(auditJson.pages[2].name); - cy.visit(`http://localhost:3000/audits/${editId}/generation/${slug}`); - testTabReachByURL(slug); - }); - }); - - it("User can go back to previous/next tab with navigator back and previous buttons", () => { - cy.createTestAudit().then(({ editId }) => { - const slug = slugify(auditJson.pages[2].name); - const nextSlug = slugify(auditJson.pages[3].name); - cy.visit(`http://localhost:3000/audits/${editId}/generation/${slug}`); - testTabsWithPrevNext(slug, nextSlug); - }); - }); - - it("User can reach topics titles with anchors", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation/`); - cy.get(".topic-filter-anchor") - .should("exist") - .each(($el, index) => { - cy.wrap($el).click(); - cy.get(`#topic_${index + 1}`).isWithinViewport(); - }); - }); - }); - - it("User can edit pages", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation/`); - - cy.contains("Actions").click(); - cy.contains("Modifier les paramètres de l’audit").click(); - - cy.get("fieldset .fr-input-group .fr-input[id^='page-name']").then( - (els) => { - expect(els).to.have.length(8); - const expectedPages = [ - "Accueil", - "Contact", - "À propos", - "Blog", - "Article", - "Connexion", - "Documentation", - "FAQ" - ]; - expectedPages.forEach((expectedPageName, i) => { - cy.wrap(els[i]).should("have.value", expectedPageName); - }); - } - ); - - cy.contains("button", "Supprimer").click(); - cy.contains("button", "Supprimer").click(); - cy.contains("button", "Supprimer").click(); - - cy.getByLabel("Nom de la page").clear().type("Accueil du blog"); - cy.getByLabel("URL de la page") - .clear() - .type("https://example.com/blog/accueil"); - - cy.get("#page-order-1").select("0"); - - cy.get("#page-order-4").select("1"); - - cy.contains("Ajouter une page").click(); - cy.get("fieldset .fr-input-group .fr-input[id^='page-name']") - .last() - .type("Paramètres"); - cy.get("fieldset .fr-input-group .fr-input[id^='page-url']") - .last() - .type("https://example.com/parametres"); - - cy.contains("Enregistrer les modifications").click(); - cy.url().should( - "eq", - `http://localhost:3000/audits/${editId}/generation/${TabSlug.AUDIT_COMMON_ELEMENTS_SLUG}` - ); - - cy.get("[data-cy='tab-label']").then((els) => { - expect(els).to.have.length(7); - const expectedPages = [ - "Éléments transverses", - "Article", - "FAQ", - "Accueil du blog", - "Connexion", - "Documentation", - "Paramètres" - ]; - expectedPages.forEach((expectedPageName, i) => { - cy.wrap(els[i]).should("have.text", expectedPageName); - }); - }); - }); - }); - - it("User can interchange page names", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation/`); - - cy.contains("Actions").click(); - cy.contains("Modifier les paramètres de l’audit").click(); - - cy.get("fieldset .fr-input-group .fr-input[id^='page-name']").then( - (els) => { - expect(els).to.have.length(8); - const expectedPages = [ - "Accueil", - "Contact", - "À propos", - "Blog", - "Article", - "Connexion", - "Documentation", - "FAQ" - ]; - expectedPages.forEach((expectedPageName, i) => { - cy.wrap(els[i]).should("have.value", expectedPageName); - }); - } - ); - - cy.get("#page-name-1-input").clear().type("Blog"); - cy.get("#page-name-2-input").clear().type("Accueil"); - cy.get("#page-name-4-input").clear().type("Contact"); - cy.get("#page-name-6-input").clear().type("FAQ"); - cy.get("#page-name-8-input").clear().type("Connexion"); - - cy.contains("Enregistrer les modifications").click(); - - cy.url().should( - "eq", - `http://localhost:3000/audits/${editId}/generation/${TabSlug.AUDIT_COMMON_ELEMENTS_SLUG}` - ); - - cy.get("[data-cy='tab-label']").then((els) => { - expect(els).to.have.length(9); - const expectedPages = [ - "Éléments transverses", - "Blog", - "Accueil", - "À propos", - "Contact", - "Article", - "FAQ", - "Documentation", - "Connexion" - ]; - expectedPages.forEach((expectedPageName, i) => { - cy.wrap(els[i]).should("have.text", expectedPageName); - }); - }); - }); - }); - - it("User can delete an audit", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("Actions").click(); - cy.contains("Supprimer l’audit").click(); - - cy.contains("Supprimer l’audit « Audit de mon petit site »"); - cy.get("dialog").contains("button", "Supprimer définitivement l’audit").click(); - - cy.url().should("eq", "http://localhost:3000/"); - cy.contains("Audit « Audit de mon petit site » supprimé"); - }); - }); - - it("User can update notes", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".notes-desktop-link") - .contains("button", "Ajouter des observations") - .click(); - - cy.get(".tiptap").type("Annotations de l’audit"); - cy.get("dialog#notes-modal").contains("button", "Fermer").click(); - - cy.get(".notes-desktop-link") - .contains("button", "Ajouter des observations") - .click(); - cy.contains("Annotations de l’audit"); - }); - }); - - it("User can fill a11y statement", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/synthese`); - cy.contains("Compléter").invoke("removeAttr", "target").click(); - - // General infos - cy.getByLabel("Entité qui a demandé l’audit") - .clear() - .type(statementJson.auditInitiator); - cy.getByLabel("Entité qui a réalisé l’audit") - .clear() - .type(statementJson.auditorOrganisation); - cy.getByLabel("URL de la page d’accueil du site audité") - .clear() - .type(statementJson.procedureUrl); - - cy.getByLabel("Adresse e-mail").clear().type(statementJson.contactEmail); - cy.getByLabel("Formulaire de contact en ligne") - .clear() - .type(statementJson.contactFormUrl); - - // Technologies - cy.getByLabel("Ajouter des technologies") - .clear() - .type(statementJson.technologies); - - cy.contains("button", "Ajouter les technologies").click(); - - // Tools - cy.contains("Web Developer Toolbar").click(); - cy.contains("WCAG Contrast checker").click(); - cy.getByLabel("Ajouter des outils d’assistance") - .clear() - .type(statementJson.tools); - - cy.contains("button", "Ajouter les outils").click(); - - // Environments - cy.contains("Combinaison 1").click(); - cy.contains("button", "Ajouter un environnement de test").click(); - cy.getByLabel("Appareil").clear().type("Ordinateur"); - cy.getByLabel("Logiciel d’exploitation").clear().type("Windows"); - cy.getByLabel("Technologie d’assistance").clear().type("JAWS"); - cy.getByLabel("Navigateur").clear().type("Edge"); - - // Not accessible content - cy.get("[aria-labelledby='notCompliantContent']") - .clear() - .type(statementJson.notCompliantContent); - cy.get("[aria-labelledby='derogatedContent']") - .clear() - .type(statementJson.derogatedContent); - cy.get("[aria-labelledby='notInScopeContent']") - .clear() - .type(statementJson.notInScopeContent); - - cy.getByLabel("URL du schéma pluriannuel de mise en accessibilité (optionnel)") - .clear() - .type(statementJson.schemaPluriannuelUrl); - - cy.getByLabel("URL du plan d'actions en cours (optionnel)") - .clear() - .type(statementJson.planActionUrl); - - cy.contains("button", "Enregistrer").click(); - cy.contains("h1", auditJson.procedureName); - }); - }); - - it("User can copy an audit", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.contains("button", "Actions").click(); - cy.contains("button", "Dupliquer l’audit").click(); - - cy.getByLabel("Nom de la copie").type("Audit de mon petit site (2)"); - cy.get("dialog").contains("button", "Dupliquer l’audit").click(); - - cy.contains("Audit « Audit de mon petit site (2) » créé", { timeout: 50_000 }); - cy.contains("button", "Accéder à l’audit").click(); - - cy.contains("h1 + p", "Audit de mon petit site (2)"); - }); - }); - - it("User can search in criteria title", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.getByLabel("Recherche par mots clés") - .clear() - .type("alternative") - .type("{enter}"); - - cy.contains("9 résultats"); - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(9); - }); - }); - }); - - it("User can hide tests and references", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.contains("Masquer les tests et références").click(); - cy.contains("Tests et références du critère 1.1").should("not.exist"); - }); - }); - - it("User can filter criteria", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - // Check total length - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(106); - }); - - // Check C criteria - cy.contains("Conforme (323)").click(); - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(36); - }); - cy.get("li.criterium-container").each((el) => { - cy.wrap(el) - .find("fieldset > div label") - .first() - .should("have.class", "green"); - }); - - // Add NA criteria - cy.contains("Non applicable (315)").click(); - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(71); - }); - cy.get("li.criterium-container").each((el) => { - cy.wrap(el) - .find("fieldset > div label") - .should( - "satisfy", - (el) => - el[0].classList.contains("green") || el.at(-1).contains("grey") - ); - }); - - // Add NC criteria - cy.contains("Non conforme (315)").click(); - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(106); - }); - cy.get("li.criterium-container").each((el) => { - cy.wrap(el) - .find("fieldset > div label") - .should( - "satisfy", - (el) => - el[0].classList.contains("green") || - el[1].contains("red") || - el.at(-1).contains("grey") - ); - }); - }); - }); - - it("User can filter evaluated criteria", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("Masquer les critères évalués").click(); - cy.contains("Tous les critères évalués ont été masqués"); - - cy.contains("Masquer les critères évalués").click(); - - cy.get("li.criterium-container fieldset input:checked") - .first() - .click({ force: true }); - - cy.get("li.criterium-container fieldset input:checked") - .eq(0) - .click({ force: true }); - - cy.contains("button[role=\"tab\"]", "Article").click(); - - cy.get("li.criterium-container fieldset input:checked") - .first() - .click({ force: true }); - - cy.contains("Masquer les critères évalués").click(); - cy.get("li.criterium-container").should("have.length", 1); - - cy.contains("button[role=\"tab\"]", "Éléments transverses").click(); - cy.get("li.criterium-container").should("have.length", 2); - - cy.get("li.criterium-container fieldset input") - .first() - .click({ force: true }); - - cy.contains("Mettre à jour critères masqués").click(); - - cy.get("li.criterium-container").should("have.length", 1); - }); - }); - - it("User can finish the audit", () => { - const monthes = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"]; - const monthesRe = "(?:" + monthes.join("|") + ")"; - cy.createTestAudit().then(({ editId, reportId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("button[role=\"tab\"]", "Accueil").click(); - - cy.get("li.criterium-container fieldset input") - .first() - .click({ force: true }); - - cy.contains(new RegExp(`Terminé le \\d{1,2} ${monthesRe} \\d{4}`)); - cy.contains("Progression de l’audit").should("not.exist"); - - cy.contains("Bravo ! Vous êtes sur le point de terminer votre audit 🎉"); - - cy.contains("a", "Accéder aux livrables").click(); - - cy.contains(new RegExp(`Terminé le \\d{1,2} ${monthesRe} \\d{4}`)); - cy.contains("a", "Accéder"); - - cy.contains("button", "Copier le lien de partage").click(); - cy.contains("button", "Lien copié"); - cy.assertClipboardValue(`http://localhost:3000/rapport/${reportId}/`); - }); - }); - - it("User can set a topic as NA", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.contains("button[role=\"tab\"]", "Connexion").click(); - cy.contains(" Non applicable sur la page").click(); - - cy.get(".topic-heading").should("have.class", "topic-heading--hidden"); - }); - }); - - it("User can edit a criterium content", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("button[role=\"tab\"]", "FAQ").click(); - cy.get(".criterium-container").contains("Non conforme"); - - cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); - - cy.get(".criterium-container .not-compliant-item input[type='text']") - .type("Absence de l'alt sur l'image"); - - cy.get(".criterium-container .not-compliant-item .tiptap") - .clear({ force: true }) - .type("Il n’y a pas de alt sur l’image du hero"); - - cy.get(".criterium-container .not-compliant-item label").contains("majeur").click(); - cy.get(".criterium-container .not-compliant-item .fr-checkbox-group").contains("Facile à corriger").click(); - }); - }); - - it("User can add a new not compliant item", () => { - cy.createTestAudit({ isPristine: true }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".criterium-container").contains("Non conforme"); - - cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); - - cy.get(".criterium-container").contains("Ajouter une erreur").click(); - - cy.get(".criterium-container .not-compliant-item:last input[type='text']") - .type("Absence de l'alt sur l'image"); - - cy.get(".criterium-container .not-compliant-item:last .tiptap") - .type("Il n’y a pas de alt sur l’image du hero"); - - cy.get(".criterium-container .not-compliant-item:last label").contains("mineur").click(); - - cy.get(".criterium-container .not-compliant-item:last .fr-checkbox-group").contains("Facile à corriger").click(); - - cy.get(".criterium-container").contains("Erreurs et recommandations (2)"); - }); - }); - - it("User can delete an not compliant item", () => { - cy.createTestAudit({ isPristine: true }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".criterium-container").contains("Non conforme"); - - cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); - - cy.get(".criterium-container .not-compliant-item:first .error-user-delete button").should("not.exist"); - - cy.get(".criterium-container").contains("Ajouter une erreur").click(); - - cy.get(".criterium-container .not-compliant-item:last input[type='text']") - .type("Absence de l'alt sur l'image"); - - cy.get(".criterium-container .not-compliant-item:last .tiptap") - .type("Il n’y a pas de alt sur l’image du hero"); - - cy.get(".criterium-container .not-compliant-item:last label").contains("mineur").click(); - - cy.get(".criterium-container .not-compliant-item:last .fr-checkbox-group").contains("Facile à corriger").click(); - - cy.get(".criterium-container").contains("Erreurs et recommandations (2)"); - - cy.get(".criterium-container .not-compliant-item:first .error-user-delete button").contains("Supprimer").click(); - - cy.get(".criterium-container").contains("Erreurs et recommandations (1)"); - }); - }); - - it("User can see transverse status and comment from other pages", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("button[role=\"tab\"]", "Documentation").click(); - cy.get(".criterium-container") - .eq(2) - .find(".criterium-transverse-notice") - .contains( - "Vous avez évalué ce critère Non conforme pour les éléments transverses." - ); - - cy.get(".criterium-container") - .eq(2) - .contains("button", "Voir les erreurs") - .click(); - - cy.get(".criterium-container").eq(2).contains("Une erreur ici"); - - cy.get(".criterium-container") - .eq(2) - .contains("button", "Masquer les erreurs") - .click(); - - cy.get(".criterium-container") - .eq(2) - .contains("Une erreur ici") - .should("not.exist"); - }); - }); - - it("User can download an audit", () => { - cy.exec("rm -rf cypress/downloads"); - - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("Actions").click(); - cy.contains("Exporter l’audit").click(); - - cy.readFile("cypress/downloads/audit-audit-de-mon-petit-site.csv"); - }); - }); - - it("User can reset filters", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("Conforme (323)").click(); - cy.contains("Non applicable (315)").click(); - cy.contains("Masquer les tests et références").click(); - cy.getByLabel("Recherche par mots clés") - .clear() - .type("alternative") - .type("{enter}"); - - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(6); - }); - - cy.contains("button", "Réinitialiser").click(); - - cy.get("li.criterium-container").then((els) => { - expect(els).to.have.length(106); - }); - - cy.focused().should("have.attr", "placeholder", "Rechercher un critère"); - cy.contains("button", "Réinitialiser").should("not.exist"); - }); - }); - - it("User can add transverse elements", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("Lister les éléments transverses").click(); - cy.getByLabel("Nom de l’élément transverse").type( - "FoooElements, BarElements, ThingElements" - ); - cy.get(".transverse-elements").contains("Ajouter").click(); - - cy.contains("button", "FoooElements").should("exist"); - cy.contains("button", "BarElements").should("exist"); - cy.contains("button", "ThingElements").should("exist"); - - cy.contains("BarElements").click(); - - cy.contains("Enregistrer").click(); - - cy.contains("FoooElements").should("exist"); - cy.contains("BarElements").should("not.exist"); - cy.contains("ThingElements").should("exist"); - }); - }); - - it("User can automatically set as NA some linked criteria", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - // check that linked criteria are also NA - cy.get(".criterium-container").contains("Non applicable").click(); - cy.get(".criterium-container").eq(2).find("fieldset > div input[type='checkbox']").eq(2).should("be.checked"); - cy.get(".criterium-container").eq(2).contains("Vous avez évalué le critère 1.1 Non applicable"); - - // check that linked criteria get their previous status back - cy.get(".criterium-container").contains("Conforme").click(); - cy.get(".criterium-container").eq(2).find("fieldset > div input[type='checkbox']").eq(2).should("not.be.checked"); - cy.get(".criterium-container").eq(2).find("fieldset > div input[type='checkbox']").eq(1).should("be.checked"); - cy.get(".criterium-container").eq(2).contains("Vous avez évalué le critère 1.1 Non applicable").should("not.exist"); - }); - }); - - it("User can show or hide topic criteria", () => { - cy.createTestAudit({ isPristine: true }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - // Check total criteria count - cy.get(".criterium-container").should("have.length", 106); - - // Hide topic 1 criteria (-9) - cy.get("button.toggle-topic-button").first().click(); - cy.get(".criterium-container").should("have.length", 97); - - // Show topic 1 criteria (+9) - cy.get("button.toggle-topic-button").first().click(); - cy.get(".criterium-container").should("have.length", 106); - }); - }); - - it("User can insert an image in the comment editor", () => { - cy.intercept("POST", "/api/audits/editor/images").as("uploadImage"); - cy.intercept("PATCH", `/api/audits/*/pages/*/results/*/not-compliant-items/*`).as("updateResults"); - - cy.createTestAudit({ isPristine: true }).then(({ editId, reportId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.get(".criterium-container").contains("Non conforme"); - cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); - - // 1. Insert an image into the editor with the button - cy.log("** Insert 1 image with the button **"); - cy.contains("Insérer une image").click(); - cy.get(".criterium-container input[type='file']") - .selectFile("cypress/fixtures/aras-rouges.jpg", { force: true }); - - // Editor content has changed => results updated - cy.wait(["@uploadImage", "@updateResults"]); - - // 2. Drag and drop a local image - cy.log("** Drag and drop 1 local image **"); - cy.get(".criterium-container .tiptap") - .selectFile("cypress/fixtures/ara-bleu.jpg", { action: "drag-drop" }); - - // Editor content has changed => results updated - cy.wait(["@uploadImage", "@updateResults"]); - - // 3. Copy-paste a local image - cy.log("** Paste 1 image from clipboard **"); - const fileName = "groupe-ara.jpg"; - cy.get(".criterium-container .tiptap").pasteImage({ filePath: `../fixtures/${fileName}`, fileName }); - - // Check success message - cy.get(".criterium-container [aria-live='polite']").contains(`L’image « ${fileName} » a été correctement insérée`); - cy.get(`.criterium-container .tiptap img[alt="${fileName}"]:not([data-loading="true"])`).debug(); - cy.get(`.criterium-container .tiptap img[alt="${fileName}"]:not([data-loading="true"])`).should("exist"); - - // Editor content has changed => results updated - cy.wait("@updateResults"); - - cy.get(".criterium-container img[src^='/uploads/']") - .should("have.length", 3); - - // Go to report page to check images count (3) - cy.visit(`http://localhost:3000/rapport/${reportId}/details-des-non-conformites`); - cy.get(".tiptap--rendered img").should("have.length", 3); - }); - }); - - it("User can paste Markdown content in the comment editor (and it’s interpreted)", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".notes-desktop-link") - .contains("button", "Ajouter des observations") - .click(); - cy.get(".tiptap").type("Copier coller de Markdown :{enter}"); - cy.get(".tiptap").pasteText("../fixtures/mdContent.md"); - cy.get(".tiptap strong").should("exist"); - cy.get(".tiptap img").should("not.exist"); - }); - }); - - it("User can paste HTML text content in the comment editor (and it's not interpreted)", () => { - cy.createTestAudit().then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".notes-desktop-link") - .contains("button", "Ajouter des observations") - .click(); - cy.get(".tiptap").type("Copier coller de texte HTML :{enter}"); - cy.get(".tiptap").pasteText("../fixtures/notMdContent.txt"); - cy.get(".tiptap strong").should("not.exist"); - cy.get(".tiptap img").should("not.exist"); - }); - }); - - it("User can insert HTML content in the comment editor (and images are stripped out)", () => { - cy.intercept("PATCH", `/api/audits/*/pages/*/results/*/*/*`).as("updateResults"); - - cy.createTestAudit({ isPristine: true }).then(({ editId, reportId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".criterium-container").contains("Non conforme"); - cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); - - // 3. Copy-paste HTML content with 2 images - cy.log("** Paste 1 image from clipboard **"); - cy.get(".criterium-container .tiptap").pasteHTML("../fixtures/contentExample.html"); - - // Editor content has changed => results updated - cy.wait("@updateResults"); - - // Go to report page to check text + images count (0) - cy.visit(`http://localhost:3000/rapport/${reportId}/details-des-non-conformites`); - // - 1 h4 - cy.get(".tiptap--rendered h4").should("have.length", 1); - // - 2 li - cy.get(".tiptap--rendered li").should("have.length", 2); - // - 0 img - cy.get(".tiptap--rendered img").should("have.length", 0); - }); - }); - - it("User can transfer an audit", () => { - cy.createTestAudit({ isPristine: true }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - cy.contains("button", "Actions").click(); - cy.contains("button", "Transférer l’audit").click(); - - // Error: 2nd field is empty - cy.getByLabel("Adresse e-mail du destinataire") - .clear() - .type("example@domain.com"); - - cy.contains("button[type='submit']", "Transférer l’audit").click(); - cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); - - cy.getByLabel("Confirmer e-mail du destinataire") - .clear() - .type("exampl@domain.com"); - - // Error: 2nd field isnt equal to first - cy.contains("button[type='submit']", "Transférer l’audit").click(); - cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); - - // Valid form - cy.getByLabel("Confirmer e-mail du destinataire") - .clear() - .type("example@domain.com"); - cy.contains("button[type='submit']", "Transférer l’audit").click(); - - // Assert we're on homepage with toast - cy.contains("Je réalise un audit d’accessibilité avec Ara"); - cy.contains("Audit « Audit de mon petit site » transféré"); - cy.contains("Lien d’accès envoyé à example@domain.com"); - }); - }); - - it("User can't transfer an audit after logging out", () => { - cy.createTestAccount({ login: true }).then(({ username }) => { - cy.createTestAudit({ auditorEmail: username, isPristine: true }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.contains("button", username).click(); - cy.contains("button", "Me déconnecter").click(); - - cy.visit(`http://localhost:3000/audits/${editId}/synthese`); - - cy.contains("button", "Actions").click(); - cy.contains("button", "Transférer").should("be.disabled"); - }); - }); - }); - - it("User can transfer an audit without being logged in", () => { - cy.createTestAudit({ isPristine: true }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/synthese`); - cy.contains("button", "Actions").click(); - cy.contains("button", "Transférer").click(); - - // Error: 2nd field is empty - cy.getByLabel("Adresse e-mail du destinataire") - .clear() - .type("example@domain.com"); - - cy.contains("button[type='submit']", "Transférer l’audit").click(); - cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); - - cy.getByLabel("Confirmer e-mail du destinataire") - .clear() - .type("exampl@domain.com"); - - // Error: 2nd field isnt equal to first - cy.contains("button[type='submit']", "Transférer l’audit").click(); - cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); - - // Valid form - cy.getByLabel("Confirmer e-mail du destinataire") - .clear() - .type("example@domain.com"); - cy.contains("button[type='submit']", "Transférer l’audit").click(); - - // Assert we're on homepage with toast - cy.contains("Je réalise un audit d’accessibilité avec Ara"); - cy.contains("Audit « Audit de mon petit site » transféré"); - cy.contains("Lien d’accès envoyé à example@domain.com"); - }); - }); - - it("User can change criteria in a completed audit to update editionDate", () => { - cy.intercept("PATCH", `/api/audits/*/results`).as("updateResults"); - - const today = new Date(); - const publicationDate = new Date(today.setDate(today.getDate() - 2)); - - cy.createTestAudit({ - isComplete: true, - publicationDate: publicationDate.toString() - }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".audit-status").contains("Terminé le"); - cy.get(".audit-status").contains("Mis à jour le").should("not.exist"); - - cy.contains("button[role=\"tab\"]", "Accueil").click(); - cy.get(".criterium-container").contains("Non conforme").click(); - - cy.wait("@updateResults"); - - cy.get(".audit-status").contains("Terminé le"); - cy.get(".audit-status").contains("Mis à jour le"); - }); - }); - - it("User can uncheck criterium in a completed audit so it becomes in progress", () => { - cy.intercept("PATCH", `/api/audits/*/results`).as("updateResults"); - - cy.createTestAudit({ - isComplete: true - }).then(({ editId }) => { - cy.visit(`http://localhost:3000/audits/${editId}/generation`); - - cy.get(".audit-status").contains("Terminé le"); - - cy.contains("button[role=\"tab\"]", "Accueil").click(); - cy.get(".criterium-container").contains("Conforme").click(); - - cy.wait("@updateResults"); - - cy.get(".audit-progress-label").contains("Progression de l’audit"); - }); - }); -}); diff --git a/cypress/e2e/audit/actions.cy.ts b/cypress/e2e/audit/actions.cy.ts new file mode 100644 index 000000000..36dd60491 --- /dev/null +++ b/cypress/e2e/audit/actions.cy.ts @@ -0,0 +1,299 @@ +import { TabSlug } from "../../../confiture-web-app/src/enums"; + +describe("Actions", () => { + it("User can go to settings page from audit", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.contains("Actions").click(); + cy.contains("Modifier les paramètres de l’audit").click(); + cy.get("h1").contains("Paramètres de l’audit"); + cy.url().should( + "eq", + `http://localhost:3000/audits/${editId}/parametres` + ); + }); + }); + + it("User can edit procedure name", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/parametres`); + + cy.getByLabel("Nom du site ou du service audité").should( + "have.value", + "Audit de mon petit site" + ); + + cy.getByLabel("Nom du site ou du service audité") + .clear() + .type("Audit de mon gros site"); + + cy.contains("Enregistrer les modifications").click(); + + cy.url().should( + "eq", + `http://localhost:3000/audits/${editId}/synthese` + ); + cy.get("h1").contains("Audit de mon gros site"); + }); + }); + + it("User can edit pages", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation/`); + + cy.contains("Actions").click(); + cy.contains("Modifier les paramètres de l’audit").click(); + + cy.get("fieldset .fr-input-group .fr-input[id^='page-name']").then( + (els) => { + expect(els).to.have.length(8); + const expectedPages = [ + "Accueil", + "Contact", + "À propos", + "Blog", + "Article", + "Connexion", + "Documentation", + "FAQ" + ]; + expectedPages.forEach((expectedPageName, i) => { + cy.wrap(els[i]).should("have.value", expectedPageName); + }); + } + ); + + cy.contains("button", "Supprimer").click(); + cy.contains("button", "Supprimer").click(); + cy.contains("button", "Supprimer").click(); + + cy.getByLabel("Nom de la page").clear().type("Accueil du blog"); + cy.getByLabel("URL de la page") + .clear() + .type("https://example.com/blog/accueil"); + + cy.get("#page-order-1").select("0"); + + cy.get("#page-order-4").select("1"); + + cy.contains("Ajouter une page").click(); + cy.get("fieldset .fr-input-group .fr-input[id^='page-name']") + .last() + .type("Paramètres"); + cy.get("fieldset .fr-input-group .fr-input[id^='page-url']") + .last() + .type("https://example.com/parametres"); + + cy.contains("Enregistrer les modifications").click(); + cy.url().should( + "eq", + `http://localhost:3000/audits/${editId}/generation/${TabSlug.AUDIT_COMMON_ELEMENTS_SLUG}` + ); + + cy.get("[data-cy='tab-label']").then((els) => { + expect(els).to.have.length(7); + const expectedPages = [ + "Éléments transverses", + "Article", + "FAQ", + "Accueil du blog", + "Connexion", + "Documentation", + "Paramètres" + ]; + expectedPages.forEach((expectedPageName, i) => { + cy.wrap(els[i]).should("have.text", expectedPageName); + }); + }); + }); + }); + + it("User can interchange page names", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation/`); + + cy.contains("Actions").click(); + cy.contains("Modifier les paramètres de l’audit").click(); + + cy.get("fieldset .fr-input-group .fr-input[id^='page-name']").then( + (els) => { + expect(els).to.have.length(8); + const expectedPages = [ + "Accueil", + "Contact", + "À propos", + "Blog", + "Article", + "Connexion", + "Documentation", + "FAQ" + ]; + expectedPages.forEach((expectedPageName, i) => { + cy.wrap(els[i]).should("have.value", expectedPageName); + }); + } + ); + + cy.get("#page-name-1-input").clear().type("Blog"); + cy.get("#page-name-2-input").clear().type("Accueil"); + cy.get("#page-name-4-input").clear().type("Contact"); + cy.get("#page-name-6-input").clear().type("FAQ"); + cy.get("#page-name-8-input").clear().type("Connexion"); + + cy.contains("Enregistrer les modifications").click(); + + cy.url().should( + "eq", + `http://localhost:3000/audits/${editId}/generation/${TabSlug.AUDIT_COMMON_ELEMENTS_SLUG}` + ); + + cy.get("[data-cy='tab-label']").then((els) => { + expect(els).to.have.length(9); + const expectedPages = [ + "Éléments transverses", + "Blog", + "Accueil", + "À propos", + "Contact", + "Article", + "FAQ", + "Documentation", + "Connexion" + ]; + expectedPages.forEach((expectedPageName, i) => { + cy.wrap(els[i]).should("have.text", expectedPageName); + }); + }); + }); + }); + + it("User can delete an audit", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("Actions").click(); + cy.contains("Supprimer l’audit").click(); + + cy.contains("Supprimer l’audit « Audit de mon petit site »"); + cy.get("dialog").contains("button", "Supprimer définitivement l’audit").click(); + + cy.url().should("eq", "http://localhost:3000/"); + cy.contains("Audit « Audit de mon petit site » supprimé"); + }); + }); + + it("User can copy an audit", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.contains("button", "Actions").click(); + cy.contains("button", "Dupliquer l’audit").click(); + + cy.getByLabel("Nom de la copie").type("Audit de mon petit site (2)"); + cy.get("dialog").contains("button", "Dupliquer l’audit").click(); + + cy.contains("Audit « Audit de mon petit site (2) » créé", { timeout: 50_000 }); + cy.contains("button", "Accéder à l’audit").click(); + + cy.contains("h1 + p", "Audit de mon petit site (2)"); + }); + }); + + it("User can download an audit", () => { + cy.exec("rm -rf cypress/downloads"); + + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("Actions").click(); + cy.contains("Exporter l’audit").click(); + + cy.readFile("cypress/downloads/audit-audit-de-mon-petit-site.csv"); + }); + }); + + it("User can transfer an audit", () => { + cy.createTestAudit({ isPristine: true }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.contains("button", "Actions").click(); + cy.contains("button", "Transférer l’audit").click(); + + // Error: 2nd field is empty + cy.getByLabel("Adresse e-mail du destinataire") + .clear() + .type("example@domain.com"); + + cy.contains("button[type='submit']", "Transférer l’audit").click(); + cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); + + cy.getByLabel("Confirmer e-mail du destinataire") + .clear() + .type("exampl@domain.com"); + + // Error: 2nd field isnt equal to first + cy.contains("button[type='submit']", "Transférer l’audit").click(); + cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); + + // Valid form + cy.getByLabel("Confirmer e-mail du destinataire") + .clear() + .type("example@domain.com"); + cy.contains("button[type='submit']", "Transférer l’audit").click(); + + // Assert we're on homepage with toast + cy.contains("Je réalise un audit d’accessibilité avec Ara"); + cy.contains("Audit « Audit de mon petit site » transféré"); + cy.contains("Lien d’accès envoyé à example@domain.com"); + }); + }); + + it("User can't transfer an audit after logging out", () => { + cy.createTestAccount({ login: true }).then(({ username }) => { + cy.createTestAudit({ auditorEmail: username, isPristine: true }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("button", username).click(); + cy.contains("button", "Me déconnecter").click(); + + cy.visit(`http://localhost:3000/audits/${editId}/synthese`); + + cy.contains("button", "Actions").click(); + cy.contains("button", "Transférer").should("be.disabled"); + }); + }); + }); + + it("User can transfer an audit without being logged in", () => { + cy.createTestAudit({ isPristine: true }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/synthese`); + cy.contains("button", "Actions").click(); + cy.contains("button", "Transférer").click(); + + // Error: 2nd field is empty + cy.getByLabel("Adresse e-mail du destinataire") + .clear() + .type("example@domain.com"); + + cy.contains("button[type='submit']", "Transférer l’audit").click(); + cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); + + cy.getByLabel("Confirmer e-mail du destinataire") + .clear() + .type("exampl@domain.com"); + + // Error: 2nd field isnt equal to first + cy.contains("button[type='submit']", "Transférer l’audit").click(); + cy.getByLabel("Confirmer e-mail du destinataire").should("be.focused"); + + // Valid form + cy.getByLabel("Confirmer e-mail du destinataire") + .clear() + .type("example@domain.com"); + cy.contains("button[type='submit']", "Transférer l’audit").click(); + + // Assert we're on homepage with toast + cy.contains("Je réalise un audit d’accessibilité avec Ara"); + cy.contains("Audit « Audit de mon petit site » transféré"); + cy.contains("Lien d’accès envoyé à example@domain.com"); + }); + }); +}); diff --git a/cypress/e2e/audit/audit-tabs.cy.ts b/cypress/e2e/audit/audit-tabs.cy.ts new file mode 100644 index 000000000..32aa58ba5 --- /dev/null +++ b/cypress/e2e/audit/audit-tabs.cy.ts @@ -0,0 +1,89 @@ +import { slugify } from "../../../confiture-web-app/src/utils"; +import * as auditJson from "../../fixtures/audit.json"; +import { testTabReachByURL, testTabsWithPrevNext } from "../common"; + +describe("Audit tabs", () => { + it("User can display the audit at a given tab directly thanks to a URL slug", () => { + cy.createTestAudit().then(({ editId }) => { + const slug = slugify(auditJson.pages[2].name); + cy.visit(`http://localhost:3000/audits/${editId}/generation/${slug}`); + testTabReachByURL(slug); + }); + }); + + it("User can go back to previous/next tab with navigator back and previous buttons", () => { + cy.createTestAudit().then(({ editId }) => { + const slug = slugify(auditJson.pages[2].name); + const nextSlug = slugify(auditJson.pages[3].name); + cy.visit(`http://localhost:3000/audits/${editId}/generation/${slug}`); + testTabsWithPrevNext(slug, nextSlug); + }); + }); + + it("User can reach topics titles with anchors", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation/`); + cy.get(".topic-filter-anchor") + .should("exist") + .each(($el, index) => { + cy.wrap($el).click(); + cy.get(`#topic_${index + 1}`).isWithinViewport(); + }); + }); + }); + + it("User can see transverse status and comment from other pages", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("button[role=\"tab\"]", "Documentation").click(); + cy.get(".criterium-container") + .eq(2) + .find(".criterium-transverse-notice") + .contains( + "Vous avez évalué ce critère Non conforme pour les éléments transverses." + ); + + cy.get(".criterium-container") + .eq(2) + .contains("button", "Voir les erreurs") + .click(); + + cy.get(".criterium-container").eq(2).contains("Une erreur ici"); + + cy.get(".criterium-container") + .eq(2) + .contains("button", "Masquer les erreurs") + .click(); + + cy.get(".criterium-container") + .eq(2) + .contains("Une erreur ici") + .should("not.exist"); + }); + }); + + it("User can add transverse elements", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("Lister les éléments transverses").click(); + cy.getByLabel("Nom de l’élément transverse").type( + "FoooElements, BarElements, ThingElements" + ); + cy.get(".transverse-elements").contains("Ajouter").click(); + + cy.contains("button", "FoooElements").should("exist"); + cy.contains("button", "BarElements").should("exist"); + cy.contains("button", "ThingElements").should("exist"); + + cy.contains("BarElements").click(); + + cy.contains("Enregistrer").click(); + + cy.contains("FoooElements").should("exist"); + cy.contains("BarElements").should("not.exist"); + cy.contains("ThingElements").should("exist"); + }); + }); +}); diff --git a/cypress/e2e/audit/audit.cy.ts b/cypress/e2e/audit/audit.cy.ts new file mode 100644 index 000000000..b772505e6 --- /dev/null +++ b/cypress/e2e/audit/audit.cy.ts @@ -0,0 +1,307 @@ +import * as auditJson from "../../fixtures/audit.json"; + +describe("Audit", () => { + it("User can create an audit", () => { + function fillPageField(pageIndex: number, field: string, content: string) { + cy.contains(`Page ${pageIndex}`) + .parent() + .parent() + .contains(field) + .parent() + .find("input") + .clear() + .type(content); + } + + cy.visit("http://localhost:3000"); + + // Navigate to new audit page + cy.contains("a", "Je réalise un audit").click(); + + // Fill fields + cy.contains("106 critères").click(); + + cy.contains("Nom du site ou du service à auditer") + .parent() + .find("input") + .type(auditJson.procedureName); + + cy.contains("button", "Étape suivante").click(); + cy.contains("button", "Ajouter une page").click(); + + fillPageField(1, "Nom de la page", auditJson.pages[0].name); + fillPageField(1, "URL de la page", auditJson.pages[0].url); + fillPageField(2, "Nom de la page", auditJson.pages[1].name); + fillPageField(2, "URL de la page", auditJson.pages[1].url); + fillPageField(3, "Nom de la page", auditJson.pages[2].name); + fillPageField(3, "URL de la page", auditJson.pages[2].url); + fillPageField(4, "Nom de la page", auditJson.pages[3].name); + fillPageField(4, "URL de la page", auditJson.pages[3].url); + fillPageField(5, "Nom de la page", auditJson.pages[4].name); + fillPageField(5, "URL de la page", auditJson.pages[4].url); + fillPageField(6, "Nom de la page", auditJson.pages[5].name); + fillPageField(6, "URL de la page", auditJson.pages[5].url); + fillPageField(7, "Nom de la page", auditJson.pages[6].name); + fillPageField(7, "URL de la page", auditJson.pages[6].url); + fillPageField(8, "Nom de la page", auditJson.pages[7].name); + fillPageField(8, "URL de la page", auditJson.pages[7].url); + + cy.contains("button", "Étape suivante").click(); + + cy.contains("button", "Ignorer cette étape").click(); + + // Fill auditor informations + cy.contains("Adresse e-mail") + .parent() + .find("input") + .type(auditJson.auditorEmail); + + cy.contains("Prénom et nom (optionnel)") + .parent() + .find("input") + .type(auditJson.auditorName); + + // Submit new audit form + cy.contains("Valider les paramètres").click(); + + // Check user is redirect to audit generation page + cy.get("h1").contains(auditJson.procedureName); + }); + + it("User can create an audit with prefilled NA topics", () => { + function fillPageField(pageIndex: number, field: string, content: string) { + cy.contains("Page " + pageIndex) + .parent() + .parent() + .contains(field) + .parent() + .find("input") + .clear() + .type(content); + } + + cy.visit("http://localhost:3000"); + + // Navigate to new audit page + cy.contains("a", "Je réalise un audit").click(); + + // Fill fields + cy.contains("106 critères").click(); + + cy.contains("Nom du site ou du service à auditer") + .parent() + .find("input") + .type(auditJson.procedureName); + + cy.contains("button", "Étape suivante").click(); + cy.contains("button", "Ajouter une page").click(); + + fillPageField(1, "Nom de la page", auditJson.pages[0].name); + fillPageField(1, "URL de la page", auditJson.pages[0].url); + fillPageField(2, "Nom de la page", auditJson.pages[1].name); + fillPageField(2, "URL de la page", auditJson.pages[1].url); + fillPageField(3, "Nom de la page", auditJson.pages[2].name); + fillPageField(3, "URL de la page", auditJson.pages[2].url); + fillPageField(4, "Nom de la page", auditJson.pages[3].name); + fillPageField(4, "URL de la page", auditJson.pages[3].url); + fillPageField(5, "Nom de la page", auditJson.pages[4].name); + fillPageField(5, "URL de la page", auditJson.pages[4].url); + fillPageField(6, "Nom de la page", auditJson.pages[5].name); + fillPageField(6, "URL de la page", auditJson.pages[5].url); + fillPageField(7, "Nom de la page", auditJson.pages[6].name); + fillPageField(7, "URL de la page", auditJson.pages[6].url); + fillPageField(8, "Nom de la page", auditJson.pages[7].name); + fillPageField(8, "URL de la page", auditJson.pages[7].url); + + cy.contains("button", "Étape suivante").click(); + + cy.get(".checkboxes .checkbox-wrapper").last().click(); + + cy.contains("button", "Étape suivante").click(); + + // Fill auditor informations + cy.contains("Adresse e-mail") + .parent() + .find("input") + .type(auditJson.auditorEmail); + + cy.contains("Prénom et nom (optionnel)") + .parent() + .find("input") + .type(auditJson.auditorName); + + // Submit new audit form + cy.contains("Valider les paramètres").click(); + + // Check user is redirect to audit generation page + cy.get("h1").contains(auditJson.procedureName); + + cy.contains("a", "Continuer").click(); + + // Check NA criteria: 2 criteria on 9 pages = 18 + cy.contains("Non applicable (18)"); + + // Check topic "Cadres" completion is 100% + cy.get(".topic-filter-item").eq(1).contains("Cadres"); + cy.get(".topic-filter-item").eq(1).contains("100%"); + + cy.get(".audit-progress-label").contains("Progression de l’audit"); + }); + + it("User can finish the audit", () => { + const monthes = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"]; + const monthesRe = "(?:" + monthes.join("|") + ")"; + cy.createTestAudit().then(({ editId, reportId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("button[role=\"tab\"]", "Accueil").click(); + + cy.get("li.criterium-container fieldset input") + .first() + .click({ force: true }); + + cy.contains(new RegExp(`Terminé le \\d{1,2} ${monthesRe} \\d{4}`)); + cy.contains("Progression de l’audit").should("not.exist"); + + cy.contains("Bravo ! Vous êtes sur le point de terminer votre audit 🎉"); + + cy.contains("a", "Accéder aux livrables").click(); + + cy.contains(new RegExp(`Terminé le \\d{1,2} ${monthesRe} \\d{4}`)); + cy.contains("a", "Accéder"); + + cy.contains("button", "Copier le lien de partage").click(); + cy.contains("button", "Lien copié"); + cy.assertClipboardValue(`http://localhost:3000/rapport/${reportId}/`); + }); + }); + + it("User can set a topic as NA", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.contains("button[role=\"tab\"]", "Connexion").click(); + cy.contains(" Non applicable sur la page").click(); + + cy.get(".topic-heading").should("have.class", "topic-heading--hidden"); + }); + }); + + it("User can edit a criterium content", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("button[role=\"tab\"]", "FAQ").click(); + cy.get(".criterium-container").contains("Non conforme"); + + cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); + + cy.get(".criterium-container .not-compliant-item input[type='text']") + .type("Absence de l'alt sur l'image"); + + cy.get(".criterium-container .not-compliant-item .tiptap") + .clear({ force: true }) + .type("Il n’y a pas de alt sur l’image du hero"); + + cy.get(".criterium-container .not-compliant-item label").contains("majeur").click(); + cy.get(".criterium-container .not-compliant-item .fr-checkbox-group").contains("Facile à corriger").click(); + }); + }); + + it("User can add a new not compliant item", () => { + cy.createTestAudit({ isPristine: true }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".criterium-container").contains("Non conforme"); + + cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); + + cy.get(".criterium-container").contains("Ajouter une erreur").click(); + + cy.get(".criterium-container .not-compliant-item:last input[type='text']") + .type("Absence de l'alt sur l'image"); + + cy.get(".criterium-container .not-compliant-item:last .tiptap") + .type("Il n’y a pas de alt sur l’image du hero"); + + cy.get(".criterium-container .not-compliant-item:last label").contains("mineur").click(); + + cy.get(".criterium-container .not-compliant-item:last .fr-checkbox-group").contains("Facile à corriger").click(); + + cy.get(".criterium-container").contains("Erreurs et recommandations (2)"); + }); + }); + + it("User can delete an not compliant item", () => { + cy.createTestAudit({ isPristine: true }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".criterium-container").contains("Non conforme"); + + cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); + + cy.get(".criterium-container .not-compliant-item:first .error-user-delete button").should("not.exist"); + + cy.get(".criterium-container").contains("Ajouter une erreur").click(); + + cy.get(".criterium-container .not-compliant-item:last input[type='text']") + .type("Absence de l'alt sur l'image"); + + cy.get(".criterium-container .not-compliant-item:last .tiptap") + .type("Il n’y a pas de alt sur l’image du hero"); + + cy.get(".criterium-container .not-compliant-item:last label").contains("mineur").click(); + + cy.get(".criterium-container .not-compliant-item:last .fr-checkbox-group").contains("Facile à corriger").click(); + + cy.get(".criterium-container").contains("Erreurs et recommandations (2)"); + + cy.get(".criterium-container .not-compliant-item:first .error-user-delete button").contains("Supprimer").click(); + + cy.get(".criterium-container").contains("Erreurs et recommandations (1)"); + }); + }); + + it("User can change criteria in a completed audit to update editionDate", () => { + cy.intercept("PATCH", `/api/audits/*/results`).as("updateResults"); + + const today = new Date(); + const publicationDate = new Date(today.setDate(today.getDate() - 2)); + + cy.createTestAudit({ + isComplete: true, + publicationDate: publicationDate.toString() + }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".audit-status").contains("Terminé le"); + cy.get(".audit-status").contains("Mis à jour le").should("not.exist"); + + cy.contains("button[role=\"tab\"]", "Accueil").click(); + cy.get(".criterium-container").contains("Non conforme").click(); + + cy.wait("@updateResults"); + + cy.get(".audit-status").contains("Terminé le"); + cy.get(".audit-status").contains("Mis à jour le"); + }); + }); + + it("User can uncheck criterium in a completed audit so it becomes in progress", () => { + cy.intercept("PATCH", `/api/audits/*/results`).as("updateResults"); + + cy.createTestAudit({ + isComplete: true + }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".audit-status").contains("Terminé le"); + + cy.contains("button[role=\"tab\"]", "Accueil").click(); + cy.get(".criterium-container").contains("Conforme").click(); + + cy.wait("@updateResults"); + + cy.get(".audit-progress-label").contains("Progression de l’audit"); + }); + }); +}); diff --git a/cypress/e2e/audit/editor.cy.ts b/cypress/e2e/audit/editor.cy.ts new file mode 100644 index 000000000..3b6654e71 --- /dev/null +++ b/cypress/e2e/audit/editor.cy.ts @@ -0,0 +1,104 @@ +describe("Editor", () => { + it("User can insert an image in the comment editor", () => { + cy.intercept("POST", "/api/audits/editor/images").as("uploadImage"); + cy.intercept("PATCH", `/api/audits/*/pages/*/results/*/not-compliant-items/*`).as("updateResults"); + + cy.createTestAudit({ isPristine: true }).then(({ editId, reportId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.get(".criterium-container").contains("Non conforme"); + cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); + + // 1. Insert an image into the editor with the button + cy.log("** Insert 1 image with the button **"); + cy.contains("Insérer une image").click(); + cy.get(".criterium-container input[type='file']") + .selectFile("cypress/fixtures/aras-rouges.jpg", { force: true }); + + // Editor content has changed => results updated + cy.wait(["@uploadImage", "@updateResults"]); + + // 2. Drag and drop a local image + cy.log("** Drag and drop 1 local image **"); + cy.get(".criterium-container .tiptap") + .selectFile("cypress/fixtures/ara-bleu.jpg", { action: "drag-drop" }); + + // Editor content has changed => results updated + cy.wait(["@uploadImage", "@updateResults"]); + + // 3. Copy-paste a local image + cy.log("** Paste 1 image from clipboard **"); + const fileName = "groupe-ara.jpg"; + cy.get(".criterium-container .tiptap").pasteImage({ filePath: `../fixtures/${fileName}`, fileName }); + + // Check success message + cy.get(".criterium-container [aria-live='polite']").contains(`L’image « ${fileName} » a été correctement insérée`); + cy.get(`.criterium-container .tiptap img[alt="${fileName}"]:not([data-loading="true"])`).debug(); + cy.get(`.criterium-container .tiptap img[alt="${fileName}"]:not([data-loading="true"])`).should("exist"); + + // Editor content has changed => results updated + cy.wait("@updateResults"); + + cy.get(".criterium-container img[src^='/uploads/']") + .should("have.length", 3); + + // Go to report page to check images count (3) + cy.visit(`http://localhost:3000/rapport/${reportId}/details-des-non-conformites`); + cy.get(".tiptap--rendered img").should("have.length", 3); + }); + }); + + it("User can paste Markdown content in the comment editor (and it’s interpreted)", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".notes-desktop-link") + .contains("button", "Ajouter des observations") + .click(); + cy.get(".tiptap").type("Copier coller de Markdown :{enter}"); + cy.get(".tiptap").pasteText("../fixtures/mdContent.md"); + cy.get(".tiptap strong").should("exist"); + cy.get(".tiptap img").should("not.exist"); + }); + }); + + it("User can paste HTML text content in the comment editor (and it's not interpreted)", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".notes-desktop-link") + .contains("button", "Ajouter des observations") + .click(); + cy.get(".tiptap").type("Copier coller de texte HTML :{enter}"); + cy.get(".tiptap").pasteText("../fixtures/notMdContent.txt"); + cy.get(".tiptap strong").should("not.exist"); + cy.get(".tiptap img").should("not.exist"); + }); + }); + + it("User can insert HTML content in the comment editor (and images are stripped out)", () => { + cy.intercept("PATCH", `/api/audits/*/pages/*/results/*/*/*`).as("updateResults"); + + cy.createTestAudit({ isPristine: true }).then(({ editId, reportId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".criterium-container").contains("Non conforme"); + cy.get(".criterium-container").contains("Erreurs et recommandations (1)").click(); + + // 3. Copy-paste HTML content with 2 images + cy.log("** Paste 1 image from clipboard **"); + cy.get(".criterium-container .tiptap").pasteHTML("../fixtures/contentExample.html"); + + // Editor content has changed => results updated + cy.wait("@updateResults"); + + // Go to report page to check text + images count (0) + cy.visit(`http://localhost:3000/rapport/${reportId}/details-des-non-conformites`); + // - 1 h4 + cy.get(".tiptap--rendered h4").should("have.length", 1); + // - 2 li + cy.get(".tiptap--rendered li").should("have.length", 2); + // - 0 img + cy.get(".tiptap--rendered img").should("have.length", 0); + }); + }); +}); diff --git a/cypress/e2e/audit/filters.cy.ts b/cypress/e2e/audit/filters.cy.ts new file mode 100644 index 000000000..f382a02c1 --- /dev/null +++ b/cypress/e2e/audit/filters.cy.ts @@ -0,0 +1,179 @@ +describe("Filters", () => { + it("User can search in criteria title", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.getByLabel("Recherche par mots clés") + .clear() + .type("alternative") + .type("{enter}"); + + cy.contains("9 résultats"); + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(9); + }); + }); + }); + + it("User can hide tests and references", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + cy.contains("Masquer les tests et références").click(); + cy.contains("Tests et références du critère 1.1").should("not.exist"); + }); + }); + + it("User can filter criteria", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + // Check total length + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(106); + }); + + // Check C criteria + cy.contains("Conforme (323)").click(); + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(36); + }); + cy.get("li.criterium-container").each((el) => { + cy.wrap(el) + .find("fieldset > div label") + .first() + .should("have.class", "green"); + }); + + // Add NA criteria + cy.contains("Non applicable (315)").click(); + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(71); + }); + cy.get("li.criterium-container").each((el) => { + cy.wrap(el) + .find("fieldset > div label") + .should( + "satisfy", + (el) => + el[0].classList.contains("green") || el.at(-1).contains("grey") + ); + }); + + // Add NC criteria + cy.contains("Non conforme (315)").click(); + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(106); + }); + cy.get("li.criterium-container").each((el) => { + cy.wrap(el) + .find("fieldset > div label") + .should( + "satisfy", + (el) => + el[0].classList.contains("green") || + el[1].contains("red") || + el.at(-1).contains("grey") + ); + }); + }); + }); + + it("User can filter evaluated criteria", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("Masquer les critères évalués").click(); + cy.contains("Tous les critères évalués ont été masqués"); + + cy.contains("Masquer les critères évalués").click(); + + cy.get("li.criterium-container fieldset input:checked") + .first() + .click({ force: true }); + + cy.get("li.criterium-container fieldset input:checked") + .eq(0) + .click({ force: true }); + + cy.contains("button[role=\"tab\"]", "Article").click(); + + cy.get("li.criterium-container fieldset input:checked") + .first() + .click({ force: true }); + + cy.contains("Masquer les critères évalués").click(); + cy.get("li.criterium-container").should("have.length", 1); + + cy.contains("button[role=\"tab\"]", "Éléments transverses").click(); + cy.get("li.criterium-container").should("have.length", 2); + + cy.get("li.criterium-container fieldset input") + .first() + .click({ force: true }); + + cy.contains("Mettre à jour critères masqués").click(); + + cy.get("li.criterium-container").should("have.length", 1); + }); + }); + + it("User can reset filters", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("Conforme (323)").click(); + cy.contains("Non applicable (315)").click(); + cy.contains("Masquer les tests et références").click(); + cy.getByLabel("Recherche par mots clés") + .clear() + .type("alternative") + .type("{enter}"); + + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(6); + }); + + cy.contains("button", "Réinitialiser").click(); + + cy.get("li.criterium-container").then((els) => { + expect(els).to.have.length(106); + }); + + cy.focused().should("have.attr", "placeholder", "Rechercher un critère"); + cy.contains("button", "Réinitialiser").should("not.exist"); + }); + }); + + it("User can automatically set as NA some linked criteria", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + // check that linked criteria are also NA + cy.get(".criterium-container").contains("Non applicable").click(); + cy.get(".criterium-container").eq(2).find("fieldset > div input[type='checkbox']").eq(2).should("be.checked"); + cy.get(".criterium-container").eq(2).contains("Vous avez évalué le critère 1.1 Non applicable"); + + // check that linked criteria get their previous status back + cy.get(".criterium-container").contains("Conforme").click(); + cy.get(".criterium-container").eq(2).find("fieldset > div input[type='checkbox']").eq(2).should("not.be.checked"); + cy.get(".criterium-container").eq(2).find("fieldset > div input[type='checkbox']").eq(1).should("be.checked"); + cy.get(".criterium-container").eq(2).contains("Vous avez évalué le critère 1.1 Non applicable").should("not.exist"); + }); + }); + + it("User can show or hide topic criteria", () => { + cy.createTestAudit({ isPristine: true }).then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + // Check total criteria count + cy.get(".criterium-container").should("have.length", 106); + + // Hide topic 1 criteria (-9) + cy.get("button.toggle-topic-button").first().click(); + cy.get(".criterium-container").should("have.length", 97); + + // Show topic 1 criteria (+9) + cy.get("button.toggle-topic-button").first().click(); + cy.get(".criterium-container").should("have.length", 106); + }); + }); +}); diff --git a/cypress/e2e/audit/notes.cy.ts b/cypress/e2e/audit/notes.cy.ts new file mode 100644 index 000000000..64431c2c9 --- /dev/null +++ b/cypress/e2e/audit/notes.cy.ts @@ -0,0 +1,19 @@ +describe("Notes", () => { + it("User can update notes", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.get(".notes-desktop-link") + .contains("button", "Ajouter des observations") + .click(); + + cy.get(".tiptap").type("Annotations de l’audit"); + cy.get("dialog#notes-modal").contains("button", "Fermer").click(); + + cy.get(".notes-desktop-link") + .contains("button", "Ajouter des observations") + .click(); + cy.contains("Annotations de l’audit"); + }); + }); +}); diff --git a/cypress/e2e/audit/transverse-tab.cy.ts b/cypress/e2e/audit/transverse-tab.cy.ts new file mode 100644 index 000000000..4f4c8bff6 --- /dev/null +++ b/cypress/e2e/audit/transverse-tab.cy.ts @@ -0,0 +1,56 @@ +describe("Tranverse tab", () => { + it("User can see transverse status and comment from other pages", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("button[role=\"tab\"]", "Documentation").click(); + cy.get(".criterium-container") + .eq(2) + .find(".criterium-transverse-notice") + .contains( + "Vous avez évalué ce critère Non conforme pour les éléments transverses." + ); + + cy.get(".criterium-container") + .eq(2) + .contains("button", "Voir les erreurs") + .click(); + + cy.get(".criterium-container").eq(2).contains("Une erreur ici"); + + cy.get(".criterium-container") + .eq(2) + .contains("button", "Masquer les erreurs") + .click(); + + cy.get(".criterium-container") + .eq(2) + .contains("Une erreur ici") + .should("not.exist"); + }); + }); + + it("User can add transverse elements", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/generation`); + + cy.contains("Lister les éléments transverses").click(); + cy.getByLabel("Nom de l’élément transverse").type( + "FoooElements, BarElements, ThingElements" + ); + cy.get(".transverse-elements").contains("Ajouter").click(); + + cy.contains("button", "FoooElements").should("exist"); + cy.contains("button", "BarElements").should("exist"); + cy.contains("button", "ThingElements").should("exist"); + + cy.contains("BarElements").click(); + + cy.contains("Enregistrer").click(); + + cy.contains("FoooElements").should("exist"); + cy.contains("BarElements").should("not.exist"); + cy.contains("ThingElements").should("exist"); + }); + }); +}); diff --git a/cypress/e2e/common.cy.ts b/cypress/e2e/common/common.cy.ts similarity index 100% rename from cypress/e2e/common.cy.ts rename to cypress/e2e/common/common.cy.ts diff --git a/cypress/e2e/report.cy.ts b/cypress/e2e/report.cy.ts deleted file mode 100644 index 761df9e21..000000000 --- a/cypress/e2e/report.cy.ts +++ /dev/null @@ -1,182 +0,0 @@ -import { TabSlug } from "../../confiture-web-app/src/enums"; -import * as auditJson from "../fixtures/audit.json"; -import * as statementJson from "../fixtures/statement.json"; -import { testTabReachByURL, testTabsWithPrevNext } from "./common"; - -// FIXME: weird behaviour with page reloads (caused by "fake tabs"?) -describe("Report", () => { - it("User can see audit in progress banner for in progress audit", () => { - cy.createTestAudit().then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("Résultats du rapport provisoires"); - }); - }); - - it("User can't see audit in progress banner for completed audit", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("Résultats du rapport provisoires").should("not.exist"); - }); - }); - - it("User can see audit header infos", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.get("[data-cy='report-header']").contains(auditJson.procedureName); - cy.get("[data-cy='report-header']").contains(`URL du site audité : ${statementJson.procedureUrl}`); - cy.get("[data-cy='report-header']").contains("Type d’audit : 106 critères"); - cy.get("[data-cy='report-header']").contains( - `Auditeur ou auditrice : ${auditJson.auditorName}` - ); - }); - }); - - it("User can copy report URL", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - // FIXME: svg logo is covering elements because - // Electron does not support CSS nesting for now. - // Adding `force: true` to click() function solves the problem. - cy.contains("button", "Copier le lien du rapport").click({ force: true }); - cy.assertClipboardValue(`http://localhost:3000/rapport/${reportId}/`); - cy.contains("button", "Lien copié"); - }); - }); - - it("User can download results", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("button", "Télécharger").click({ force: true }); - cy.contains("a", "Télécharger l'audit").click({ force: true }); - - cy.readFile("cypress/downloads/audit.csv"); - }); - }); - - it("User can see correct pages count and transverse criteria count", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.get("#repartition-des-criteres-par-pages + .fr-table tbody tr").then( - (els) => { - expect(els).to.have.length(8); - } - ); - - cy.contains( - "35 critères non conformes concernent des éléments transverses à toutes les pages de l’échantillon." - ); - }); - }); - - it("User can’t see improvements tab if there are no improvements with comment", () => { - cy.createTestAudit({ - isComplete: true, - hasNoImprovementsComments: true - }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("button", "Points d’amélioration").should("not.exist"); - }); - }); - - it("User can see pages anchors in improvements tab", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("button", "Détails des non-conformités").click(); - cy.get(".fr-sidemenu__item").then((els) => { - expect(els).to.have.length(9); - }); - }); - }); - - it("User can see pages anchors in errors tab", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("button", "Détails des non-conformités").click(); - cy.get(".fr-sidemenu__item").then((els) => { - expect(els).to.have.length(9); - }); - }); - }); - - it("User can filter errors", () => { - cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/rapport/${reportId}`); - cy.contains("button", "Détails des non-conformités").click(); - cy.contains("315 non-conformités"); - cy.get(".criterium-title").then((els) => { - expect(els).to.have.length(315); - }); - - // Check & uncheck easy to fix - cy.contains("Uniquement les erreurs faciles à corriger").click(); - cy.contains("45 non-conformités"); - cy.get(".criterium-title").then((els) => { - expect(els).to.have.length(45); - }); - cy.contains("Uniquement les erreurs faciles à corriger").click(); - - // Uncheck minor impact - cy.contains("Mineur (81)").click(); - cy.contains("234 non-conformités"); - cy.get(".criterium-title").then((els) => { - expect(els).to.have.length(234); - }); - - // Uncheck major impact - cy.contains("Majeur (81)").click(); - cy.contains("153 non-conformités"); - cy.get(".criterium-title").then((els) => { - expect(els).to.have.length(153); - }); - - // Uncheck blocking impact - cy.contains("Bloquant (81)").click(); - cy.contains("72 non-conformités"); - cy.get(".criterium-title").then((els) => { - expect(els).to.have.length(72); - }); - - // Uncheck not specified impact - cy.contains("Impact non renseigné (72)").click(); - cy.contains("0 non-conformité"); - cy.get(".criterium-title").should("not.exist"); - - // Reset filters - cy.contains("button", "Réinitialiser les filtres").click(); - cy.contains("315 non-conformités"); - cy.get(".criterium-title").then((els) => { - expect(els).to.have.length(315); - }); - }); - }); - - it("User can display the audit at a given tab directly thanks to a URL slug", () => { - cy.createTestAudit().then(({ reportId }) => { - const slug = TabSlug.REPORT_ERRORS_SLUG; - cy.visit(`http://localhost:3000/rapport/${reportId}/${slug}`); - testTabReachByURL(slug); - }); - }); - - it("User can go back to previous/next tab with navigator back and previous buttons", () => { - cy.createTestAudit().then(({ reportId }) => { - const slug = TabSlug.REPORT_ERRORS_SLUG; - const nextSlug = TabSlug.REPORT_IMPROVEMENTS_SLUG; - cy.visit(`http://localhost:3000/rapport/${reportId}/${slug}`); - testTabsWithPrevNext(slug, nextSlug); - }); - }); - - it("User can reach topics titles with anchors", () => { - cy.createTestAudit().then(({ reportId }) => { - const slug = TabSlug.REPORT_ERRORS_SLUG; - cy.visit(`http://localhost:3000/rapport/${reportId}/${slug}`); - cy.get(".fr-sidemenu__link") - .should("exist") - .each(($el, index) => { - cy.wrap($el).click(); - cy.get(".page-title").eq(index).should("exist").isWithinViewport(); - }); - }); - }); -}); diff --git a/cypress/e2e/report/header.cy.ts b/cypress/e2e/report/header.cy.ts new file mode 100644 index 000000000..9601d934e --- /dev/null +++ b/cypress/e2e/report/header.cy.ts @@ -0,0 +1,52 @@ +import * as auditJson from "../../fixtures/audit.json"; +import * as statementJson from "../../fixtures/statement.json"; + +describe("Report header", () => { + it("User can see audit in progress banner for in progress audit", () => { + cy.createTestAudit().then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("Résultats du rapport provisoires"); + }); + }); + + it("User can't see audit in progress banner for completed audit", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("Résultats du rapport provisoires").should("not.exist"); + }); + }); + + it("User can see audit header infos", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.get("[data-cy='report-header']").contains(auditJson.procedureName); + cy.get("[data-cy='report-header']").contains(`URL du site audité : ${statementJson.procedureUrl}`); + cy.get("[data-cy='report-header']").contains("Type d’audit : 106 critères"); + cy.get("[data-cy='report-header']").contains( + `Auditeur ou auditrice : ${auditJson.auditorName}` + ); + }); + }); + + it("User can copy report URL", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + // FIXME: svg logo is covering elements because + // Electron does not support CSS nesting for now. + // Adding `force: true` to click() function solves the problem. + cy.contains("button", "Copier le lien du rapport").click({ force: true }); + cy.assertClipboardValue(`http://localhost:3000/rapport/${reportId}/`); + cy.contains("button", "Lien copié"); + }); + }); + + it("User can download results", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("button", "Télécharger").click({ force: true }); + cy.contains("a", "Télécharger l'audit").click({ force: true }); + + cy.readFile("cypress/downloads/audit.csv"); + }); + }); +}); diff --git a/cypress/e2e/report/report.cy.ts b/cypress/e2e/report/report.cy.ts new file mode 100644 index 000000000..e9a61b704 --- /dev/null +++ b/cypress/e2e/report/report.cy.ts @@ -0,0 +1,83 @@ +import { TabSlug } from "../../../confiture-web-app/src/enums"; + +describe("Report", () => { + it("User can see correct pages count and transverse criteria count", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.get("#repartition-des-criteres-par-pages + .fr-table tbody tr").then( + (els) => { + expect(els).to.have.length(8); + } + ); + + cy.contains( + "35 critères non conformes concernent des éléments transverses à toutes les pages de l’échantillon." + ); + }); + }); + + it("User can filter errors", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("button", "Détails des non-conformités").click(); + cy.contains("315 non-conformités"); + cy.get(".criterium-title").then((els) => { + expect(els).to.have.length(315); + }); + + // Check & uncheck easy to fix + cy.contains("Uniquement les erreurs faciles à corriger").click(); + cy.contains("45 non-conformités"); + cy.get(".criterium-title").then((els) => { + expect(els).to.have.length(45); + }); + cy.contains("Uniquement les erreurs faciles à corriger").click(); + + // Uncheck minor impact + cy.contains("Mineur (81)").click(); + cy.contains("234 non-conformités"); + cy.get(".criterium-title").then((els) => { + expect(els).to.have.length(234); + }); + + // Uncheck major impact + cy.contains("Majeur (81)").click(); + cy.contains("153 non-conformités"); + cy.get(".criterium-title").then((els) => { + expect(els).to.have.length(153); + }); + + // Uncheck blocking impact + cy.contains("Bloquant (81)").click(); + cy.contains("72 non-conformités"); + cy.get(".criterium-title").then((els) => { + expect(els).to.have.length(72); + }); + + // Uncheck not specified impact + cy.contains("Impact non renseigné (72)").click(); + cy.contains("0 non-conformité"); + cy.get(".criterium-title").should("not.exist"); + + // Reset filters + cy.contains("button", "Réinitialiser les filtres").click(); + cy.contains("315 non-conformités"); + cy.get(".criterium-title").then((els) => { + expect(els).to.have.length(315); + }); + }); + }); + + it("User can reach topics titles with anchors", () => { + cy.createTestAudit().then(({ reportId }) => { + const slug = TabSlug.REPORT_ERRORS_SLUG; + cy.visit(`http://localhost:3000/rapport/${reportId}/${slug}`); + cy.get(".fr-sidemenu__link") + .should("exist") + .each(($el, index) => { + cy.wrap($el).click(); + cy.get(".page-title").eq(index).should("exist").isWithinViewport(); + }); + }); + }); +}); diff --git a/cypress/e2e/report/tabs.cy.ts b/cypress/e2e/report/tabs.cy.ts new file mode 100644 index 000000000..67eb0564a --- /dev/null +++ b/cypress/e2e/report/tabs.cy.ts @@ -0,0 +1,52 @@ +import { TabSlug } from "../../../confiture-web-app/src/enums"; +import { testTabsWithPrevNext, testTabReachByURL } from "../common"; + +// FIXME: weird behaviour with page reloads (caused by "fake tabs"?) +describe("Tabs", () => { + it("User can’t see improvements tab if there are no improvements with comment", () => { + cy.createTestAudit({ + isComplete: true, + hasNoImprovementsComments: true + }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("button", "Points d’amélioration").should("not.exist"); + }); + }); + + it("User can see pages anchors in improvements tab", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("button", "Détails des non-conformités").click(); + cy.get(".fr-sidemenu__item").then((els) => { + expect(els).to.have.length(9); + }); + }); + }); + + it("User can see pages anchors in errors tab", () => { + cy.createTestAudit({ isComplete: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/rapport/${reportId}`); + cy.contains("button", "Détails des non-conformités").click(); + cy.get(".fr-sidemenu__item").then((els) => { + expect(els).to.have.length(9); + }); + }); + }); + + it("User can go back to previous/next tab with navigator back and previous buttons", () => { + cy.createTestAudit().then(({ reportId }) => { + const slug = TabSlug.REPORT_ERRORS_SLUG; + const nextSlug = TabSlug.REPORT_IMPROVEMENTS_SLUG; + cy.visit(`http://localhost:3000/rapport/${reportId}/${slug}`); + testTabsWithPrevNext(slug, nextSlug); + }); + }); + + it("User can display the audit at a given tab directly thanks to a URL slug", () => { + cy.createTestAudit().then(({ reportId }) => { + const slug = TabSlug.REPORT_ERRORS_SLUG; + cy.visit(`http://localhost:3000/rapport/${reportId}/${slug}`); + testTabReachByURL(slug); + }); + }); +}); diff --git a/cypress/e2e/statement.cy.ts b/cypress/e2e/statement.cy.ts deleted file mode 100644 index a97d89fd7..000000000 --- a/cypress/e2e/statement.cy.ts +++ /dev/null @@ -1,16 +0,0 @@ -describe("Statement", () => { - it("User can copy statement html", () => { - cy.createTestAudit({ fillStatement: true }).then(({ reportId }) => { - cy.visit(`http://localhost:3000/declaration/${reportId}`); - cy.contains("Copier le code HTML").click(); - cy.contains("Code HTML copié"); - cy.window().focus(); - cy.window() - .its("navigator.clipboard") - .then(clipboard => clipboard.readText() - .then((t: string) => { - cy.wrap(t).should("not.be.empty"); - })); - }); - }); -}); diff --git a/cypress/e2e/statement/statement.cy.ts b/cypress/e2e/statement/statement.cy.ts new file mode 100644 index 000000000..b1929b12f --- /dev/null +++ b/cypress/e2e/statement/statement.cy.ts @@ -0,0 +1,88 @@ +import * as auditJson from "../../fixtures/audit.json"; +import * as statementJson from "../../fixtures/statement.json"; + +describe("Statement", () => { + it("User can fill a11y statement", () => { + cy.createTestAudit().then(({ editId }) => { + cy.visit(`http://localhost:3000/audits/${editId}/synthese`); + cy.contains("Compléter").invoke("removeAttr", "target").click(); + + // General infos + cy.getByLabel("Entité qui a demandé l’audit") + .clear() + .type(statementJson.auditInitiator); + cy.getByLabel("Entité qui a réalisé l’audit") + .clear() + .type(statementJson.auditorOrganisation); + cy.getByLabel("URL de la page d’accueil du site audité") + .clear() + .type(statementJson.procedureUrl); + + cy.getByLabel("Adresse e-mail").clear().type(statementJson.contactEmail); + cy.getByLabel("Formulaire de contact en ligne") + .clear() + .type(statementJson.contactFormUrl); + + // Technologies + cy.getByLabel("Ajouter des technologies") + .clear() + .type(statementJson.technologies); + + cy.contains("button", "Ajouter les technologies").click(); + + // Tools + cy.contains("Web Developer Toolbar").click(); + cy.contains("WCAG Contrast checker").click(); + cy.getByLabel("Ajouter des outils d’assistance") + .clear() + .type(statementJson.tools); + + cy.contains("button", "Ajouter les outils").click(); + + // Environments + cy.contains("Combinaison 1").click(); + cy.contains("button", "Ajouter un environnement de test").click(); + cy.getByLabel("Appareil").clear().type("Ordinateur"); + cy.getByLabel("Logiciel d’exploitation").clear().type("Windows"); + cy.getByLabel("Technologie d’assistance").clear().type("JAWS"); + cy.getByLabel("Navigateur").clear().type("Edge"); + + // Not accessible content + cy.get("[aria-labelledby='notCompliantContent']") + .clear() + .type(statementJson.notCompliantContent); + cy.get("[aria-labelledby='derogatedContent']") + .clear() + .type(statementJson.derogatedContent); + cy.get("[aria-labelledby='notInScopeContent']") + .clear() + .type(statementJson.notInScopeContent); + + cy.getByLabel("URL du schéma pluriannuel de mise en accessibilité (optionnel)") + .clear() + .type(statementJson.schemaPluriannuelUrl); + + cy.getByLabel("URL du plan d'actions en cours (optionnel)") + .clear() + .type(statementJson.planActionUrl); + + cy.contains("button", "Enregistrer").click(); + cy.contains("h1", auditJson.procedureName); + }); + }); + + it("User can copy statement html", () => { + cy.createTestAudit({ fillStatement: true }).then(({ reportId }) => { + cy.visit(`http://localhost:3000/declaration/${reportId}`); + cy.contains("Copier le code HTML").click(); + cy.contains("Code HTML copié"); + cy.window().focus(); + cy.window() + .its("navigator.clipboard") + .then(clipboard => clipboard.readText() + .then((t: string) => { + cy.wrap(t).should("not.be.empty"); + })); + }); + }); +});