Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Added a PlayWright test for user cookie consent
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed May 5, 2023
1 parent b35cf8c commit 656e54c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function Domego( { Component, pageProps }: AppProps )
// Désactivation de l'interaction avec la page.
disablePageInteraction: true,

// Disparition du mécanisme pour les robots.
hideFromBots: process.env.NODE_ENV === "production",

// Paramètres internes des cookies.
cookie: {
path: basePath
Expand Down
19 changes: 18 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
//
import dynamic from "next/dynamic";
import { useRouter } from "next/router";
import * as CookieConsent from "vanilla-cookieconsent";
import type { SweetAlertIcon } from "sweetalert2";
import { useTranslation, Trans } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { useState, useContext, useEffect, ChangeEvent } from "react";
import { useState, useContext, useEffect, ChangeEvent, MouseEvent } from "react";

import styles from "./index.module.scss";
import { UserType } from "@/enums/User";
Expand Down Expand Up @@ -198,6 +199,13 @@ export default function GameHome()
setDisabled( !event.target.validity.valid );
};

// Affichage de la fenêtre de préférences des cookies.
const showPreferences = ( event: MouseEvent<HTMLAnchorElement> ) =>
{
event.preventDefault();
CookieConsent.showPreferences();
};

// Préchargement de la page de sélection de la partie.
useEffect( () =>
{
Expand Down Expand Up @@ -262,6 +270,15 @@ export default function GameHome()
a2: <a href="https://policies.google.com/terms">...</a>
}}
/>

<br />

<Trans
i18nKey="pages.index.cookies_preferences"
components={{
a1: <a href="#cookies" onClick={showPreferences}>...</a>
}}
/>
</small>
</section>
);
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"create_new_game": "Create a new game",
"games_available": "Available games",
"send_chat_message": "Send",
"google_recaptcha": "This site is protected by reCAPTCHA and the Google <a1>Privacy Policy</a1> and <a2>Terms of Service</a2> apply."
"google_recaptcha": "This site is protected by reCAPTCHA and the Google <a1>Privacy Policy</a1> and <a2>Terms of Service</a2> apply.",
"cookies_preferences": "This site uses cookies to offer you the best possible experience. You can <a1>manage your preferences</a1> at any time."
},
"rooms": {
"join": "Join",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"create_new_game": "Créer une partie",
"games_available": "Parties disponibles",
"send_chat_message": "Envoyer",
"google_recaptcha": "Ce site est protégé par reCAPTCHA sur lequel s'appliquent les <a1>politiques de confidentialité</a1> et les <a2>conditions d'utilisation</a2> de Google."
"google_recaptcha": "Ce site est protégé par reCAPTCHA sur lequel s'appliquent les <a1>politiques de confidentialité</a1> et les <a2>conditions d'utilisation</a2> de Google.",
"cookies_preferences": "Ce site utilise des cookies pour vous offrir la meilleure expérience possible. Vous pouvez <a1>gérer vos préférences</a1> à tout moment."
},
"rooms": {
"join": "Rejoindre",
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ test( "Vérification de certains contenus", async ( { page } ) =>
await expect( page.getByText( "A serious educational game" ) ).toBeVisible();
} );

//
// Permet de vérifier que le consentement des cookies fonctionne.
//
test( "Affichage du consentement des cookies", async ( { page } ) =>
{
// Clic sur le bouton du consentement des cookies.
await page.getByRole( "link", { name: "manage your preferences" } ).click();

// Sauvegarde des préférences actuelles.
await page.getByRole( "button", { name: "Save preferences" } ).click();

// Vérification de la page actuelle.
await expect( page ).toHaveURL( "/" );
} );

//
// Permet de vérifier qu'il est possible d'annuler la création d'une nouvelle partie.
//
Expand Down

0 comments on commit 656e54c

Please sign in to comment.