From 393177c1feb554532d569e04db32686194f361f9 Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Wed, 10 Jan 2018 08:18:25 -0500 Subject: [PATCH] Add post-form component scaffold `ember g component post-form` Rather than just getting the test to pass by putting a form input on the route's template, we "write the code we wish we had." In this case, we wish we had a `post-form` component to use that would provide the form inputs for us. We generate it and go ahead and render it in our route template. --- app/components/post-form.js | 4 +++ app/templates/components/post-form.hbs | 1 + app/templates/posts/new.hbs | 4 ++- .../integration/components/post-form-test.js | 26 +++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/components/post-form.js create mode 100644 app/templates/components/post-form.hbs create mode 100644 tests/integration/components/post-form-test.js diff --git a/app/components/post-form.js b/app/components/post-form.js new file mode 100644 index 0000000..bb93d73 --- /dev/null +++ b/app/components/post-form.js @@ -0,0 +1,4 @@ +import Component from '@ember/component'; + +export default Component.extend({ +}); diff --git a/app/templates/components/post-form.hbs b/app/templates/components/post-form.hbs new file mode 100644 index 0000000..889d9ee --- /dev/null +++ b/app/templates/components/post-form.hbs @@ -0,0 +1 @@ +{{yield}} diff --git a/app/templates/posts/new.hbs b/app/templates/posts/new.hbs index c24cd68..bc4762c 100644 --- a/app/templates/posts/new.hbs +++ b/app/templates/posts/new.hbs @@ -1 +1,3 @@ -{{outlet}} +

New Post

+ + diff --git a/tests/integration/components/post-form-test.js b/tests/integration/components/post-form-test.js new file mode 100644 index 0000000..1997447 --- /dev/null +++ b/tests/integration/components/post-form-test.js @@ -0,0 +1,26 @@ +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 | post-form', 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`{{post-form}}`); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + {{#post-form}} + template block text + {{/post-form}} + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +});