From 51b978e9035b671f28d673a73abaedd3cfadfa3d Mon Sep 17 00:00:00 2001 From: Xavier FACQ Date: Tue, 12 Mar 2024 08:31:33 +0100 Subject: [PATCH] [issues-2703] Update swag store link and add a disclaimer (#2709) * [issues-2703] Update swag store link and add a disclaimer * Update / Create tests * Coverage --------- Co-authored-by: Martijn Verburg --- locales/fr/leaving-site-disclaimer.json | 8 ++ .../__snapshots__/Footer.test.tsx.snap | 61 ++++++++- src/components/Footer/index.tsx | 15 ++- .../LeavingSiteDisclaimerModal.test.tsx | 26 ++++ .../LeavingSiteDisclaimerModal.test.tsx.snap | 121 ++++++++++++++++++ .../LeavingSiteDisclaimerModal/index.tsx | 55 ++++++++ 6 files changed, 282 insertions(+), 4 deletions(-) create mode 100644 locales/fr/leaving-site-disclaimer.json create mode 100644 src/components/LeavingSiteDisclaimerModal/__tests__/LeavingSiteDisclaimerModal.test.tsx create mode 100644 src/components/LeavingSiteDisclaimerModal/__tests__/__snapshots__/LeavingSiteDisclaimerModal.test.tsx.snap create mode 100644 src/components/LeavingSiteDisclaimerModal/index.tsx diff --git a/locales/fr/leaving-site-disclaimer.json b/locales/fr/leaving-site-disclaimer.json new file mode 100644 index 000000000..58d61f806 --- /dev/null +++ b/locales/fr/leaving-site-disclaimer.json @@ -0,0 +1,8 @@ +{ + "leaving.site.disclaimer.modal.title": "Avis de non-responsabilité - Vous allez quitter notre site Web", + "leaving.site.disclaimer.modal.continue": "Continuer", + "leaving.site.disclaimer.modal.close": "Fermer", + + "swag.store.disclaimer": "En cliquant sur le bouton Continuer, vous quitterez notre site Web. Veuillez noter que de nouvelles conditions d'utilisation s'appliqueront à la boutique Eclipse Foundation, alimentée par Fourthwall : https://eclipse-foundation.store/." + } + \ No newline at end of file diff --git a/src/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap b/src/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap index 0f0faa350..fa0b45997 100644 --- a/src/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap +++ b/src/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap @@ -8,6 +8,61 @@ exports[`Footer component > renders correctly 1`] = `
+
renders correctly 1`] = ` > Text diff --git a/src/components/Footer/index.tsx b/src/components/Footer/index.tsx index 86e154817..8cef26126 100644 --- a/src/components/Footer/index.tsx +++ b/src/components/Footer/index.tsx @@ -1,17 +1,21 @@ -import { Link } from 'gatsby-plugin-react-i18next'; import React from 'react'; import { FaYoutube, FaGithub, FaSlack, FaLinkedin } from 'react-icons/fa'; import { FaXTwitter } from 'react-icons/fa6'; import RandomContributor from '../RandomContributor'; import LanguageSelector from '../LanguageSelector'; -import { Trans } from 'gatsby-plugin-react-i18next'; +import { Link, Trans, useTranslation } from 'gatsby-plugin-react-i18next'; +import LeavingSiteDisclaimerModal from '../LeavingSiteDisclaimerModal'; import './Footer.scss'; const Footer = (): JSX.Element => { + + const {t} = useTranslation(); + return ( <>
+
@@ -51,7 +55,12 @@ const Footer = (): JSX.Element => {
  • -
  • +
  • diff --git a/src/components/LeavingSiteDisclaimerModal/__tests__/LeavingSiteDisclaimerModal.test.tsx b/src/components/LeavingSiteDisclaimerModal/__tests__/LeavingSiteDisclaimerModal.test.tsx new file mode 100644 index 000000000..55a74b7b9 --- /dev/null +++ b/src/components/LeavingSiteDisclaimerModal/__tests__/LeavingSiteDisclaimerModal.test.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import userEvent from '@testing-library/user-event'; +import { render, screen } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest' +import LeavingSiteDisclaimerModal from '..'; + +describe('LeavingSiteDisclaimerModal component', () => { + it('LeavingSiteDisclaimerModal renders correctly', () => { + const { container } = render( + + ); + expect(container).toMatchSnapshot(); + }); + + it('LeavingSiteDisclaimerModal continue correctly', async () => { + const { container } = render( + + ); + + const cancelButton = container.querySelector('button[class="btn btn-primary"]'); + + await userEvent.click(cancelButton).then(async() => { + expect(container).toMatchSnapshot(); + }); + }); +}); diff --git a/src/components/LeavingSiteDisclaimerModal/__tests__/__snapshots__/LeavingSiteDisclaimerModal.test.tsx.snap b/src/components/LeavingSiteDisclaimerModal/__tests__/__snapshots__/LeavingSiteDisclaimerModal.test.tsx.snap new file mode 100644 index 000000000..407a66baf --- /dev/null +++ b/src/components/LeavingSiteDisclaimerModal/__tests__/__snapshots__/LeavingSiteDisclaimerModal.test.tsx.snap @@ -0,0 +1,121 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`LeavingSiteDisclaimerModal component > LeavingSiteDisclaimerModal continue correctly 1`] = ` +
    + +
    +`; + +exports[`LeavingSiteDisclaimerModal component > LeavingSiteDisclaimerModal renders correctly 1`] = ` +
    + +
    +`; diff --git a/src/components/LeavingSiteDisclaimerModal/index.tsx b/src/components/LeavingSiteDisclaimerModal/index.tsx new file mode 100644 index 000000000..de91d5544 --- /dev/null +++ b/src/components/LeavingSiteDisclaimerModal/index.tsx @@ -0,0 +1,55 @@ +import React, { useState } from "react"; +import { Trans } from 'gatsby-plugin-react-i18next'; + +const LeavingSiteDisclaimerModal = () => { + + const [message, setMessage] = useState(''); + const [location, setLocation] = useState(''); + + if (typeof window !== `undefined`) { + window.addEventListener('show.bs.modal', (event: Event) => { + let button = event.relatedTarget; + setMessage(button.getAttribute('data-bs-message')) + setLocation(button.getAttribute('data-bs-location')) + }); + } + + return ( + <> + + + ); +}; + +export default LeavingSiteDisclaimerModal;