1
- import { module , test } from 'qunit' ;
1
+ import AuAccordion from ' @appuniversum/ember-appuniversum/components/au-accordion' ;
2
+ import { click , settled , render } from ' @ember/test-helpers' ;
3
+ import { tracked } from ' @glimmer/tracking' ;
2
4
import { setupRenderingTest } from ' ember-qunit' ;
3
- import { click , render } from '@ember/test-helpers' ;
4
- import { hbs } from 'ember-cli-htmlbars' ;
5
+ import { module , test } from ' qunit' ;
5
6
6
7
const ACCORDION = {
7
8
TOGGLE: ' [data-test-accordion-toggle]' ,
@@ -13,25 +14,35 @@ const ACCORDION = {
13
14
LOADER: ' [data-test-accordion-loader]' ,
14
15
};
15
16
17
+ class TestState {
18
+ @tracked iconClosed? : string ;
19
+ @tracked iconOpen? : string ;
20
+ @tracked isLoading? : boolean ;
21
+ }
22
+
16
23
module (' Integration | Component | au-accordion' , function (hooks ) {
17
24
setupRenderingTest (hooks );
18
25
19
26
test (" it doesn't render any content when initially rendered" , async function (assert ) {
20
- await render ( hbs `
21
- <AuAccordion>
22
- Content
23
- </AuAccordion>
24
- ` ) ;
27
+ await render (
28
+ <template >
29
+ <AuAccordion >
30
+ Content
31
+ </AuAccordion >
32
+ </template >,
33
+ );
25
34
26
35
assert .dom (ACCORDION .CONTENT ).doesNotExist ();
27
36
});
28
37
29
38
test (' it toggles its content rendering when clicking it' , async function (assert ) {
30
- await render ( hbs `
31
- <AuAccordion>
32
- Some content
33
- </AuAccordion>
34
- ` ) ;
39
+ await render (
40
+ <template >
41
+ <AuAccordion >
42
+ Some content
43
+ </AuAccordion >
44
+ </template >,
45
+ );
35
46
36
47
await toggleAccordion ();
37
48
assert .dom (ACCORDION .CONTENT ).exists ().hasText (' Some content' );
@@ -41,31 +52,37 @@ module('Integration | Component | au-accordion', function (hooks) {
41
52
});
42
53
43
54
test (' it can display a subtitle' , async function (assert ) {
44
- await render ( hbs `
45
- <AuAccordion @subtitle="Foo">
46
- Some content
47
- </AuAccordion>
48
- ` ) ;
55
+ await render (
56
+ <template >
57
+ <AuAccordion @ subtitle =" Foo" >
58
+ Some content
59
+ </AuAccordion >
60
+ </template >,
61
+ );
49
62
50
63
assert .dom (ACCORDION .SUBTITLE ).exists ().hasText (' Foo' );
51
64
});
52
65
53
66
test (' it supports changing the label of the toggle button' , async function (assert ) {
54
- await render ( hbs `
55
- <AuAccordion @buttonLabel="Foo button">
56
- Some content
57
- </AuAccordion>
58
- ` ) ;
67
+ await render (
68
+ <template >
69
+ <AuAccordion @ buttonLabel =" Foo button" >
70
+ Some content
71
+ </AuAccordion >
72
+ </template >,
73
+ );
59
74
60
75
assert .dom (ACCORDION .BUTTON ).exists ().hasText (' Foo button' );
61
76
});
62
77
63
78
test (' it shows a different icon depending on the open state' , async function (assert ) {
64
- await render ( hbs `
65
- <AuAccordion>
66
- Some content
67
- </AuAccordion>
68
- ` ) ;
79
+ await render (
80
+ <template >
81
+ <AuAccordion >
82
+ Some content
83
+ </AuAccordion >
84
+ </template >,
85
+ );
69
86
70
87
assert .dom (ACCORDION .ICON_OPEN ).doesNotExist ();
71
88
assert .dom (ACCORDION .ICON_CLOSED ).exists ();
@@ -76,17 +93,24 @@ module('Integration | Component | au-accordion', function (hooks) {
76
93
});
77
94
78
95
test (' it supports choosing different icons' , async function (assert ) {
79
- await render ( hbs `
80
- <AuAccordion @iconOpen={{this.iconOpen}} @iconClosed={{this.iconClosed}}>
81
- Some content
82
- </AuAccordion>
83
- ` ) ;
96
+ const state = new TestState ();
97
+ await render (
98
+ <template >
99
+ <AuAccordion
100
+ @ iconOpen ={{state.iconOpen }}
101
+ @ iconClosed ={{state.iconClosed }}
102
+ >
103
+ Some content
104
+ </AuAccordion >
105
+ </template >,
106
+ );
84
107
85
108
assert
86
109
.dom (ACCORDION .ICON_CLOSED )
87
110
.hasAttribute (' data-test-accordion-icon-closed' , ' nav-right' );
88
111
89
- this . set ( 'iconClosed' , 'other-closed-icon' ) ;
112
+ state .iconClosed = ' other-closed-icon' ;
113
+ await settled ();
90
114
91
115
assert
92
116
.dom (ACCORDION .ICON_CLOSED )
@@ -97,35 +121,42 @@ module('Integration | Component | au-accordion', function (hooks) {
97
121
.dom (ACCORDION .ICON_OPEN )
98
122
.hasAttribute (' data-test-accordion-icon-open' , ' nav-down' );
99
123
100
- this . set ( 'iconOpen' , 'other-open-icon' ) ;
124
+ state .iconOpen = ' other-open-icon' ;
125
+ await settled ();
101
126
102
127
assert
103
128
.dom (ACCORDION .ICON_OPEN )
104
129
.hasAttribute (' data-test-accordion-icon-open' , ' other-open-icon' );
105
130
});
106
131
107
132
test (' it can show a loading indicator instead of content' , async function (assert ) {
108
- this . isLoading = true ;
133
+ const state = new TestState ();
134
+ state .isLoading = true ;
109
135
110
- await render ( hbs `
111
- <AuAccordion @loading={{this.isLoading}}>Some content</AuAccordion>
112
- ` ) ;
136
+ await render (
137
+ <template >
138
+ <AuAccordion @ loading ={{state.isLoading }} >Some content</AuAccordion >
139
+ </template >,
140
+ );
113
141
114
142
assert .dom (ACCORDION .LOADER ).doesNotExist ();
115
143
116
144
await toggleAccordion ();
117
145
assert .dom (ACCORDION .LOADER ).exists ();
118
146
assert .dom (ACCORDION .CONTENT ).doesNotContainText (' Some content' );
119
147
120
- this . set ( 'isLoading' , false ) ;
148
+ state .isLoading = false ;
149
+ await settled ();
121
150
assert .dom (ACCORDION .LOADER ).doesNotExist ();
122
151
assert .dom (ACCORDION .CONTENT ).containsText (' Some content' );
123
152
});
124
153
125
154
test (" it's possible to add extra html attributes" , async function (assert ) {
126
- await render ( hbs `
127
- <AuAccordion class="test" data-test-accordion-external></AuAccordion>
128
- ` ) ;
155
+ await render (
156
+ <template >
157
+ <AuAccordion class =" test" data-test-accordion-external />
158
+ </template >,
159
+ );
129
160
130
161
assert .dom (' [data-test-accordion-external]' ).exists ().hasClass (' test' );
131
162
});
0 commit comments