From 1ee2b8fcd67591686039a25d87348e60a6a90c43 Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Thu, 5 Dec 2024 17:45:08 +0100 Subject: [PATCH] feat(admin): add CGU template and component --- admin/app/components/users/cgu.gjs | 58 ++++++++++++++++++ .../templates/authenticated/users/get/cgu.hbs | 10 +++ .../integration/components/users/cgu-test.gjs | 61 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 admin/app/components/users/cgu.gjs create mode 100644 admin/app/templates/authenticated/users/get/cgu.hbs create mode 100644 admin/tests/integration/components/users/cgu-test.gjs diff --git a/admin/app/components/users/cgu.gjs b/admin/app/components/users/cgu.gjs new file mode 100644 index 00000000000..555b53fe4fe --- /dev/null +++ b/admin/app/components/users/cgu.gjs @@ -0,0 +1,58 @@ +import { service } from '@ember/service'; +import Component from '@glimmer/component'; +import dayjs from 'dayjs'; +import { t } from 'ember-intl'; + +export default class Cgu extends Component { + @service accessControl; + @service intl; + + get userHasValidatePixAppTermsOfService() { + return this._formatValidatedTermsOfServiceText(this.args.lastTermsOfServiceValidatedAt, this.args.cgu); + } + + get userHasValidatePixOrgaTermsOfService() { + return this._formatValidatedTermsOfServiceText( + this.args.lastPixOrgaTermsOfServiceValidatedAt, + this.args.pixOrgaTermsOfServiceAccepted, + ); + } + + get userHasValidatePixCertifTermsOfService() { + return this._formatValidatedTermsOfServiceText( + this.args.lastPixCertifTermsOfServiceValidatedAt, + this.args.pixCertifTermsOfServiceAccepted, + ); + } + _formatValidatedTermsOfServiceText(date, hasValidatedTermsOfService) { + if (!hasValidatedTermsOfService) { + return this.intl.t('components.users.user-detail-personal-information.cgu.validation.status.non-validated'); + } + + return date + ? this.intl.t('components.users.user-detail-personal-information.cgu.validation.status.validated-with-date', { + formattedDate: dayjs(date).format('DD/MM/YYYY'), + }) + : this.intl.t('components.users.user-detail-personal-information.cgu.validation.status.validated'); + } + + +} diff --git a/admin/app/templates/authenticated/users/get/cgu.hbs b/admin/app/templates/authenticated/users/get/cgu.hbs new file mode 100644 index 00000000000..d5eb3d7f7e0 --- /dev/null +++ b/admin/app/templates/authenticated/users/get/cgu.hbs @@ -0,0 +1,10 @@ +
+ +
\ No newline at end of file diff --git a/admin/tests/integration/components/users/cgu-test.gjs b/admin/tests/integration/components/users/cgu-test.gjs new file mode 100644 index 00000000000..f5e0d904d42 --- /dev/null +++ b/admin/tests/integration/components/users/cgu-test.gjs @@ -0,0 +1,61 @@ +import { render } from '@1024pix/ember-testing-library'; +import { setupRenderingTest } from 'ember-qunit'; +import Cgu from 'pix-admin/components/users/cgu'; +import { module, test } from 'qunit'; + +import setupIntl from '../../../helpers/setup-intl'; + +module('Integration | Component | cgu', function (hooks) { + setupRenderingTest(hooks); + setupIntl(hooks); + + hooks.beforeEach(function () { + this.intl = this.owner.lookup('service:intl'); + }); + + test('displays correct Terms of Service status for Pix App, Pix Orga and Pix Certif', async function (assert) { + //Given + + const cgu = true; + const lastTermsOfServiceValidatedAt = new Date('2021-12-10'); + const pixOrgaTermsOfServiceAccepted = true; + const lastPixOrgaTermsOfServiceValidatedAt = null; + const pixCertifTermsOfServiceAccepted = false; + const lastPixCertifTermsOfServiceValidatedAt = null; + + const appDomain = this.intl.t('components.users.user-detail-personal-information.cgu.validation.domain.pix-app'); + const validatedWithDate = this.intl.t( + 'components.users.user-detail-personal-information.cgu.validation.status.validated-with-date', + { formattedDate: '10/12/2021' }, + ); + + const orgaDomain = this.intl.t('components.users.user-detail-personal-information.cgu.validation.domain.pix-orga'); + const validated = this.intl.t('components.users.user-detail-personal-information.cgu.validation.status.validated'); + + const certifDomain = this.intl.t( + 'components.users.user-detail-personal-information.cgu.validation.domain.pix-certif', + ); + const nonValidated = this.intl.t( + 'components.users.user-detail-personal-information.cgu.validation.status.non-validated', + ); + + //When + const screen = await render( + , + ); + + //Then + assert.dom(screen.queryByText(`${appDomain} ${validatedWithDate}`)).exists(); + assert.dom(screen.queryByText(`${orgaDomain} ${validated}`)).exists(); + assert.dom(screen.queryByText(`${certifDomain} ${nonValidated}`)).exists(); + }); +});