|
1 | 1 | import { module, test } from 'qunit'; |
2 | 2 | import { setupRenderingTest } from 'dummy/tests/helpers'; |
3 | | -import { fillIn, render, settled } from '@ember/test-helpers'; |
| 3 | +import { fillIn, render } from '@ember/test-helpers'; |
4 | 4 | import { hbs } from 'ember-cli-htmlbars'; |
5 | 5 |
|
6 | 6 | module('Integration | Component | date-time-input', function (hooks) { |
@@ -108,15 +108,38 @@ module('Integration | Component | date-time-input', function (hooks) { |
108 | 108 | await fillIn('[aria-label="Time Input"]', '19:12'); |
109 | 109 | }); |
110 | 110 |
|
111 | | - test('it syncs when the external value changes', async function (assert) { |
| 111 | + test('it does not reset while controlled by a parent value', async function (assert) { |
| 112 | + assert.expect(4); |
| 113 | + |
112 | 114 | this.set('value', '2026-06-18 18:47'); |
| 115 | + this.set('onUpdate', (dateTimeInstance) => { |
| 116 | + this.set('value', dateTimeInstance); |
| 117 | + }); |
113 | 118 |
|
114 | | - await render(hbs`<DateTimeInput @value={{this.value}} />`); |
| 119 | + await render(hbs`<DateTimeInput @value={{this.value}} @onUpdate={{this.onUpdate}} />`); |
115 | 120 |
|
116 | | - this.set('value', '2026-07-03T15:00:00+08:00'); |
117 | | - await settled(); |
| 121 | + await fillIn('[aria-label="Date Input"]', '2026-06-19'); |
118 | 122 |
|
119 | | - assert.dom('[aria-label="Date Input"]').hasValue('2026-07-03'); |
120 | | - assert.dom('[aria-label="Time Input"]').hasValue('15:00'); |
| 123 | + assert.dom('[aria-label="Date Input"]').hasValue('2026-06-19'); |
| 124 | + assert.dom('[aria-label="Time Input"]').hasValue('18:47'); |
| 125 | + |
| 126 | + await fillIn('[aria-label="Time Input"]', '19:12'); |
| 127 | + |
| 128 | + assert.dom('[aria-label="Date Input"]').hasValue('2026-06-19'); |
| 129 | + assert.dom('[aria-label="Time Input"]').hasValue('19:12'); |
| 130 | + }); |
| 131 | + |
| 132 | + test('it does not emit null while native inputs are incomplete', async function (assert) { |
| 133 | + assert.expect(1); |
| 134 | + |
| 135 | + this.set('value', '2026-06-18 18:47'); |
| 136 | + this.set('onUpdate', () => { |
| 137 | + assert.ok(false, 'onUpdate should not be called for incomplete input'); |
| 138 | + }); |
| 139 | + |
| 140 | + await render(hbs`<DateTimeInput @value={{this.value}} @onUpdate={{this.onUpdate}} />`); |
| 141 | + await fillIn('[aria-label="Date Input"]', ''); |
| 142 | + |
| 143 | + assert.dom('[aria-label="Date Input"]').hasValue(''); |
121 | 144 | }); |
122 | 145 | }); |
0 commit comments