Skip to content

Commit

Permalink
fix(search-input): split input initial value and action up value
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbertrand committed Feb 26, 2024
1 parent 994bf82 commit 953b76c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addon/components/pix-search-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class="pix-search-input__input"
name={{@inputName}}
placeholder={{@placeholder}}
value={{@value}}
value={{this.initialValue}}
oninput={{this.onSearch}}
...attributes
/>
Expand Down
2 changes: 2 additions & 0 deletions addon/components/pix-search-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions tests/integration/components/pix-search-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`<PixSearchInput
@id={{123}}
@label='Champ de recherche de fruits'
@debounceTimeInMs='0'
@triggerFiltering={{this.triggerFiltering}}
@value={{this.dynamicValue}}
/>`);

// 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');
});
});
2 changes: 1 addition & 1 deletion tests/unit/components/pix-search-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 953b76c

Please sign in to comment.