|
1 | 1 | import { module, test } from 'qunit';
|
2 | 2 | import { setupRenderingTest } from 'ember-qunit';
|
3 |
| -import { render, findAll } from '@ember/test-helpers'; |
| 3 | +import { render, findAll, click } from '@ember/test-helpers'; |
4 | 4 | import hbs from 'htmlbars-inline-precompile';
|
5 | 5 |
|
| 6 | +const TIMEOUT_FOR_ANIMATION = 600; |
| 7 | +const CLASSES = ['Descriptor', 'Ember']; |
| 8 | +const MODULES = ['@ember/application', '@ember/array']; |
| 9 | + |
6 | 10 | module('Integration | Component | table of contents', function (hooks) {
|
7 | 11 | setupRenderingTest(hooks);
|
8 | 12 |
|
9 | 13 | test('it renders', async function (assert) {
|
10 | 14 | // Set any properties with this.set('myProperty', 'value');
|
11 | 15 | this.set('projectId', 'Ember');
|
12 | 16 | this.set('emberVersion', '2.4.3');
|
| 17 | + this.set('classesIDs', CLASSES); |
| 18 | + |
| 19 | + await render(hbs` |
| 20 | + {{ |
| 21 | + table-of-contents showPrivateClasses=true |
| 22 | + projectid=projectId |
| 23 | + version=emberVersion |
| 24 | + classesIDs=classesIDs |
| 25 | + isShowingNamespaces=true |
| 26 | + }} |
| 27 | + `); |
| 28 | + |
| 29 | + const contentTitle = document.querySelector( |
| 30 | + '[data-test-toc-title="classes"]' |
| 31 | + ); |
| 32 | + const contentReference = '.toc-level-1'; |
| 33 | + |
| 34 | + assert.dom(contentTitle).hasText('Classes'); |
| 35 | + assert |
| 36 | + .dom(`${contentReference} li`) |
| 37 | + .exists({ count: 2 }, 'We have two items to display'); |
| 38 | + assert.dom(findAll(`${contentReference} li`)[0]).hasText(CLASSES[0]); |
| 39 | + assert.dom(findAll(`${contentReference} li`)[1]).hasText(CLASSES[1]); |
| 40 | + }); |
| 41 | + |
| 42 | + test('Starts with underlying content visible', async function (assert) { |
| 43 | + // Set any properties with this.set('myProperty', 'value'); |
| 44 | + this.set('projectId', 'Ember'); |
| 45 | + this.set('emberVersion', '2.4.3'); |
| 46 | + this.set('moduleIDs', MODULES); |
13 | 47 |
|
14 |
| - this.set('classesIDs', ['Descriptor', 'Ember']); |
| 48 | + await render(hbs` |
| 49 | + {{ |
| 50 | + table-of-contents showPrivateClasses=true |
| 51 | + projectid=projectId |
| 52 | + version=emberVersion |
| 53 | + moduleIDs=moduleIDs |
| 54 | + isShowingNamespaces=true |
| 55 | + }} |
| 56 | + `); |
15 | 57 |
|
16 |
| - await render(hbs`{{table-of-contents showPrivateClasses=true |
17 |
| - projectid=projectId |
18 |
| - version=emberVersion |
19 |
| - classesIDs=classesIDs |
20 |
| - isShowingNamespaces=true |
21 |
| - }}`); |
| 58 | + const contentReference = '.toc-level-1'; |
| 59 | + const content = document.querySelector(contentReference); |
| 60 | + const contentTitle = document.querySelector( |
| 61 | + '[data-test-toc-title="classes"]' |
| 62 | + ); |
22 | 63 |
|
23 |
| - assert.dom(findAll('.toc-level-0 > a')[2]).hasText('Classes'); |
| 64 | + assert.dom(contentTitle).hasText('Classes'); |
| 65 | + assert.dom(content).hasClass('selected'); |
24 | 66 | assert
|
25 |
| - .dom('.toc-level-1 li') |
| 67 | + .dom(`${contentReference} li`) |
26 | 68 | .exists({ count: 2 }, 'We have two items to display');
|
27 |
| - assert.dom(findAll('.toc-level-1 li')[0]).hasText('Descriptor'); |
28 |
| - assert.dom(findAll('.toc-level-1 li')[1]).hasText('Ember'); |
| 69 | + assert.dom(content).isVisible(); |
| 70 | + assert.dom(findAll(`${contentReference} li`)[0]).hasText(MODULES[0]); |
| 71 | + assert.dom(findAll(`${contentReference} li`)[1]).hasText(MODULES[1]); |
| 72 | + }); |
| 73 | + |
| 74 | + test('Underlying content hides once clicked', async function (assert) { |
| 75 | + // Set any properties with this.set('myProperty', 'value'); |
| 76 | + this.set('projectId', 'Ember'); |
| 77 | + this.set('emberVersion', '2.4.3'); |
| 78 | + this.set('moduleIDs', MODULES); |
| 79 | + |
| 80 | + await render(hbs` |
| 81 | + {{ |
| 82 | + table-of-contents showPrivateClasses=true |
| 83 | + projectid=projectId |
| 84 | + version=emberVersion |
| 85 | + moduleIDs=moduleIDs |
| 86 | + isShowingNamespaces=true |
| 87 | + }} |
| 88 | + `); |
| 89 | + |
| 90 | + const contentTitle = document.querySelector( |
| 91 | + '[data-test-toc-title="packages"]' |
| 92 | + ); |
| 93 | + const contentReference = '.toc-level-1'; |
| 94 | + const content = document.querySelector(contentReference); |
| 95 | + |
| 96 | + assert.dom(contentTitle).hasText('Packages'); |
| 97 | + assert.dom(content).hasClass('selected'); |
| 98 | + assert.dom(content).isVisible(); |
| 99 | + |
| 100 | + await click(contentTitle); |
| 101 | + |
| 102 | + const done = assert.async(); |
| 103 | + setTimeout(() => { |
| 104 | + assert.dom(content).isNotVisible(); |
| 105 | + assert.dom(content).doesNotHaveClass('selected'); |
| 106 | + done(); |
| 107 | + }, TIMEOUT_FOR_ANIMATION); |
| 108 | + }); |
| 109 | + |
| 110 | + test('Underlying content should be visible after 2 clicks', async function (assert) { |
| 111 | + // Set any properties with this.set('myProperty', 'value'); |
| 112 | + this.set('projectId', 'Ember'); |
| 113 | + this.set('emberVersion', '2.4.3'); |
| 114 | + this.set('moduleIDs', MODULES); |
| 115 | + |
| 116 | + await render(hbs` |
| 117 | + {{ |
| 118 | + table-of-contents showPrivateClasses=true |
| 119 | + projectid=projectId |
| 120 | + version=emberVersion |
| 121 | + moduleIDs=moduleIDs |
| 122 | + isShowingNamespaces=true |
| 123 | + }} |
| 124 | + `); |
| 125 | + |
| 126 | + const titleButton = document.querySelector( |
| 127 | + '[data-test-toc-title="packages"]' |
| 128 | + ); |
| 129 | + const contentReference = '.toc-level-1'; |
| 130 | + const content = document.querySelector(contentReference); |
| 131 | + |
| 132 | + assert.dom(titleButton).hasText('Packages'); |
| 133 | + assert.dom(content).hasClass('selected'); |
| 134 | + assert.dom(content).isVisible(); |
| 135 | + |
| 136 | + await click(titleButton); |
| 137 | + |
| 138 | + const done1 = assert.async(); |
| 139 | + |
| 140 | + setTimeout(async () => { |
| 141 | + assert.dom(content).isNotVisible(); |
| 142 | + assert.dom(content).doesNotHaveClass('selected'); |
| 143 | + |
| 144 | + await click(titleButton); |
| 145 | + |
| 146 | + const done2 = assert.async(); |
| 147 | + |
| 148 | + setTimeout(() => { |
| 149 | + assert.dom(content).isVisible(); |
| 150 | + assert.dom(content).hasClass('selected'); |
| 151 | + done2(); |
| 152 | + }, TIMEOUT_FOR_ANIMATION); |
| 153 | + |
| 154 | + done1(); |
| 155 | + }, TIMEOUT_FOR_ANIMATION); |
29 | 156 | });
|
30 | 157 | });
|
0 commit comments