|
1 | 1 | import { module, test } from 'qunit'; |
2 | 2 | import { setupRenderingTest } from 'ember-qunit'; |
3 | | -import { render } from '@ember/test-helpers'; |
| 3 | +import { click, render } from '@ember/test-helpers'; |
4 | 4 | import hbs from 'htmlbars-inline-precompile'; |
| 5 | +import { helper } from '@ember/component/helper'; |
| 6 | + |
5 | 7 |
|
6 | 8 | module('Integration | Component | sidebar-layout', function(hooks) { |
7 | 9 | setupRenderingTest(hooks); |
8 | 10 |
|
9 | | - test('it renders', async function(assert) { |
10 | | - // Set any properties with this.set('myProperty', 'value'); |
11 | | - // Handle any actions with this.set('myAction', function(val) { ... }); |
12 | | - |
13 | | - await render(hbs`<SidebarLayout />`); |
14 | | - |
15 | | - assert.equal(this.element.textContent.trim(), ''); |
| 11 | + hooks.beforeEach(function() { |
| 12 | + this.owner.register('helper:route-action', helper(function noop() { |
| 13 | + return () => {}; |
| 14 | + })); |
| 15 | + this.owner.register('helper:transition-to', helper(function noop() { |
| 16 | + return () => {}; |
| 17 | + })); |
| 18 | + this.owner.register('template:components/test-sidebar', hbs`test sidebar`); |
| 19 | + }); |
16 | 20 |
|
17 | | - // Template block usage: |
| 21 | + test('it toggles', async function(assert) { |
| 22 | + this.set('isSidebarOpen', true); |
18 | 23 | await render(hbs` |
19 | | - <SidebarLayout> |
20 | | - template block text |
| 24 | + <SidebarLayout |
| 25 | + @sidebarComponent={{component "test-sidebar"}} |
| 26 | + @isSidebarOpen={{this.isSidebarOpen}} |
| 27 | + @onSidebarUpdated={{fn (mut this.isSidebarOpen)}} |
| 28 | + as |sidebar|> |
| 29 | + {{#if sidebar.isSidebarOpen}} |
| 30 | + <button class="close" {{on "click" sidebar.hideSidebar}}>Close</button> |
| 31 | + {{else}} |
| 32 | + <button class="open" {{on "click" sidebar.showSidebar}}>Open</button> |
| 33 | + {{/if}} |
| 34 | + Content Here |
21 | 35 | </SidebarLayout> |
22 | 36 | `); |
23 | 37 |
|
24 | | - assert.equal(this.element.textContent.trim(), 'template block text'); |
| 38 | + assert.dom('.sidebar').hasText('Close Menu test sidebar Sign in Help GitHub Issue tracker'); |
| 39 | + assert.dom('.content').hasText('Close Content Here'); |
| 40 | + await click('.close'); |
| 41 | + assert.dom('.sidebar').doesNotExist(); |
| 42 | + assert.dom('.content').hasText('Open Content Here'); |
| 43 | + await click('.open'); |
| 44 | + assert.dom('.content').hasText('Close Content Here'); |
25 | 45 | }); |
26 | 46 | }); |
0 commit comments