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