|
1 |
| -import { render } from '@ember/test-helpers'; |
| 1 | +import { click, render } from '@ember/test-helpers'; |
| 2 | +import { setProperties } from '@ember/object'; |
2 | 3 | import { module, test } from 'qunit';
|
3 | 4 | import { setupRenderingTest } from 'ember-qunit';
|
4 | 5 | import hbs from 'htmlbars-inline-precompile';
|
5 | 6 |
|
| 7 | +const customHomeUrl = 'https://github.com/emberjs'; |
| 8 | + |
6 | 9 | module('Integration | Component | es header', function(hooks) {
|
7 | 10 | setupRenderingTest(hooks);
|
8 | 11 |
|
9 |
| - test('it renders', async function(assert) { |
10 |
| - // Set any properties with this.set('myProperty', 'value'); |
11 |
| - // Handle any actions with this.on('myAction', function(val) { ... }); |
| 12 | + test('it uses the header HTML element with correct attributes', async function(assert) { |
| 13 | + await render(hbs`<EsHeader/>`); |
| 14 | + |
| 15 | + assert.dom('header').exists({ count: 1 }); |
| 16 | + assert.dom('header').hasClass('es-header'); |
| 17 | + assert.dom('header').hasAttribute('role', 'banner'); |
| 18 | + }); |
| 19 | + |
| 20 | + test('it renders the logo', async function(assert) { |
| 21 | + await render(hbs`<EsHeader/>`); |
12 | 22 |
|
13 |
| - await render(hbs`{{es-header}}`); |
| 23 | + assert.dom('.navbar-brand').hasAttribute('src', '/images/ember-logo.svg'); |
| 24 | + }); |
| 25 | + |
| 26 | + test('it renders the link to the Ember homepage by default', async function(assert) { |
| 27 | + await render(hbs`<EsHeader/>`); |
| 28 | + |
| 29 | + assert.dom('.navbar-brand-wrapper').hasAttribute('href', 'https://www.emberjs.com'); |
| 30 | + }); |
14 | 31 |
|
15 |
| - assert.dom(this.element).containsText('Show Site Navigation'); |
| 32 | + test('it renders a link to a custom homepage', async function(assert) { |
| 33 | + setProperties(this, { customHomeUrl }); |
| 34 | + await render(hbs`<EsHeader @home={{customHomeUrl}} />`); |
16 | 35 |
|
17 |
| - // Template block usage: |
| 36 | + assert.dom('.navbar-brand-wrapper').hasAttribute('href', customHomeUrl); |
| 37 | + }); |
| 38 | + |
| 39 | + test('it renders custom content at the end', async function(assert) { |
18 | 40 | await render(hbs`
|
19 |
| - {{#es-header}} |
20 |
| - template block text |
21 |
| - {{/es-header}} |
| 41 | + <EsHeader> |
| 42 | + Custom content |
| 43 | + </EsHeader> |
22 | 44 | `);
|
23 | 45 |
|
24 |
| - assert.dom(this.element).containsText('template block text'); |
| 46 | + assert.dom('.navbar-end').containsText('Custom content'); |
25 | 47 | });
|
26 | 48 |
|
27 |
| - test('it uses the header html element', async function(assert) { |
28 |
| - await render(hbs`{{es-header}}`); |
29 |
| - assert.dom('header').exists({ count: 1 }, 'the header uses the header html element!'); |
30 |
| - }); |
| 49 | + test('it renders the navbar collapsed by default', async function(assert) { |
| 50 | + await render(hbs`<EsHeader/>`); |
31 | 51 |
|
32 |
| - test('it has the role of banner', async function(assert) { |
33 |
| - await render(hbs`{{es-header}}`); |
34 |
| - assert.dom('header').hasAttribute('role', 'banner', 'header has the role of banner'); |
| 52 | + assert.dom('.es-navbar').doesNotHaveClass('navbar-expanded'); |
| 53 | + assert.dom('.navbar-toggler').containsText('Show Site Navigation'); |
35 | 54 | });
|
36 | 55 |
|
37 |
| - //the class matches the component name |
38 |
| - //but how do I make it so it just checks for the one of them? |
39 |
| - test('it has the className es-header', async function(assert) { |
40 |
| - await render(hbs`{{es-header}}`); |
41 |
| - assert.dom('header').hasClass('es-header'); |
| 56 | + test('it toggles the navbar when click the toggler', async function(assert) { |
| 57 | + await render(hbs`<EsHeader/>`); |
| 58 | + |
| 59 | + await click('.navbar-toggler'); |
| 60 | + |
| 61 | + assert.dom('.es-navbar').hasClass('navbar-expanded'); |
| 62 | + assert.dom('.navbar-toggler').containsText('Hide Site Navigation'); |
| 63 | + |
| 64 | + await click('.navbar-toggler'); |
| 65 | + |
| 66 | + assert.dom('.es-navbar').doesNotHaveClass('navbar-expanded'); |
| 67 | + assert.dom('.navbar-toggler').containsText('Show Site Navigation'); |
42 | 68 | });
|
43 | 69 | });
|
0 commit comments