Skip to content

Commit 8f55053

Browse files
committed
added missing test for the radio field group
1 parent b61a9da commit 8f55053

File tree

1 file changed

+25
-0
lines changed
  • showcase/tests/integration/components/hds/form/radio

1 file changed

+25
-0
lines changed

showcase/tests/integration/components/hds/form/radio/group-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@ module('Integration | Component | hds/form/radio/group', function (hooks) {
141141
);
142142
});
143143

144+
test('it automatically provides all the ID relations between the elements when dynamically rendered using boolean values', async function (assert) {
145+
await render(
146+
hbs`<Hds::Form::Radio::Group as |G|>
147+
<G.RadioField @value={{true}} @id={{true}} as |F|>
148+
<F.Label>This is the label for the 'true' value</F.Label>
149+
</G.RadioField>
150+
<G.RadioField @value={{false}} @id={{false}} as |F|>
151+
<F.Label>This is the label for the 'false' value</F.Label>
152+
</G.RadioField>
153+
</Hds::Form::Radio::Group>`
154+
);
155+
156+
const inputs = this.element.querySelectorAll('input[type="radio"]');
157+
const labels = this.element.querySelectorAll('label');
158+
159+
// the `true` value should be used for the `id` (input) and `for` (label) attributes
160+
assert.dom(inputs[0]).hasAttribute('id', 'true');
161+
assert.dom(labels[0]).hasAttribute('for', 'true');
162+
163+
// the `false` value should not be used, but the `id` (input) attribute should be generated and the `for` (label) attribute should match it
164+
const generatedId = inputs[1].id;
165+
assert.true(generatedId.startsWith('ember'));
166+
assert.dom(labels[1]).hasAttribute('for', generatedId);
167+
});
168+
144169
// NAME
145170

146171
test('it renders the defined name on all controls within a group', async function (assert) {

0 commit comments

Comments
 (0)