This repository has been archived by the owner on Feb 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Metzener
committed
Oct 25, 2018
1 parent
55b08e1
commit b6eae2d
Showing
8 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Component from "@ember/component"; | ||
import layout from "../../../templates/components/cf-field/input/checkbox"; | ||
|
||
/** | ||
* Input component for the checkbox question type | ||
* | ||
* @class CfFieldInputCheckboxComponent | ||
*/ | ||
export default Component.extend({ | ||
layout, | ||
tagName: "" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#each field.question.checkboxOptions.edges as |optionEdge i|}} | ||
{{#let optionEdge.node as |option|}} | ||
{{#if (gt i 0)}}<br>{{/if}} | ||
<label> | ||
<input | ||
class="uk-checkbox uk-margin-small-right" | ||
type="checkbox" | ||
name={{field.id}} | ||
value={{option.slug}} | ||
checked={{contains option.slug field.answer.listValue}} | ||
> | ||
{{option.label}} | ||
</label> | ||
{{/let}} | ||
{{/each}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input/checkbox"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/integration/components/cf-field/input/checkbox-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { module, test } from "qunit"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { render } from "@ember/test-helpers"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
|
||
module("Integration | Component | cf-field/input/checkbox", function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders", async function(assert) { | ||
assert.expect(12); | ||
|
||
await render(hbs` | ||
{{cf-field/input/checkbox | ||
field=(hash | ||
id="test" | ||
answer=(hash | ||
listValue=(array "option-1" "option-2") | ||
) | ||
question=(hash | ||
checkboxOptions=(hash | ||
edges=(array | ||
(hash node=(hash slug="option-1" label="Option 1")) | ||
(hash node=(hash slug="option-2" label="Option 2")) | ||
(hash node=(hash slug="option-3" label="Option 3")) | ||
) | ||
) | ||
) | ||
) | ||
}} | ||
`); | ||
|
||
assert.dom("input[type=checkbox]").exists({ count: 3 }); | ||
assert.dom("label").exists({ count: 3 }); | ||
assert.dom("br").exists({ count: 2 }); | ||
assert.dom("label:nth-of-type(3) + br").doesNotExist(); | ||
|
||
assert.dom("label:nth-of-type(1)").hasText("Option 1"); | ||
assert.dom("label:nth-of-type(2)").hasText("Option 2"); | ||
assert.dom("label:nth-of-type(3)").hasText("Option 3"); | ||
|
||
assert | ||
.dom("label:nth-of-type(1) input[type=checkbox]") | ||
.hasValue("option-1"); | ||
assert | ||
.dom("label:nth-of-type(2) input[type=checkbox]") | ||
.hasValue("option-2"); | ||
assert | ||
.dom("label:nth-of-type(3) input[type=checkbox]") | ||
.hasValue("option-3"); | ||
|
||
assert.dom("label:nth-of-type(1) input[type=checkbox]").isChecked(); | ||
assert.dom("label:nth-of-type(2) input[type=checkbox]").isChecked(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters