Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppression des tests e2e #172

Merged
merged 11 commits into from Feb 6, 2023
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -14,7 +14,7 @@
"build": "vite build",
"build:test": "vite build --mode test",
cedricr marked this conversation as resolved.
Show resolved Hide resolved
"start": "node build",
"preview": "vite preview --port 3000 --strictPort",
cedricr marked this conversation as resolved.
Show resolved Hide resolved
"preview": "vite preview",
"test": "playwright test",
"test:debug": "playwright test --debug",
"test:unit": "vitest",
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/specialized/service-search.svelte
Expand Up @@ -80,7 +80,10 @@
: [];
</script>

<div class="w-full rounded-md border border-gray-02 bg-white">
<div
id="home-search-form"
class="w-full rounded-md border border-gray-02 bg-white"
>
{#if servicesOptions.categories}
<form class="grid" on:submit|preventDefault={handleSearch}>
<div
Expand Down
5 changes: 4 additions & 1 deletion src/lib/utils/misc.ts
Expand Up @@ -14,7 +14,10 @@ export function markdownToHTML(markdownContent: string, titleLevel = 2) {
simplifiedAutoLink: true,
});

return insane(converter.makeHtml(markdownContent));
return insane(converter.makeHtml(markdownContent)).replace(
/target="_blank"/g,
AlexandreCantin marked this conversation as resolved.
Show resolved Hide resolved
'target="_blank" rel="nofollow"'
);
}

export function htmlToMarkdown(html: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/markdownToHTML.test.ts
@@ -1,4 +1,4 @@
import { markdownToHTML } from "$lib/utils/index";
import { markdownToHTML } from "$lib/utils/misc";
import { describe, expect, test } from "vitest";

describe("markdownToHTML", () => {
Expand All @@ -10,7 +10,7 @@ describe("markdownToHTML", () => {
const text = `[https://perdu.com/](Perdu) - [https://www.google.fr/](Google)`;

expect(markdownToHTML(text)).toBe(
'<p><a href="Perdu" rel="nofollow">https://perdu.com/</a> - <a href="Google" rel="nofollow">https://www.google.fr/</a></p>'
'<p><a href="Perdu" target="_blank" rel="nofollow">https://perdu.com/</a> - <a href="Google" target="_blank" rel="nofollow">https://www.google.fr/</a></p>'
);
});

Expand Down
108 changes: 96 additions & 12 deletions src/tests/utils/service/computeUpdateStatusData.test.ts
Expand Up @@ -14,9 +14,10 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
});

test("moins d'un jour", () => {
// ÉTANT DONNÉ un service modifié à 13h
// ÉTANT DONNÉ un service publié et modifié à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le même jour à 14h
Expand All @@ -37,9 +38,10 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
});

test("moins d'une semaine", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 6 janvier à 14h
Expand All @@ -61,9 +63,10 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
});

test("moins de deux semaines", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 13 janvier à 14h
Expand All @@ -84,9 +87,10 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
expect(label).toStrictEqual("Actualisé il y a 1 semaine");
});
test("moins d'un mois", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 28 janvier à 14h
Expand All @@ -108,9 +112,10 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
});

test("plus d'un mois", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 10 février à 14h
Expand All @@ -132,9 +137,10 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
});

test("plus de 3 mois", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 10 avril à 14h
Expand All @@ -155,10 +161,11 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
expect(label).toStrictEqual("Actualisé il y a 3 mois");
});

test("plus de 6 mois", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
test("plus de 6 mois et service publié", () => {
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 10 juillet à 14h
Expand All @@ -179,10 +186,36 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
expect(label).toStrictEqual("Actualisé il y a 6 mois");
});

test("plus de 10 mois", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier à 13h
test("plus de 6 mois et service en brouillon", () => {
// ÉTANT DONNÉ un service en brouillon et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "DRAFT",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 10 juillet à 14h
const date = new Date(2022, 7, 10, 14);
vi.setSystemTime(date);

const res = computeUpdateStatusData(service);
const label = computeUpdateStatusLabel({ ...res });

// ALORS l'actualisation n'est demandée
expect(res).toStrictEqual({
dayDiff: 190,
weekDiff: 27,
monthDiff: 6,
yearDiff: 0,
updateStatus: "NOT_NEEDED",
});
expect(label).toStrictEqual("Actualisé il y a 6 mois");
});

test("plus de 10 mois et service publié", () => {
// ÉTANT DONNÉ un service publié et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 10 octobre à 14h
Expand All @@ -203,10 +236,36 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
expect(label).toStrictEqual("Actualisé il y a 9 mois");
});

test("plus de 2 ans", () => {
// ÉTANT DONNÉ un service modifié le 1er janvier 2022 à 13h
test("plus de 10 mois et service en brouillon", () => {
// ÉTANT DONNÉ un service en brouillon et modifié le 1er janvier à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "DRAFT",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 10 octobre à 14h
const date = new Date(2022, 10, 10, 14);
vi.setSystemTime(date);

const res = computeUpdateStatusData(service);
const label = computeUpdateStatusLabel({ ...res });

// ALORS l'actualisation n'est pas requise
expect(res).toStrictEqual({
dayDiff: 282,
weekDiff: 40,
monthDiff: 9,
yearDiff: 0,
updateStatus: "NOT_NEEDED",
});
expect(label).toStrictEqual("Actualisé il y a 9 mois");
});

test("plus de 2 ans et service publié", () => {
// ÉTANT DONNÉ un service publié et modifié le 1er janvier 2022 à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "PUBLISHED",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 1 janvier 2024
Expand All @@ -226,4 +285,29 @@ describe("computeUpdateStatusData et computeUpdateStatusDataLabel", () => {
});
expect(label).toStrictEqual("Actualisé il y a plus de 2 ans");
});

test("plus de 2 ans et service en brouillon", () => {
// ÉTANT DONNÉ un service en brouillon et modifié le 1er janvier 2022 à 13h
const service = {
modificationDate: new Date(2022, 1, 1, 13),
status: "DRAFT",
} as unknown as Service;

// SI je récupère ses données d'actualisation le 1 janvier 2024
const date = new Date(2024, 10, 10, 14);
vi.setSystemTime(date);

const res = computeUpdateStatusData(service);
const label = computeUpdateStatusLabel({ ...res });

// ALORS l'actualisation est obligatoire et il est considéré comme actualisé il y a plus de 2 ans
expect(res).toStrictEqual({
dayDiff: 1013,
weekDiff: 144,
monthDiff: 33,
yearDiff: 2,
updateStatus: "NOT_NEEDED",
});
expect(label).toStrictEqual("Actualisé il y a plus de 2 ans");
});
});
94 changes: 94 additions & 0 deletions tests/mocks/mockStructure.ts
@@ -0,0 +1,94 @@
export function createFakeStructure({
name = "DUMMY STRUCTURE",
slug = "dummy-structure",
creationDate = "2022-01-01T01:00:00.000000+02:00",
modificationDate = "2022-01-01T01:00:00.000000+02:00",
status = "PUBLISHED",
}) {
return {
accesslibreUrl: null,
address1: "",
address2: "",
ape: "",
archivedServices: [],
branches: [],
canWrite: false,
city: "",
cityCode: "",
codeSafirPe: null,
creationDate,
department: "",
email: "",
fullDesc: "",
hasAdmin: true,
hasBeenEdited: false,
isAdmin: false,
isMember: false,
isPendingMember: false,
latitude: null,
longitude: null,
models: [],
modificationDate,
name: name,
nationalLabels: [],
numModels: 0,
numServices: 1,
openingHours: null,
openingHoursDetails: null,
otherLabels: "",
parent: "linklusion",
phone: "",
postalCode: "",
services: [
{
address1: "8 Impasse Bonnet",
address2: "O Local",
categoriesDisplay: [
"Création d’activité",
"Numérique",
"Difficultés financières",
"Acco. global individualisé",
"Handicap",
"Remobilisation",
"Accès aux droits & citoyenneté",
],
category: "creation-activite",
categoryDisplay: "Création d’activité",
city: "Toulouse",
cityCode: "31555",
contactEmail: "arnaud@linklusion.fr",
contactName: "Arnaud Leveneur",
contactPhone: "0600000000",
department: "31",
diffusionZoneDetailsDisplay: "Haute-Garonne",
diffusionZoneType: "department",
diffusionZoneTypeDisplay: "Département",
isAvailable: true,
isCumulative: true,
locationKinds: ["en-presentiel", "a-distance"],
locationKindsDisplay: ["En présentiel", "À distance"],
model: null,
modelChanged: null,
modificationDate,
name: name,
postalCode: "31500",
remoteUrl: "",
shortDesc: "",
slug: slug,
status,
structure: "tih-booster-haute-ga",
useInclusionNumeriqueScheme: false,
},
],
shortDesc: "",
siret: "82371229400078",
slug: slug,
source: {
value: "porteur",
label: "Porteur",
},
typology: "Autre",
typologyDisplay: "Autre",
url: "",
};
}
1 change: 1 addition & 0 deletions tests/mocks/mockUser.ts
Expand Up @@ -24,6 +24,7 @@ export function createFakeUser({
lastName: "LastName",
newsletter: false,
pendingStructures: [],
bookmarks: [],
phoneNumber: "",
shortName: "Name",
structures,
Expand Down
2 changes: 1 addition & 1 deletion tests/pages/home.ts
Expand Up @@ -2,7 +2,7 @@ export const HOME_URL = "/";

export const HOME_SELECTORS = {};
HOME_SELECTORS.SEARCH_FORM = "#home-search-form";
HOME_SELECTORS.FORM_LABELS = `${HOME_SELECTORS.SEARCH_FORM} h4`;
// HOME_SELECTORS.FORM_LABELS = `${HOME_SELECTORS.SEARCH_FORM} label`;

/*
export async function fillSearchForm({
Expand Down
10 changes: 10 additions & 0 deletions tests/pages/service.ts
Expand Up @@ -15,6 +15,16 @@ export async function mockGetServiceResponse(context, service) {
});
});
}
export async function mockGetStructureResponse(context, structure) {
await context.route(
`**/structures/${encodeURI(structure.name)}/`,
(route) => {
return route.fulfill({
body: JSON.stringify(structure),
});
}
);
}

export async function goToServicePage(page, service) {
await page.goto(`/services/${service.slug}`);
Expand Down