Skip to content

Commit

Permalink
fix(combo): default value with delayed data (#1555)
Browse files Browse the repository at this point in the history
* Added form integration tests with delayed data
* Preserve pristine state on data set
* Avoid triggering pipeline for state updates setting same data
  • Loading branch information
damyanpetev authored Jan 24, 2025
1 parent e7224ee commit ea4e682
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/components/combo/combo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,45 @@ describe('Combo', () => {
});
});

describe('Form integration with delayed data', () => {
const spec = createFormAssociatedTestBed<IgcComboComponent<City>>(html`
<igc-combo name="combo" value-key="id" display-key="name"></igc-combo>
`);

function initDataDefaultValue(single = false) {
spec.element.singleSelect = single;
// assign data after init to simulate async data
spec.element.data = cities;
spec.element.defaultValue = value;
}

beforeEach(async () => {
await spec.setup(IgcComboComponent.tagName);
});

it('correct initial state (single)', () => {
initDataDefaultValue(true);
spec.assertIsPristine();
expect(spec.element.value).to.eql([first(value)]);
});

it('correct initial state (multiple)', () => {
initDataDefaultValue();
spec.assertIsPristine();
expect(spec.element.value).to.eql(value);
});

it('is correctly submitted (single)', () => {
initDataDefaultValue(true);
spec.assertSubmitHasValue(first(value));
});

it('is correctly submitted (multiple)', () => {
initDataDefaultValue();
spec.assertSubmitHasValues(value);
});
});

describe('Validation', () => {
const spec = createFormAssociatedTestBed<IgcComboComponent<City>>(html`
<igc-combo
Expand Down
5 changes: 5 additions & 0 deletions src/components/combo/combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ export default class IgcComboComponent<
/* treatAsRef */
@property({ attribute: false })
public set data(value: T[]) {
if (this._data === value) {
return;
}
this._data = asArray(value);
const pristine = this._pristine;
this.value = asArray(this.value);
this._pristine = pristine;
this._state.runPipeline();
}

Expand Down

0 comments on commit ea4e682

Please sign in to comment.