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