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

fix(contributions): remettre les titres des contribs avec le nom de la question pour afficher dans le front le nom de la CC dans le h1 #1526

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("generateMetadata", () => {
breadcrumbs
);

expect(metadata.title).toBe("Question - CC Short title");
expect(metadata.title).toBe("Question");
expect(metadata.text).toBe("Description");
expect(metadata.metas.title).toBe("SEO Title - CC Short title");
expect(metadata.metas.description).toBe("Question - Description");
Expand All @@ -120,97 +120,11 @@ describe("generateMetadata", () => {
breadcrumbs
);

expect(metadata.title).toBe("Question - CC Short title");
expect(metadata.title).toBe("Question");
expect(metadata.text).toBe("Description");
expect(metadata.metas.title).toBe("Breadcrumb 2 - CC Short title");
expect(metadata.metas.description).toBe("Question - Description");
});
});
});

describe("Page personnalisée avec une question longue et nom de la CC long", () => {
const ccns: Partial<DocumentElasticWithSource<AgreementDoc>>[] = [
{
num: 123,
shortTitle: "Nom de CC trop long",
},
];

const contribution: Partial<
DocumentElasticWithSource<ContributionDocumentJson>
> = {
idcc: "123",
questionName: "Question très longue avec plus de cinquante caractères ?",
seoTitle: "",
description: "Description",
};

it("doit générer un titre avec seulement la question (sans le nom de la convention collective)", () => {
const metadata: ContributionMetadata = generateMetadata(
ccns as DocumentElasticWithSource<AgreementDoc>[],
contribution as DocumentElasticWithSource<ContributionDocumentJson>,
breadcrumbs
);

expect(metadata.title).toBe(
"Question très longue avec plus de cinquante caractères ?"
);
});
});

describe("Page personnalisée avec une question courte et nom de la CC long", () => {
const ccns: Partial<DocumentElasticWithSource<AgreementDoc>>[] = [
{
num: 123,
shortTitle: "Nom de CC trop long",
},
];

const contribution: Partial<
DocumentElasticWithSource<ContributionDocumentJson>
> = {
idcc: "123",
questionName: "Question très courte ?",
seoTitle: "",
description: "Description",
};

it("doit générer un titre avec seulement la question (sans le nom de la convention collective)", () => {
const metadata: ContributionMetadata = generateMetadata(
ccns as DocumentElasticWithSource<AgreementDoc>[],
contribution as DocumentElasticWithSource<ContributionDocumentJson>,
breadcrumbs
);

expect(metadata.title).toBe("Question très courte ?");
});
});

describe("Page personnalisée avec une question courte et nom de la CC court", () => {
const ccns: Partial<DocumentElasticWithSource<AgreementDoc>>[] = [
{
num: 123,
shortTitle: "CC court",
},
];

const contribution: Partial<
DocumentElasticWithSource<ContributionDocumentJson>
> = {
idcc: "123",
questionName: "Question très courte ?",
seoTitle: "",
description: "Description",
};

it("doit générer un titre avec la question et le nom de la convention collective", () => {
const metadata: ContributionMetadata = generateMetadata(
ccns as DocumentElasticWithSource<AgreementDoc>[],
contribution as DocumentElasticWithSource<ContributionDocumentJson>,
breadcrumbs
);

expect(metadata.title).toBe("Question très courte ? - CC court");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ import {
export const generateMetadata = (
agreements: DocumentElasticWithSource<AgreementDoc>[],
contribution: DocumentElasticWithSource<ContributionDocumentJson>,
breadcrumbs: Breadcrumb[]
breadcrumbs: Breadcrumb[],
): ContributionMetadata => {
if (contribution.idcc === "0000") {
return generateGenericMetadata(contribution);
}

const agreement = agreements.find(
(v) => v.num === parseInt(contribution.idcc)
(v) => v.num === parseInt(contribution.idcc),
);

if (!agreement) {
throw new Error(
`Can't find the agreement (${contribution.idcc}) information for contribution ${contribution.questionIndex} - ${contribution.questionName} (${contribution.id})`
`Can't find the agreement (${contribution.idcc}) information for contribution ${contribution.questionIndex} - ${contribution.questionName} (${contribution.id})`,
);
}

if (breadcrumbs.length === 0) {
throw new Error(
`Contribution ${contribution.questionIndex} - ${contribution.questionName} (${contribution.id}) must be themed`
`Contribution ${contribution.questionIndex} - ${contribution.questionName} (${contribution.id}) must be themed`,
);
}

return generateCustomMetadata(
contribution,
breadcrumbs[breadcrumbs.length - 1],
agreement
agreement,
);
};

const generateGenericMetadata = (
contribution: DocumentElasticWithSource<ContributionDocumentJson>
contribution: DocumentElasticWithSource<ContributionDocumentJson>,
): ContributionMetadata => {
return {
title: contribution.questionName,
Expand All @@ -54,39 +54,26 @@ const generateGenericMetadata = (
const generateCustomMetadata = (
contribution: DocumentElasticWithSource<ContributionDocumentJson>,
breadcrumb: Breadcrumb,
agreement: DocumentElasticWithSource<AgreementDoc>
agreement: DocumentElasticWithSource<AgreementDoc>,
): ContributionMetadata => {
return {
title: generateTitle(contribution.questionName, agreement.shortTitle),
title: contribution.questionName,
text: contribution.description,
metas: {
title: generateMetaTitle(
contribution.seoTitle,
breadcrumb,
agreement.shortTitle
agreement.shortTitle,
),
description: `${contribution.questionName} - ${contribution.description}`,
},
};
};
const generateTitle = (
questionName: string,
agreementShortTitle: string | undefined
) => {
if (
!agreementShortTitle ||
agreementShortTitle.length > 14 ||
questionName.length > 50
) {
return questionName;
}
return `${questionName} - ${agreementShortTitle}`;
};

const generateMetaTitle = (
seoTitle: string | undefined,
breadcrumb: Breadcrumb,
agreementShortTitle: string
agreementShortTitle: string,
): string => {
if (seoTitle && seoTitle !== "") {
return `${seoTitle} - ${agreementShortTitle}`;
Expand Down
Loading