Skip to content

Commit

Permalink
Add post-form component scaffold
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Josh Justice authored and CodingItWrong committed Oct 24, 2018
1 parent 7a30c21 commit 393177c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/components/post-form.js
@@ -0,0 +1,4 @@
import Component from '@ember/component';

export default Component.extend({
});
1 change: 1 addition & 0 deletions app/templates/components/post-form.hbs
@@ -0,0 +1 @@
{{yield}}
4 changes: 3 additions & 1 deletion app/templates/posts/new.hbs
@@ -1 +1,3 @@
{{outlet}}
<h1>New Post</h1>

<PostForm />
26 changes: 26 additions & 0 deletions 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');
});
});

0 comments on commit 393177c

Please sign in to comment.