Skip to content

Commit 4f62489

Browse files
committed
fix: Field components, add test for label and hint blocks
- change label and hint block from unknown to [] for TS - added tests for label and hint blocks
1 parent 2d6fc8d commit 4f62489

14 files changed

+127
-14
lines changed

ember-toucan-core/src/components/form/fields/checkbox-group.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export interface ToucanFormCheckboxGroupFieldComponentSignature {
5454
>;
5555
}
5656
];
57-
label: unknown;
58-
hint: unknown;
57+
label: [];
58+
hint: [];
5959
};
6060
}
6161

ember-toucan-core/src/components/form/fields/file-input.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ interface ToucanFormFileInputFieldComponentSignature {
2323
rootTestSelector?: string;
2424
};
2525
Blocks: {
26-
label: unknown;
27-
hint: unknown;
26+
label: [];
27+
hint: [];
2828
};
2929
}
3030

ember-toucan-core/src/components/form/fields/input.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ interface ToucanFormInputFieldComponentSignature {
4343
};
4444
Blocks: {
4545
default: [];
46-
label: unknown;
47-
hint: unknown;
46+
label: [];
47+
hint: [];
4848
};
4949
}
5050

ember-toucan-core/src/components/form/fields/radio-group.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export interface ToucanFormRadioGroupFieldComponentSignature {
6161
>;
6262
}
6363
];
64-
label: unknown;
65-
hint: unknown;
64+
label: [];
65+
hint: [];
6666
};
6767
}
6868

ember-toucan-core/src/components/form/fields/radio.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export interface ToucanFormRadioFieldComponentSignature {
5050
value: ToucanFormRadioControlComponentSignature['Args']['value'];
5151
};
5252
Blocks: {
53-
label: unknown;
54-
hint: unknown;
53+
label: [];
54+
hint: [];
5555
};
5656
}
5757

ember-toucan-core/src/components/form/fields/textarea.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export interface ToucanFormTextareaFieldComponentSignature {
4343
value?: ToucanFormTextareaControlComponentSignature['Args']['value'];
4444
};
4545
Blocks: {
46-
label: unknown;
47-
hint: unknown;
46+
label: [];
47+
hint: [];
4848
};
4949
}
5050

ember-toucan-core/src/components/form/fieldset.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface ToucanFormFieldsetComponentSignature {
2828
};
2929
Blocks: {
3030
default: [];
31-
label: unknown;
32-
hint: unknown;
31+
label: [];
32+
hint: [];
3333
};
3434
}
3535

test-app/tests/integration/components/checkbox-group-field-test.gts

+12
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ module('Integration | Component | Fields | CheckboxGroup', function (hooks) {
113113
assert.dom('[data-error]').hasText('Error text');
114114
});
115115

116+
test('it renders with a hint and label block', async function (assert) {
117+
await render(<template>
118+
<CheckboxGroupField @label="Label" @name="group" @hint="Hint text">
119+
<:label>Extra label content</:label>
120+
<:hint>Extra hint content</:hint>
121+
</CheckboxGroupField>
122+
</template>);
123+
124+
assert.dom('[data-hint]').hasText('Hint text Extra hint content');
125+
assert.dom('[data-label]').hasText('Label Extra label content');
126+
});
127+
116128
test('it default-checks the checkbox with the matching `@value`', async function (assert) {
117129
let selectedOption = ['option-2'];
118130

test-app/tests/integration/components/fieldset-test.gts

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ module('Integration | Component | Fieldset', function (hooks) {
4242
assert.dom('[data-fieldset]').hasAttribute('aria-describedby');
4343
});
4444

45+
test('it renders with hint and label blocks', async function (assert) {
46+
await render(<template>
47+
<Fieldset @label="Label" @hint="Hint text" data-fieldset>
48+
<:label>Extra label content</:label>
49+
<:hint>Extra hint content</:hint>
50+
</Fieldset>
51+
</template>);
52+
53+
assert.dom('[data-hint]').hasText('Hint text Extra hint content');
54+
assert.dom('[data-label]').hasText('Label Extra label content');
55+
});
56+
4557
test('it renders with an error', async function (assert) {
4658
await render(<template>
4759
<Fieldset @label="Label" @error="Error text" data-fieldset />

test-app/tests/integration/components/file-input-field-test.gts

+25
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,31 @@ module('Integration | Component | Fields | FileInput', function (hooks) {
100100
assert.dom(hint).hasText('Hint text');
101101
});
102102

103+
test('it renders with a hint and label block', async function (assert) {
104+
await render(<template>
105+
<FileInputField
106+
@deleteLabel="Delete File"
107+
@label="Label"
108+
@trigger="Select Files"
109+
@hint="Hint text"
110+
@onChange={{onChange}}
111+
data-file-input-field
112+
>
113+
<:label>Extra label content</:label>
114+
<:hint>Extra hint content</:hint>
115+
</FileInputField>
116+
</template>);
117+
118+
// For the file input field component, the only aria-describedby
119+
// value should be the errorId. This is due to the way the component
120+
// is structured, where the label+hint are rendered inside of the
121+
// wrapping <label> element
122+
const hint = find('[data-hint]');
123+
const label = find('[data-label]');
124+
125+
assert.dom(hint).hasText('Hint text Extra hint content');
126+
assert.dom(label).hasText('Label Extra label content');
127+
});
103128
test('it renders with an error', async function (assert) {
104129
await render(<template>
105130
<FileInputField

test-app/tests/integration/components/input-field-test.gts

+20
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ module('Integration | Component | Fields | Input', function (hooks) {
110110
);
111111
});
112112

113+
test('it renders a hint and label block', async function (assert) {
114+
await render(<template>
115+
<InputField
116+
@label="Label"
117+
type="text"
118+
@hint="Hint text visible here"
119+
data-input
120+
>
121+
<:label>Extra label content</:label>
122+
<:hint>Extra hint content</:hint>
123+
</InputField>
124+
</template>);
125+
126+
const label = '[data-label]';
127+
const hint = '[data-hint]';
128+
129+
assert.dom(label).hasText('Label Extra label content');
130+
assert.dom(hint).hasText('Hint text visible here Extra hint content');
131+
132+
});
113133
test('it sets aria-describedby when both a hint and error are provided using the hint and error ids', async function (assert) {
114134
await render(<template>
115135
<InputField

test-app/tests/integration/components/radio-field-test.gts

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ module('Integration | Component | Fields | Radio', function (hooks) {
4848
assert.dom('[data-hint]').hasText('Hint text');
4949
});
5050

51+
test('it renders with a hint and label block', async function (assert) {
52+
await render(<template>
53+
<RadioField
54+
@value="option"
55+
@label="Label"
56+
@hint="Hint text"
57+
@name="name"
58+
data-radio
59+
>
60+
<:label>Extra label content</:label>
61+
<:hint>Extra hint content</:hint>
62+
</RadioField>
63+
</template>);
64+
65+
assert.dom('[data-hint]').hasText('Hint text Extra hint content');
66+
assert.dom('[data-label]').hasText('Label Extra label content');
67+
});
5168
test('it sets the "for" attribute on the label to the "id" attribute of the radio', async function (assert) {
5269
await render(<template>
5370
<RadioField @value="option" @label="Label" @name="name" data-radio />

test-app/tests/integration/components/radio-group-field-test.gts

+12
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ module('Integration | Component | Fields | RadioGroup', function (hooks) {
6363
assert.dom('[data-hint]').hasText('Hint text');
6464
});
6565

66+
test('it renders with a hint and label block', async function (assert) {
67+
await render(<template>
68+
<RadioGroupField @label="Label" @name="group" @hint="Hint text">
69+
<:label>Extra label content</:label>
70+
<:hint>Extra hint content</:hint>
71+
</RadioGroupField>
72+
</template>);
73+
74+
assert.dom('[data-hint]').hasText('Hint text Extra hint content');
75+
assert.dom('[data-label]').hasText('Label Extra label content');
76+
});
77+
6678
test('it renders with an error', async function (assert) {
6779
await render(<template>
6880
<RadioGroupField @label="Label" @name="group" @error="Error text" />

test-app/tests/integration/components/textarea-field-test.gts

+15
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ module('Integration | Component | Fields | Textarea', function (hooks) {
5555
);
5656
});
5757

58+
test('it renders with a hint and label block', async function (assert) {
59+
await render(<template>
60+
<TextareaField @label="Label" @hint="Hint text" data-textarea>
61+
<:label>Extra label content</:label>
62+
<:hint>Extra hint content</:hint>
63+
</TextareaField>
64+
</template>);
65+
66+
let hint = find('[data-hint]');
67+
let label = find('[data-label]');
68+
69+
assert.dom(hint).hasText('Hint text Extra hint content');
70+
assert.dom(label).hasText('Label Extra label content');
71+
});
72+
5873
test('it renders with an error', async function (assert) {
5974
await render(<template>
6075
<TextareaField @label="Label" @error="Error text" data-textarea />

0 commit comments

Comments
 (0)