|
1 | 1 | import { moduleForComponent, test } from 'ember-qunit'; |
2 | 2 | import hbs from 'htmlbars-inline-precompile'; |
| 3 | +import { set } from '@ember/object'; |
| 4 | +import PageObject from 'ember-cli-page-object'; |
| 5 | + |
| 6 | +// Since this is a tagless component, we cannot effectively use a typical page |
| 7 | +// object. |
| 8 | +// |
| 9 | +// Instead, we render the tagless form inside a test container and dynamically |
| 10 | +// define a page object using the scope of the test container. |
| 11 | + |
| 12 | +let page = PageObject.create({ scope: '.test-container' }); |
| 13 | + |
| 14 | +function renderPage() { |
| 15 | + page.render(hbs` |
| 16 | + <div class="test-container"> |
| 17 | + {{#common/busy-model-wrapper model=model}} |
| 18 | + Yielded |
| 19 | + {{/common/busy-model-wrapper}} |
| 20 | + </div> |
| 21 | + `); |
| 22 | +} |
3 | 23 |
|
4 | 24 | moduleForComponent('common/busy-model-wrapper', 'Integration | Component | common/busy model wrapper', { |
5 | | - integration: true |
| 25 | + integration: true, |
| 26 | + beforeEach() { |
| 27 | + page.setContext(this); |
| 28 | + }, |
| 29 | + afterEach() { |
| 30 | + page.removeContext(); |
| 31 | + } |
6 | 32 | }); |
7 | 33 |
|
8 | | -test('it renders', function(assert) { |
| 34 | +test('it shows "Deleting" if model is saving and is deleted', function(assert) { |
| 35 | + let model = { isSaving: true, isDeleted: true }; |
| 36 | + set(this, 'model', model); |
9 | 37 |
|
10 | | - // Set any properties with this.set('myProperty', 'value'); |
11 | | - // Handle any actions with this.on('myAction', function(val) { ... }); |
| 38 | + renderPage(); |
| 39 | + assert.equal(page.text, 'Deleting...', 'A deletion indicator is rendered in place of the yielded block.'); |
| 40 | +}); |
12 | 41 |
|
13 | | - this.render(hbs`{{common/busy-model-wrapper}}`); |
| 42 | +test('it shows "Saving" if model is saving and not deleted', function(assert) { |
| 43 | + let model = { isSaving: true, isDeleted: false }; |
| 44 | + set(this, 'model', model); |
14 | 45 |
|
15 | | - assert.equal(this.$().text().trim(), ''); |
| 46 | + renderPage(); |
| 47 | + assert.equal(page.text, 'Saving...', 'A deletion indicator is rendered in place of the yielded block.'); |
| 48 | +}); |
16 | 49 |
|
17 | | - // Template block usage: |
18 | | - this.render(hbs` |
19 | | - {{#common/busy-model-wrapper}} |
20 | | - template block text |
21 | | - {{/common/busy-model-wrapper}} |
22 | | - `); |
| 50 | +test('it shows yield if model is neither saving or deleted', function(assert) { |
| 51 | + let model = { isSaving: false, isDeleted: false }; |
| 52 | + set(this, 'model', model); |
23 | 53 |
|
24 | | - assert.equal(this.$().text().trim(), 'template block text'); |
| 54 | + renderPage(); |
| 55 | + assert.equal(page.text, 'Yielded', 'The yielded block is rendered.'); |
25 | 56 | }); |
0 commit comments