chore: 🤖 Add ember-radio-button as radiofield
Use ember-radio-button to wrap a radiofield. Introduce radiofield group
This commit is contained in:
15 files changed
+260
-192
No files matched your search
@@ -1,20 +0,0 @@
|
||||
import Component from '@ember/component';
|
||||
import layout from '../../../templates/components/rose/form/radio';
|
||||
|
||||
/**
|
||||
* A HTML `<input type="radio">` element.
|
||||
*
|
||||
* @example
|
||||
* <Rose::Form::Radio
|
||||
* @id="fieldId"
|
||||
* @label="label"
|
||||
* name="fieldName"
|
||||
* disabled={{true}}
|
||||
* @checked={{true}}
|
||||
* @error={{true}}
|
||||
* />
|
||||
*/
|
||||
export default Component.extend({
|
||||
layout,
|
||||
tagName: '',
|
||||
});
|
||||
@@ -1,8 +1,31 @@
|
||||
import Component from '@ember/component';
|
||||
import layout from '../../../../templates/components/rose/form/radio/group';
|
||||
|
||||
/**
|
||||
* A `<input type="radio" name="radio-group">` element.
|
||||
*
|
||||
* @example
|
||||
* <Rose::Form::Radio::Group @name="color" @variable="green" as |radioGroup|>
|
||||
* <radioGroup.radio
|
||||
* @id="red-radio"
|
||||
* @label="Red"
|
||||
* @value="red"
|
||||
* />
|
||||
* <radioGroup.radio
|
||||
* @id="green-radio"
|
||||
* @label="Green"
|
||||
* @value="green"
|
||||
* />
|
||||
* <radioGroup.radio
|
||||
* @id="blue-radio"
|
||||
* @label="Blue"
|
||||
* @value="blue"
|
||||
* />
|
||||
* </Rose::Form::Radio::Group>
|
||||
*/
|
||||
|
||||
export default Component.extend({
|
||||
layout,
|
||||
|
||||
tagName: ''
|
||||
tagName: '',
|
||||
});
|
||||
@@ -2,18 +2,20 @@ import Component from '@ember/component';
|
||||
import layout from '../../../../templates/components/rose/form/radio/radio';
|
||||
|
||||
/**
|
||||
* A HTML `<input type="radio">` element.
|
||||
*
|
||||
* @example
|
||||
* <Rose::Form::Radio
|
||||
* @id="fieldId"
|
||||
* @label="label"
|
||||
* name="fieldName"
|
||||
* disabled={{true}}
|
||||
* @checked={{true}}
|
||||
* @error={{true}}
|
||||
* />
|
||||
*/
|
||||
* A `<input type="radio">` element.
|
||||
* `value` and `variable` must be equal to select
|
||||
* radiofield.
|
||||
*
|
||||
* @example
|
||||
* <Rose::Form::Radio::Radio
|
||||
* @id="fieldId"
|
||||
* @label="label"
|
||||
* @error={{true}}
|
||||
* @value="fieldValue"
|
||||
* @variable="fieldValue"
|
||||
* @disabled={{true}}
|
||||
* />
|
||||
*/
|
||||
export default Component.extend({
|
||||
layout,
|
||||
tagName: '',
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
@use '../../utilities/type';
|
||||
|
||||
$radio-svg: (
|
||||
'default': "<svg viewBox='0 0 24 24' fill='%23aaaaaa' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
|
||||
'hover': "<svg viewBox='0 0 24 24' fill='%236f7682' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
|
||||
'focus': "<svg viewBox='0 0 24 24' fill='%231563ff' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
|
||||
'checked': "<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' fill='%231563ff'/></svg>",
|
||||
|
||||
'disabled': "<svg viewBox='0 0 24 24' fill='%23bac1cc' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
|
||||
'disabled-checked': "<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' fill='%23bac1cc'/></svg>",
|
||||
|
||||
'error': "<svg viewBox='0 0 24 24' fill='%23c73445' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
|
||||
'error-checked': "<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' fill='%23c73445'/></svg>",
|
||||
'default':
|
||||
"<svg viewBox='0 0 24 24' fill='%23aaaaaa' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
'hover':
|
||||
"<svg viewBox='0 0 24 24' fill='%236f7682' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
'focus':
|
||||
"<svg viewBox='0 0 24 24' fill='%231563ff' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
'checked':
|
||||
"<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' fill='%231563ff'/></svg>",
|
||||
'disabled':
|
||||
"<svg viewBox='0 0 24 24' fill='%23bac1cc' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
'disabled-checked':
|
||||
"<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' fill='%23bac1cc'/></svg>",
|
||||
'error':
|
||||
"<svg viewBox='0 0 24 24' fill='%23c73445' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' /></svg>",
|
||||
'error-checked':
|
||||
"<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z' fill='%23c73445'/></svg>",
|
||||
);
|
||||
|
||||
$data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
@@ -33,6 +34,7 @@ $data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
|
||||
&::before {
|
||||
position: absolute;
|
||||
top: sizing.rems(xs);
|
||||
left: 0;
|
||||
display: block;
|
||||
width: sizing.rems(m);
|
||||
@@ -68,7 +70,10 @@ $data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
&:hover {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'hover'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'hover'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +81,10 @@ $data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
&:focus {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'focus'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'focus'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +92,10 @@ $data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
&:checked {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'checked'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'checked'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,14 +104,20 @@ $data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
&:disabled {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'disabled'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'disabled'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
&:checked {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'disabled-checked'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'disabled-checked'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,14 +131,20 @@ $data-svg-prefix: 'data:image/svg+xml;utf-8,';
|
||||
&:not(:disabled):not(:focus) {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'error'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'error'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
&:checked {
|
||||
~ .rose-form-radio-label {
|
||||
&::after {
|
||||
background-image: url($data-svg-prefix + map-get($radio-svg, 'error-checked'));
|
||||
background-image: url($data-svg-prefix + map-get(
|
||||
$radio-svg,
|
||||
'error-checked'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<div class="rose-form-radio{{if @error " error"}}">
|
||||
|
||||
<input
|
||||
...attributes
|
||||
class="rose-form-radio-field"
|
||||
id={{@id}}
|
||||
type="radio"
|
||||
checked={{@checked}} />
|
||||
|
||||
<label class="rose-form-radio-label" for={{@id}}>
|
||||
{{@label}}
|
||||
</label>
|
||||
|
||||
{{yield}}
|
||||
|
||||
</div>
|
||||
@@ -7,7 +7,8 @@
|
||||
type="radio"
|
||||
@name={{@name}}
|
||||
@value={{@value}}
|
||||
@groupValue={{@variable}} />
|
||||
@groupValue={{@variable}}
|
||||
@disabled={{@disabled}}/>
|
||||
|
||||
<label class="rose-form-radio-label" for={{@id}}>
|
||||
{{@label}}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from 'rose/components/rose/form/radio';
|
||||
@@ -1 +1 @@
|
||||
export { default } from 'rose/components/rose/form/radio/group';
|
||||
export { default } from 'rose/components/rose/form/radio/group';
|
||||
@@ -1 +1 @@
|
||||
export { default } from 'rose/components/rose/form/radio/radio';
|
||||
export { default } from 'rose/components/rose/form/radio/radio';
|
||||
@@ -119,8 +119,38 @@ Dummy app index template
|
||||
disabled={{true}}
|
||||
/>
|
||||
|
||||
<h2>Radio</h2>
|
||||
<h2>Radio field</h2>
|
||||
<Rose::Form::Radio::Radio
|
||||
@id="radio-1"
|
||||
@label="Label"
|
||||
@value="radio-1"
|
||||
/>
|
||||
<Rose::Form::Radio::Radio
|
||||
@id="radio-2"
|
||||
@error={{true}}
|
||||
@label="Error"
|
||||
@value="radio-2"
|
||||
/>
|
||||
<Rose::Form::Radio::Radio
|
||||
@id="radio-3"
|
||||
@label="Checked"
|
||||
/>
|
||||
|
||||
<Rose::Form::Radio::Radio
|
||||
@id="radio-4"
|
||||
@label="Disabled"
|
||||
@disabled={{true}}
|
||||
@value="radio-4"
|
||||
/>
|
||||
<Rose::Form::Radio::Radio
|
||||
@id="radio-5"
|
||||
@label="Disabled + Checked"
|
||||
@value="radio-5"
|
||||
@variable="radio-5"
|
||||
@disabled={{true}}
|
||||
/>
|
||||
|
||||
<h2>Radio field group</h2>
|
||||
<Rose::Form::Radio::Group @name="color" @variable="green" as |radioGroup|>
|
||||
<radioGroup.radio
|
||||
@id="red-radio"
|
||||
@@ -138,33 +168,3 @@ Dummy app index template
|
||||
@value="blue"
|
||||
/>
|
||||
</Rose::Form::Radio::Group>
|
||||
|
||||
<Rose::Form::Radio
|
||||
@id="radio-1"
|
||||
@label="Label"
|
||||
name="radio-group"
|
||||
/>
|
||||
<Rose::Form::Radio
|
||||
@id="radio-2"
|
||||
@error={{true}}
|
||||
@label="Error"
|
||||
name="radio-group"
|
||||
/>
|
||||
<Rose::Form::Radio
|
||||
@id="radio-3"
|
||||
@checked={{true}}
|
||||
@label="Checked"
|
||||
name="radio-group"
|
||||
/>
|
||||
|
||||
<Rose::Form::Radio
|
||||
@id="radio-4"
|
||||
@label="Disabled"
|
||||
disabled={{true}}
|
||||
/>
|
||||
<Rose::Form::Radio
|
||||
@id="radio-5"
|
||||
@checked={{true}}
|
||||
@label="Disabled + Checked"
|
||||
disabled={{true}}
|
||||
/>
|
||||
@@ -0,0 +1,41 @@
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
import { text } from '@storybook/addon-knobs';
|
||||
|
||||
export default {
|
||||
title: 'Rose::Form::Radio::Group',
|
||||
};
|
||||
|
||||
export const Normal = () => ({
|
||||
template: hbs`
|
||||
<Rose::Form::Radio::Group @name={{name}} @variable={{variable}} as |radioGroup|>
|
||||
<radioGroup.radio
|
||||
@id="firstField"
|
||||
@label={{firstFieldLabel}}
|
||||
@value={{firstFieldValue}}
|
||||
/>
|
||||
<radioGroup.radio
|
||||
@id="secondField"
|
||||
@label={{secondFieldLabel}}
|
||||
@value={{secondFieldValue}}
|
||||
/>
|
||||
<radioGroup.radio
|
||||
@id="thirdField"
|
||||
@label={{thirdFieldLabel}}
|
||||
@value={{thirdFieldValue}}
|
||||
/>
|
||||
</Rose::Form::Radio::Group>
|
||||
`,
|
||||
context: {
|
||||
name: text('name', 'Groupname'),
|
||||
variable: text('variable', 'disagree'),
|
||||
|
||||
firstFieldLabel: text('first radiofield label', 'Agree'),
|
||||
firstFieldValue: text('first radiofield value', 'agree'),
|
||||
|
||||
secondFieldLabel: text('second radiofield label', 'Maybe'),
|
||||
secondFieldValue: text('second radiofield value', 'maybe'),
|
||||
|
||||
thirdFieldLabel: text('third radiofield label', 'Disagree'),
|
||||
thirdFieldValue: text('third radiofield value', 'disagree'),
|
||||
},
|
||||
});
|
||||
+11
-8
@@ -2,26 +2,29 @@ import { hbs } from 'ember-cli-htmlbars';
|
||||
import { text, boolean } from '@storybook/addon-knobs';
|
||||
|
||||
export default {
|
||||
title: 'Rose::Form::Radio',
|
||||
title: 'Rose::Form::Radio::Radio',
|
||||
};
|
||||
|
||||
export const Normal = () => ({
|
||||
template: hbs`
|
||||
<Rose::Form::Radio
|
||||
<Rose::Form::Radio::Radio
|
||||
@id={{id}}
|
||||
name={{name}}
|
||||
@label={{label}}
|
||||
@checked={{checked}}
|
||||
@error={{error}}
|
||||
disabled={{disabled}}
|
||||
@value={{value}}
|
||||
@variable={{variable}}
|
||||
@disabled={{disabled}}
|
||||
/>
|
||||
`,
|
||||
context: {
|
||||
label: text('text', 'Radiofield'),
|
||||
id: text('id', 'radio-1'),
|
||||
name: text('name', 'radio-1'),
|
||||
checked: boolean('checked', false),
|
||||
label: text('text', 'Radiofield'),
|
||||
error: boolean('error', false),
|
||||
value: text('value', 'value and variable must match to select radiofield'),
|
||||
variable: text(
|
||||
'variable',
|
||||
'value and variable must match to select radiofield'
|
||||
),
|
||||
disabled: boolean('disabled', false),
|
||||
},
|
||||
});
|
||||
@@ -1,49 +0,0 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render, find } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
module('Integration | Component | rose/form/radio', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio />`);
|
||||
assert.ok(await find('input'));
|
||||
assert.equal(await find('input').type, 'radio');
|
||||
});
|
||||
|
||||
test('it renders with label', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio @label="Label"/>`);
|
||||
assert.equal(await find('label').textContent.trim(), 'Label');
|
||||
});
|
||||
|
||||
test('it is not checked by default', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio />`);
|
||||
assert.equal(await find('input').checked, false);
|
||||
});
|
||||
|
||||
test('it is not disabled by default', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio />`);
|
||||
assert.equal(await find('input').disabled, false);
|
||||
});
|
||||
|
||||
test('it is not in error state by default', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio />`);
|
||||
assert.notOk(await find('.error'));
|
||||
});
|
||||
|
||||
test('it is checked when @checked={{true}}', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio @checked={{true}}/>`);
|
||||
assert.equal(await find('input').checked, true);
|
||||
});
|
||||
|
||||
test('it is disabled when disabled={{true}}', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio disabled={{true}}/>`);
|
||||
assert.equal(await find('input').disabled, true);
|
||||
});
|
||||
|
||||
test('it is in error state when @error={{true}}', async function(assert) {
|
||||
await render(hbs`<Rose::Form::Radio @error={{true}} />`);
|
||||
assert.ok(await find('.error'));
|
||||
});
|
||||
});
|
||||
@@ -1,26 +1,54 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { render, click, findAll } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
module('Integration | Component | rose/form/radio/group', function(hooks) {
|
||||
module('Integration | Component | rose/form/radio/group', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
// Set any properties with this.set('myProperty', 'value');
|
||||
// Handle any actions with this.set('myAction', function(val) { ... });
|
||||
|
||||
await render(hbs`{{rose/form/radio/group}}`);
|
||||
|
||||
assert.equal(this.element.textContent.trim(), '');
|
||||
|
||||
// Template block usage:
|
||||
test('it renders', async function (assert) {
|
||||
await render(hbs`
|
||||
{{#rose/form/radio/group}}
|
||||
template block text
|
||||
{{/rose/form/radio/group}}
|
||||
<Rose::Form::Radio::Group @name="bird" as |radioGroup|>
|
||||
<radioGroup.radio
|
||||
@id="bird-1"
|
||||
@label="Pegion"
|
||||
@value="pegion"
|
||||
/>
|
||||
<radioGroup.radio
|
||||
@id="bird-2"
|
||||
@label="flamingo"
|
||||
@value="flamingo"
|
||||
/>
|
||||
</Rose::Form::Radio::Group>
|
||||
`);
|
||||
|
||||
assert.equal(this.element.textContent.trim(), 'template block text');
|
||||
assert.equal(findAll('input').length, 2);
|
||||
assert.equal(findAll('input')[0].name, 'bird');
|
||||
assert.equal(findAll('input')[1].name, 'bird');
|
||||
});
|
||||
|
||||
test('it renders with @variable value selected', async function (assert) {
|
||||
await render(hbs`
|
||||
<Rose::Form::Radio::Group @name="bird" @variable="flamingo" as |radioGroup|>
|
||||
<radioGroup.radio
|
||||
@id="bird-1"
|
||||
@label="Pegion"
|
||||
@value="pegion"
|
||||
/>
|
||||
<radioGroup.radio
|
||||
@id="bird-2"
|
||||
@label="flamingo"
|
||||
@value="flamingo"
|
||||
/>
|
||||
</Rose::Form::Radio::Group>
|
||||
`);
|
||||
|
||||
assert.equal(findAll('#bird-1')[0].checked, false);
|
||||
assert.equal(findAll('#bird-2')[0].checked, true);
|
||||
|
||||
await click(findAll('#bird-1')[0]);
|
||||
|
||||
assert.equal(findAll('#bird-1')[0].checked, true);
|
||||
assert.equal(findAll('#bird-2')[0].checked, false);
|
||||
});
|
||||
});
|
||||
@@ -1,26 +1,59 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { render, find } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
module('Integration | Component | rose/form/radio/radio', function(hooks) {
|
||||
module('Integration | Component | rose/form/radio/radio', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
// Set any properties with this.set('myProperty', 'value');
|
||||
// Handle any actions with this.set('myAction', function(val) { ... });
|
||||
test('it renders', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio />`);
|
||||
assert.ok(await find('input'));
|
||||
assert.equal(await find('input').type, 'radio');
|
||||
});
|
||||
|
||||
await render(hbs`{{rose/form/radio/radio}}`);
|
||||
test('it renders with label', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio @label="Label"/>`);
|
||||
assert.equal(await find('label').textContent.trim(), 'Label');
|
||||
});
|
||||
|
||||
assert.equal(this.element.textContent.trim(), '');
|
||||
test('it is checked when @value and @variable values match', async function (assert) {
|
||||
await render(
|
||||
hbs`<Rose::Form::Radio::Radio @value="tree" @variable="tree"/>`
|
||||
);
|
||||
assert.equal(await find('input').checked, true);
|
||||
});
|
||||
|
||||
// Template block usage:
|
||||
await render(hbs`
|
||||
{{#rose/form/radio/radio}}
|
||||
template block text
|
||||
{{/rose/form/radio/radio}}
|
||||
`);
|
||||
test('it is not checked when @value and @variable values are different', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio @value="tree"/>`);
|
||||
assert.equal(await find('input').checked, false);
|
||||
|
||||
assert.equal(this.element.textContent.trim(), 'template block text');
|
||||
await render(hbs`<Rose::Form::Radio::Radio @variable="tree"/>`);
|
||||
assert.equal(await find('input').checked, false);
|
||||
|
||||
await render(
|
||||
hbs`<Rose::Form::Radio::Radio @value="root" @variable="tree"/>`
|
||||
);
|
||||
assert.equal(await find('input').checked, false);
|
||||
});
|
||||
|
||||
test('it is not disabled by default', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio />`);
|
||||
assert.equal(await find('input').disabled, false);
|
||||
});
|
||||
|
||||
test('it is not in error state by default', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio />`);
|
||||
assert.notOk(await find('.error'));
|
||||
});
|
||||
|
||||
test('it is disabled when @disabled={{true}}', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio @disabled={{true}}/>`);
|
||||
assert.equal(await find('input').disabled, true);
|
||||
});
|
||||
|
||||
test('it is in error state when @error={{true}}', async function (assert) {
|
||||
await render(hbs`<Rose::Form::Radio::Radio @error={{true}} />`);
|
||||
assert.ok(await find('.error'));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user