From 953b76c58cbee46f87cd8d24c28ae73810570092 Mon Sep 17 00:00:00 2001 From: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:19:57 +0100 Subject: [PATCH] fix(search-input): split input initial value and action up value --- addon/components/pix-search-input.hbs | 2 +- addon/components/pix-search-input.js | 2 ++ .../components/pix-search-input-test.js | 22 +++++++++++++++++++ .../unit/components/pix-search-input-test.js | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/addon/components/pix-search-input.hbs b/addon/components/pix-search-input.hbs index 79459fcf5..9010585e3 100644 --- a/addon/components/pix-search-input.hbs +++ b/addon/components/pix-search-input.hbs @@ -16,7 +16,7 @@ class="pix-search-input__input" name={{@inputName}} placeholder={{@placeholder}} - value={{@value}} + value={{this.initialValue}} oninput={{this.onSearch}} ...attributes /> diff --git a/addon/components/pix-search-input.js b/addon/components/pix-search-input.js index d1bbc269b..4e63bc191 100644 --- a/addon/components/pix-search-input.js +++ b/addon/components/pix-search-input.js @@ -4,6 +4,8 @@ import { guidFor } from '@ember/object/internals'; import { debounceTask } from 'ember-lifeline'; export default class PixSearchInput extends Component { + initialValue = this.args.value; + constructor() { super(...arguments); diff --git a/tests/integration/components/pix-search-input-test.js b/tests/integration/components/pix-search-input-test.js index 3f3a67238..8fdb29aa7 100644 --- a/tests/integration/components/pix-search-input-test.js +++ b/tests/integration/components/pix-search-input-test.js @@ -42,4 +42,26 @@ module('Integration | Component | search-input', function (hooks) { // then assert.ok(triggerFiltering.calledWith(123, 'Mangue')); }); + + test("doesn't update value when input value is udpated", async function (assert) { + // given + this.set('triggerFiltering', sinon.stub()); + this.set('dynamicValue', 'init'); + const screen = await render(hbs``); + + // when + await fillByLabel('Champ de recherche de fruits', 'Mangue'); + this.set('dynamicValue', 'dynamicValue'); + + // then + const inputFound = screen.getByLabelText('Champ de recherche de fruits'); + assert.dom(inputFound).exists(); + assert.strictEqual(inputFound.value, 'Mangue'); + }); }); diff --git a/tests/unit/components/pix-search-input-test.js b/tests/unit/components/pix-search-input-test.js index f3155bd1f..609a3c462 100644 --- a/tests/unit/components/pix-search-input-test.js +++ b/tests/unit/components/pix-search-input-test.js @@ -3,7 +3,7 @@ import { setupTest } from 'ember-qunit'; import createGlimmerComponent from '../../helpers/create-glimmer-component'; import sinon from 'sinon'; -module('Unit | Component | pix-search-select', function (hooks) { +module('Unit | Component | pix-search-input', function (hooks) { setupTest(hooks); module('when there are errors in params', function () {