Skip to content

Commit 1877626

Browse files
committed
Add Glint support to the AuRadioGroup component
1 parent 27bc01b commit 1877626

File tree

5 files changed

+145
-89
lines changed

5 files changed

+145
-89
lines changed

addon/components/au-radio-group.gjs addon/components/au-radio-group.gts

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
import { AuRadio } from '@appuniversum/ember-appuniversum';
21
import { hash } from '@ember/helper';
32
import { guidFor } from '@ember/object/internals';
43
import Component from '@glimmer/component';
4+
import type { WithBoundArgs } from '@glint/template';
5+
import AuRadio, { type AuRadioSignature } from './au-radio';
56

67
// TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version
78
import or from 'ember-truth-helpers/helpers/or';
89

9-
export default class AuRadioGroup extends Component {
10+
export interface AuRadioGroupSignature {
11+
Args: {
12+
alignment?: 'inline';
13+
disabled?: AuRadioSignature['Args']['disabled'];
14+
name?: AuRadioSignature['Args']['name'];
15+
onChange?: AuRadioSignature['Args']['onChangeGroup'];
16+
selected?: AuRadioSignature['Args']['groupValue'];
17+
};
18+
Blocks: {
19+
default: [
20+
{
21+
Radio: WithBoundArgs<
22+
typeof AuRadio,
23+
'name' | 'inGroup' | 'groupValue' | 'disabled' | 'onChangeGroup'
24+
>;
25+
},
26+
];
27+
};
28+
Element: HTMLDivElement;
29+
}
30+
31+
export default class AuRadioGroup extends Component<AuRadioGroupSignature> {
1032
uniqueName = guidFor(this);
1133

1234
get alignmentClass() {

addon/template-registry.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import type AuModal from '@appuniversum/ember-appuniversum/components/au-modal';
3535
import type AuNavigationLink from '@appuniversum/ember-appuniversum/components/au-navigation-link';
3636
import type AuPanel from '@appuniversum/ember-appuniversum/components/au-panel';
3737
import type AuPill from '@appuniversum/ember-appuniversum/components/au-pill';
38+
import type AuRadioGroup from '@appuniversum/ember-appuniversum/components/au-radio-group';
3839
import type AuRadio from '@appuniversum/ember-appuniversum/components/au-radio';
3940
import type AuToolbar from '@appuniversum/ember-appuniversum/components/au-toolbar';
4041

@@ -79,6 +80,7 @@ export default interface AppuniversumRegistry {
7980
AuNavigationLink: typeof AuNavigationLink;
8081
AuPanel: typeof AuPanel;
8182
AuPill: typeof AuPill;
83+
AuRadioGroup: typeof AuRadioGroup;
8284
AuRadio: typeof AuRadio;
8385
AuToolbar: typeof AuToolbar;
8486

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import AuRadioGroup from '@appuniversum/ember-appuniversum/components/au-radio-group';
2+
import { settled } from '@ember/test-helpers';
3+
import { click, render } from '@ember/test-helpers';
4+
import { tracked } from '@glimmer/tracking';
5+
import { setupRenderingTest } from 'dummy/tests/helpers';
6+
import { module, test } from 'qunit';
7+
8+
module('Integration | Component | au-radio-group', function (hooks) {
9+
setupRenderingTest(hooks);
10+
11+
test('it can be given a name', async function (assert) {
12+
await render(
13+
<template>
14+
<AuRadioGroup @name="foo" as |Group|>
15+
<Group.Radio data-test-foo>Foo</Group.Radio>
16+
</AuRadioGroup>
17+
</template>,
18+
);
19+
assert.dom('[data-test-foo]').hasAttribute('name', 'foo');
20+
});
21+
22+
test('if it is given no name, it will automatically generate a unique name', async function (assert) {
23+
await render(
24+
<template>
25+
<AuRadioGroup as |Group|>
26+
<Group.Radio data-test-foo>Foo</Group.Radio>
27+
</AuRadioGroup>
28+
</template>,
29+
);
30+
assert.dom('[data-test-foo]').hasAttribute('name');
31+
});
32+
33+
test('it can be given a value', async function (assert) {
34+
const state = new TestState();
35+
state.value = 'bar';
36+
37+
await render(
38+
<template>
39+
<AuRadioGroup @selected={{state.value}} as |Group|>
40+
<Group.Radio @value="foo" data-test-foo>Foo</Group.Radio>
41+
<Group.Radio @value="bar" data-test-bar>Bar</Group.Radio>
42+
</AuRadioGroup>
43+
</template>,
44+
);
45+
46+
assert.dom('[data-test-bar]').isChecked();
47+
assert.dom('[data-test-foo]').isNotChecked();
48+
49+
state.value = 'foo';
50+
await settled();
51+
assert.dom('[data-test-bar]').isNotChecked();
52+
assert.dom('[data-test-foo]').isChecked();
53+
});
54+
55+
test('it can be disabled', async function (assert) {
56+
const state = new TestState();
57+
state.disabled = true;
58+
await render(
59+
<template>
60+
<AuRadioGroup @disabled={{state.disabled}} as |Group|>
61+
<Group.Radio data-test-foo>Foo</Group.Radio>
62+
</AuRadioGroup>
63+
</template>,
64+
);
65+
66+
assert.dom('[data-test-foo]').isDisabled();
67+
68+
state.disabled = false;
69+
await settled();
70+
assert.dom('[data-test-foo]').isNotDisabled();
71+
});
72+
73+
test('it calls the provided @onChange action when its state changes by user input', async function (assert) {
74+
let currentValue: string | undefined;
75+
76+
const handleChange = (value: string | undefined, event: Event) => {
77+
currentValue = value;
78+
assert.true(event instanceof Event);
79+
};
80+
81+
await render(
82+
<template>
83+
<AuRadioGroup @onChange={{handleChange}} as |Group|>
84+
<Group.Radio @value="foo" data-test-foo>Foo</Group.Radio>
85+
<Group.Radio @value="bar" data-test-bar>Bar</Group.Radio>
86+
</AuRadioGroup>
87+
</template>,
88+
);
89+
90+
await click('[data-test-bar]');
91+
assert.strictEqual(currentValue, 'bar');
92+
93+
await click('[data-test-foo]');
94+
assert.strictEqual(currentValue, 'foo');
95+
});
96+
97+
test('it adds any extra attributes to the group element', async function (assert) {
98+
await render(
99+
<template>
100+
<AuRadioGroup foo="bar" data-test-radio-group as |Group|>
101+
<Group.Radio>Foo</Group.Radio>
102+
</AuRadioGroup>
103+
</template>,
104+
);
105+
assert.dom('[data-test-radio-group]').hasAttribute('foo', 'bar');
106+
});
107+
});
108+
109+
class TestState {
110+
@tracked disabled?: boolean;
111+
@tracked value?: string;
112+
}

tests/integration/components/au-radio-group-test.js

-87
This file was deleted.

tests/integration/components/loose-mode-test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ module('Integration | Component | Loose mode', function (hooks) {
255255
assert.dom('[data-test-pill]').exists();
256256
});
257257

258+
test('`<AuRadioGroup>` resolves in loose mode', async function (assert) {
259+
await render(hbs`
260+
<AuRadioGroup data-test-radio-group />
261+
`);
262+
assert.dom('[data-test-radio-group]').exists();
263+
});
264+
258265
test('`<AuRadio>` resolves in loose mode', async function (assert) {
259266
await render(hbs`
260267
<AuRadio data-test-radio />

0 commit comments

Comments
 (0)