From 461c2a2f4377d6bd86d24c17e5f1da99424004db Mon Sep 17 00:00:00 2001 From: Xavier Carron <33637571+xav-car@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:13:53 +0100 Subject: [PATCH] remove unused component --- mon-pix/app/components/form-textfield.hbs | 78 ----- mon-pix/app/components/form-textfield.js | 102 ------- .../components/form-textfield-test.js | 278 ------------------ 3 files changed, 458 deletions(-) delete mode 100644 mon-pix/app/components/form-textfield.hbs delete mode 100644 mon-pix/app/components/form-textfield.js delete mode 100644 mon-pix/tests/integration/components/form-textfield-test.js diff --git a/mon-pix/app/components/form-textfield.hbs b/mon-pix/app/components/form-textfield.hbs deleted file mode 100644 index 79b70e18064..00000000000 --- a/mon-pix/app/components/form-textfield.hbs +++ /dev/null @@ -1,78 +0,0 @@ -{{! DEPRECATED COMPONENT: DON’T USE IT! USE COMPONENTS OF THE DESIGN SYSTEM INSTEAD!! }} - -{{! template-lint-disable require-input-label no-unknown-arguments-for-builtin-components }} -
- - -
- -
- {{#if this.isPassword}} - {{#if this.isPasswordVisible}} - - {{else}} - - {{/if}} - {{/if}} - - {{#if this.hasIcon}} - {{#if (eq @validationStatus "error")}} - {{t - {{else}} - {{t - {{/if}} - {{/if}} -
-
- - -
\ No newline at end of file diff --git a/mon-pix/app/components/form-textfield.js b/mon-pix/app/components/form-textfield.js deleted file mode 100644 index f8496d98642..00000000000 --- a/mon-pix/app/components/form-textfield.js +++ /dev/null @@ -1,102 +0,0 @@ -// DEPRECATED COMPONENT: DON’T USE IT! USE COMPONENTS OF THE DESIGN SYSTEM INSTEAD! - -import { action } from '@ember/object'; -import { isEmpty } from '@ember/utils'; -import Component from '@glimmer/component'; -import { tracked } from '@glimmer/tracking'; - -const INPUT_VALIDATION_STATUS_MAP = { - default: 'form-textfield__input--default', - error: 'form-textfield__input--error', - success: 'form-textfield__input--success', -}; - -const ICON_TYPE_STATUS_MAP = { - default: '', - error: 'error', - success: 'success', -}; - -const MESSAGE_VALIDATION_STATUS_MAP = { - default: 'form-textfield__message--default', - error: 'form-textfield__message--error', - success: 'form-textfield__message--success', -}; - -const INPUT_CONTAINER_VALIDATION_STATUS_MAP = { - default: 'form-textfield__input-container--default', - error: 'form-textfield__input-container--error', - success: 'form-textfield__input-container--success', -}; - -export default class FormTextfield extends Component { - @tracked isPasswordVisible = false; - - onValidate; - - constructor() { - super(...arguments); - this.onValidate = this.args.onValidate || (() => {}); - } - - get isPassword() { - return this.args.textfieldName === 'password'; - } - - get isEmail() { - return this.args.textfieldName === 'email'; - } - - get textfieldType() { - switch (this.args.textfieldName) { - case 'password': - return this.isPasswordVisible ? 'text' : 'password'; - case 'email': - return 'email'; - default: - return 'text'; - } - } - - get hasIcon() { - return this._isValidationStatusNotDefault() && !this.args.disabled; - } - - _isValidationStatusNotDefault() { - return this.args.validationStatus !== 'default'; - } - - get displayMessage() { - return !isEmpty(this.args.validationMessage) || this.hasIcon; - } - - get inputContainerStatusClass() { - return INPUT_CONTAINER_VALIDATION_STATUS_MAP[this.args.validationStatus] || null; - } - - get iconType() { - return ICON_TYPE_STATUS_MAP[this.args.validationStatus] || ''; - } - - get inputValidationStatus() { - return INPUT_VALIDATION_STATUS_MAP[this.args.validationStatus] || ''; - } - - get validationMessageClass() { - return MESSAGE_VALIDATION_STATUS_MAP[this.args.validationStatus] || ''; - } - - @action - onInput(event) { - this.args?.onInput(event); - } - - @action - togglePasswordVisibility() { - this.isPasswordVisible = !this.isPasswordVisible; - const InputElement = document.getElementById('password'); - if (InputElement) { - InputElement.focus(); - } - } -} diff --git a/mon-pix/tests/integration/components/form-textfield-test.js b/mon-pix/tests/integration/components/form-textfield-test.js deleted file mode 100644 index d60fdf1be09..00000000000 --- a/mon-pix/tests/integration/components/form-textfield-test.js +++ /dev/null @@ -1,278 +0,0 @@ -import { render } from '@1024pix/ember-testing-library'; -// eslint-disable-next-line no-restricted-imports -import { click, fillIn, find, triggerEvent } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; -import { t } from 'ember-intl/test-support'; -import { module, test } from 'qunit'; - -import setupIntlRenderingTest from '../../helpers/setup-intl-rendering'; - -module('Integration | Component | form textfield', function (hooks) { - setupIntlRenderingTest(hooks); - - const LABEL = '.form-textfield__label'; - const LABEL_TEXT = 'NOM'; - - const MESSAGE = '.form-textfield__message'; - const MESSAGE_ERROR_STATUS = 'form-textfield__message--error'; - const MESSAGE_SUCCESS_STATUS = 'form-textfield__message--success'; - const MESSAGE_TEXT = 'MESSAGE'; - - const INPUT = '.form-textfield__input'; - const INPUT_DEFAULT_CLASS = 'form-textfield__input--default'; - const INPUT_SUCCESS_CLASS = 'form-textfield__input--success'; - const INPUT_ERROR_CLASS = 'form-textfield__input--error'; - - module('#Component rendering', function (hooks) { - let screen; - hooks.beforeEach(async function () { - this.set('label', 'nom'); - this.set('validationStatus', ''); - this.set('validationMessage', MESSAGE_TEXT); - this.set('textfieldName', 'firstname'); - this.set('value', 'georges'); - // When - screen = await render( - hbs``, - ); - }); - - test('should set initial value', function (assert) { - const input = screen.getByRole('textbox', { name: 'nom' }); - assert.ok(input.value, 'georges'); - }); - - [ - { expectedRendering: 'label', item: LABEL, expectedLength: 1 }, - { expectedRendering: 'div', item: MESSAGE, expectedLength: 1 }, - { expectedRendering: 'input', item: INPUT, expectedLength: 1 }, - ].forEach(function ({ expectedRendering, item, expectedLength }) { - test(`should render a ${expectedRendering}`, function (assert) { - // Then - assert.dom(item).exists({ count: expectedLength }); - assert.strictEqual(find(item).nodeName, expectedRendering.toUpperCase()); - }); - }); - - [ - { item: LABEL, expectedRendering: 'label', expectedText: LABEL_TEXT }, - { item: MESSAGE, expectedRendering: 'div.message', expectedText: MESSAGE_TEXT }, - ].forEach(function ({ item, expectedRendering, expectedText }) { - test(`should render a ${expectedRendering}`, function (assert) { - // Then - assert.ok(find(item).textContent.toUpperCase().includes(expectedText)); - }); - }); - }); - - module('#Component Interactions', function () { - test('should handle action when input lost focus', async function (assert) { - // given - let isActionValidateHandled = false; - let inputValueToValidate; - const expectedInputValue = 'firstname'; - - this.set('validate', function (arg) { - isActionValidateHandled = true; - inputValueToValidate = arg; - }); - - this.set('label', 'nom'); - this.set('validationStatus', ''); - this.set('validationMessage', 'message'); - this.set('textfieldName', 'firstname'); - this.set('onInput', () => {}); - - await render( - hbs``, - ); - - // when - await fillIn(INPUT, 'pix'); - await triggerEvent(INPUT, 'focusout'); - - // then - assert.true(isActionValidateHandled); - assert.deepEqual(inputValueToValidate, expectedInputValue); - }); - - module('#When validationStatus gets "default", Component should ', function (hooks) { - hooks.beforeEach(async function () { - this.set('label', 'nom'); - this.set('validationStatus', 'default'); - this.set('textfieldName', 'firstname'); - this.set('validationMessage', 'message'); - this.set('onInput', () => {}); - // When - await render( - hbs``, - ); - }); - - test("return true if any svg doesn't exist", function (assert) { - // then - assert.dom('img').doesNotExist(); - }); - - test(`contain an input with an additional class ${INPUT_DEFAULT_CLASS}`, function (assert) { - const input = find(INPUT); - // then - assert.ok(input.getAttribute('class').includes(INPUT_DEFAULT_CLASS)); - assert.ok(input.value.includes('')); - }); - }); - - module('#When validationStatus gets "error", Component should ', function (hooks) { - hooks.beforeEach(async function () { - this.set('label', 'nom'); - this.set('validationStatus', 'error'); - this.set('textfieldName', 'firstname'); - this.set('validationMessage', 'message'); - this.set('onInput', () => {}); - - // When - await render( - hbs``, - ); - }); - - test('return true if any img does exist', function (assert) { - // then - assert.dom('img').exists({ count: 1 }); - assert.ok(find('img').getAttribute('class').includes('form-textfield-icon__state--error')); - }); - - [ - { item: 'Input', itemSelector: INPUT, expectedClass: INPUT_ERROR_CLASS }, - { item: 'Div for message validation status', itemSelector: MESSAGE, expectedClass: MESSAGE_ERROR_STATUS }, - ].forEach(({ item, itemSelector, expectedClass }) => { - test(`contain an ${item} with an additional class ${expectedClass}`, function (assert) { - // then - assert.ok(find(itemSelector).getAttribute('class').includes(expectedClass)); - }); - }); - }); - - module('#When validationStatus gets "success", Component should ', function (hooks) { - hooks.beforeEach(async function () { - this.set('label', 'nom'); - this.set('validationStatus', 'success'); - this.set('validationMessage', 'message'); - this.set('textfieldName', 'firstname'); - this.set('onInput', () => {}); - - // When - await render( - hbs``, - ); - }); - - test('return true if any img does exist', function (assert) { - // then - assert.dom('img').exists({ count: 1 }); - assert.ok(find('img').getAttribute('class').includes('form-textfield-icon__state--success')); - }); - - [ - { item: 'Input', itemSelector: INPUT, expectedClass: INPUT_SUCCESS_CLASS }, - { item: 'Div for message validation status', itemSelector: MESSAGE, expectedClass: MESSAGE_SUCCESS_STATUS }, - ].forEach(({ item, itemSelector, expectedClass }) => { - test(`contain an ${item} with an additional class ${expectedClass}`, function (assert) { - // then - assert.ok(find(itemSelector).getAttribute('class').includes(expectedClass)); - }); - }); - }); - - module('#When password is hidden', function () { - test('should change type when user click on eye icon', async function (assert) { - // given - this.set('label', 'Mot de passe'); - this.set('validationStatus', 'default'); - this.set('validationMessage', 'message'); - this.set('textfieldName', 'password'); - this.set('onInput', () => {}); - - // given - const screen = await render( - hbs``, - ); - - // when - await click(screen.getByRole('button', { name: t('common.form.visible-password') })); - - // then - assert.strictEqual(find('input').getAttribute('type'), 'text'); - }); - - test('should change icon when user click on it', async function (assert) { - // given - this.set('label', 'Mot de passe'); - this.set('validationStatus', 'default'); - this.set('validationMessage', 'message'); - this.set('textfieldName', 'password'); - this.set('onInput', () => {}); - - // given - const screen = await render( - hbs``, - ); - - // when - const displayPasswordButton = screen.getByRole('button', { name: t('common.form.visible-password') }); - await click(displayPasswordButton); - - // then - const hidePasswordButton = screen.getByRole('button', { - name: t('common.form.invisible-password'), - }); - assert.dom(hidePasswordButton).exists(); - }); - }); - }); -});