Skip to content

Commit

Permalink
use object options in create test audit and fix wait tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bellangerq committed Nov 28, 2024
1 parent 70af275 commit 7ee3bbb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 53 deletions.
4 changes: 2 additions & 2 deletions confiture-rest-api/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { CRITERIA } from "../src/audits/criteria";
import { nanoid } from "nanoid";

async function main() {
const isComplete = process.argv.at(2) === "--complete";
const hasNoImprovementsComments = process.argv.at(3) === "--no-impr";
const isComplete = process.argv.includes("--complete");
const hasNoImprovementsComments = process.argv.includes("--no-impr");

const prisma = new PrismaClient();

Expand Down
4 changes: 3 additions & 1 deletion confiture-web-app/src/pages/report/ReportPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const tabs = computed(() => [
const showCopyAlert = ref(false);
async function copyReportUrl() {
const url = `${window.location.origin}/rapports/${uniqueId}`;
const url =
window.location.origin +
router.resolve({ name: "report", params: { uniqueId } }).fullPath;
navigator.clipboard.writeText(url).then(() => {
showCopyAlert.value = true;
Expand Down
49 changes: 25 additions & 24 deletions cypress/e2e/report.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ import * as statementJson from "../fixtures/statement.json";
describe("Report", () => {
it("User can see audit in progress banner for in progress audit", () => {
cy.createTestAudit().then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
cy.visit(`http://localhost:3000/rapport/${reportId}`);
cy.contains(
"Les résultats de ce rapport sont provisoires tant que l’audit n'est pas terminé.",
);
});
});

it("User can't see audit in progress banner for completed audit", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
// FIXME: how to force Cy to wait until UI refreshes?
cy.wait(5000);
cy.createTestAudit({ isComplete: true }).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapport/${reportId}`);
cy.get(".header").contains(auditJson.procedureName);
cy.contains(
"Les résultats de ce rapport sont provisoires tant que l’audit n'est pas terminé.",
).should("not.exist");
});
});

it("User can see audit header infos", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
cy.createTestAudit({ isComplete: true }).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapport/${reportId}`);
cy.get(".header").contains(auditJson.procedureName);
cy.get(".header").contains(`URL du site : ${statementJson.procedureUrl}`);
cy.get(".header").contains("Type d’audit : 106 critères");
Expand All @@ -36,19 +35,19 @@ describe("Report", () => {
});

it("User can copy report URL", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
cy.createTestAudit({ isComplete: true }).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapport/${reportId}`);
cy.contains("button", "Copier le lien du rapport").click();
cy.assertClipboardValue(`http://localhost:3000/rapports/${reportId}`);
cy.assertClipboardValue(`http://localhost:3000/rapport/${reportId}`);
cy.contains(
"Le lien vers le rapport a bien été copié dans le presse-papier.",
);
});
});

it("User can download results", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
cy.createTestAudit({ isComplete: true }).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapport/${reportId}`);
cy.contains("button", "Télécharger").click();
cy.contains("a", "Télécharger l'audit").click();

Expand All @@ -57,8 +56,8 @@ describe("Report", () => {
});

it("User can see correct pages count and transverse criteria count", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
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);
Expand All @@ -72,17 +71,19 @@ describe("Report", () => {
});

it("User can’t see improvements tab if there are no improvements with comment", () => {
cy.createTestAudit(true, true).then(({ reportId, pouet }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
// FIXME: wait
cy.wait(5000);
cy.createTestAudit({
isComplete: true,
hasNoImprovementsComments: true,
}).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapport/${reportId}`);
cy.get(".header").contains(auditJson.procedureName);
cy.contains("button", "Points d’amélioration").should("not.exist");
});
});

it("User can see pages anchors in improvements tab", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
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("#tabpanel-points-damelioration-panel .fr-sidemenu__item").then(
(els) => {
Expand All @@ -93,8 +94,8 @@ describe("Report", () => {
});

it("User can see pages anchors in errors tab", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
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(
"#tabpanel-details-des-non-conformites-panel .fr-sidemenu__item",
Expand All @@ -105,8 +106,8 @@ describe("Report", () => {
});

it("User can filter errors", () => {
cy.createTestAudit(true).then(({ reportId }) => {
cy.visit(`http://localhost:3000/rapports/${reportId}`);
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 résultats");
cy.get(
Expand Down
53 changes: 27 additions & 26 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
// }
// }

interface CreateTestAuditOptions {
isComplete?: boolean;
hasNoImprovementsComments?: boolean;
}

declare global {
namespace Cypress {
interface Chainable {
Expand All @@ -55,10 +60,7 @@ declare global {
* Create a test audit with auto generated IDs
* @example cy.createTestAudit(true, true)
*/
createTestAudit(
isComplete?: boolean,
hasNoImprovementsComments?: boolean,
): Chainable;
createTestAudit(options?: CreateTestAuditOptions): Chainable;
}
}
}
Expand Down Expand Up @@ -86,29 +88,28 @@ Cypress.Commands.add("assertClipboardValue", (value: string) => {
});
});

Cypress.Commands.add(
"createTestAudit",
(isComplete?: boolean, hasNoImprovementsComments?: boolean) => {
cy.exec(
`yarn run tests:seed-debug-audit ${isComplete ? "--complete" : ""} ${
hasNoImprovementsComments ? "--no-impr" : ""
}`,
).then((result) => {
if (result.code !== 0) {
// failure
throw "Command exited with non-zero code";
}
Cypress.Commands.add("createTestAudit", (options?: CreateTestAuditOptions) => {
const isComplete = options?.isComplete;
const hasNoImprovementsComments = options?.hasNoImprovementsComments;
cy.exec(
`yarn run tests:seed-debug-audit ${isComplete ? "--complete" : ""} ${
hasNoImprovementsComments ? "--no-impr" : ""
}`,
).then((result) => {
if (result.code !== 0) {
// failure
throw "Command exited with non-zero code";
}

// sucesss
const json = result.stdout.split("\n")[1];
const data = JSON.parse(json);
// sucesss
const json = result.stdout.split("\n")[1];
const data = JSON.parse(json);

return {
editId: data.editId,
reportId: data.reportId,
};
});
},
);
return {
editId: data.editId,
reportId: data.reportId,
};
});
});

export {};

0 comments on commit 7ee3bbb

Please sign in to comment.