File tree 3 files changed +50
-4
lines changed
tests/integration/private/helpers
3 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { on } from '@ember/modifier';
5
5
import { action } from ' @ember/object' ;
6
6
import Component from ' @glimmer/component' ;
7
7
import { focusTrap } from ' ember-focus-trap' ;
8
+ import { cn } from ' ../private/helpers/class-names' ;
8
9
9
10
// TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version
10
11
import not from ' ember-truth-helpers/helpers/not' ;
@@ -33,7 +34,7 @@ export default class AuModal extends Component {
33
34
}
34
35
35
36
get padding () {
36
- if (this .args .padding === ' none' ) return ' au-c-modal--flush' ;
37
+ if (this .args .padding === ' none' ) return ' au-c-modal--flush' ;
37
38
else return ' ' ;
38
39
}
39
40
@@ -89,12 +90,12 @@ export default class AuModal extends Component {
89
90
<div class =" au-c-modal-backdrop {{if @ modalOpen ' is-visible' }} " ></div >
90
91
<div
91
92
id =" {{@ id }} "
92
- class ={{concat
93
- " au-c-modal "
93
+ class ={{cn
94
+ " au-c-modal"
94
95
this . size
95
96
this . padding
96
97
this . overflow
97
- ( if @ modalOpen " is-visible" )
98
+ ( if @ modalOpen " is-visible" )
98
99
}}
99
100
role =" dialog"
100
101
aria-describedby ={{concat " au-c-modal-title-" @ id}}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * A very basic alternative to https://github.com/JedWatson/classnames
3
+ */
4
+ export function cn ( ...classNames : Array < string | undefined > ) {
5
+ return classNames . filter ( Boolean ) . join ( ' ' ) ;
6
+ }
Original file line number Diff line number Diff line change
1
+ import { settled , render } from ' @ember/test-helpers' ;
2
+ import { tracked } from ' @glimmer/tracking' ;
3
+ import { setupRenderingTest } from ' ember-qunit' ;
4
+ import { module , test } from ' qunit' ;
5
+ import { cn } from ' @appuniversum/ember-appuniversum/private/helpers/class-names' ;
6
+
7
+ module (' Integration | Private Helper | class-names' , function (hooks ) {
8
+ setupRenderingTest (hooks );
9
+
10
+ test (' it accepts a list of classes and adds the needed whitespace' , async function (assert ) {
11
+ await render (
12
+ <template >
13
+ <div data-test class ={{cn " foo" " bar" " baz" }} ></div >
14
+ </template >,
15
+ );
16
+
17
+ assert .dom (' [data-test]' ).hasClass (' foo' ).hasClass (' bar' ).hasClass (' baz' );
18
+ });
19
+
20
+ test (' it removes falsy values' , async function (assert ) {
21
+ class TestState {
22
+ @tracked someFlag: boolean = false ;
23
+ }
24
+
25
+ const state = new TestState ();
26
+ await render (
27
+ <template >
28
+ <div data-test class ={{cn " foo" ( if state.someFlag " bar" ) " baz" }} ></div >
29
+ </template >,
30
+ );
31
+
32
+ assert .dom (' [data-test]' ).hasClass (' foo' ).hasNoClass (' bar' ).hasClass (' baz' );
33
+
34
+ state .someFlag = true ;
35
+ await settled ();
36
+
37
+ assert .dom (' [data-test]' ).hasClass (' foo' ).hasClass (' bar' ).hasClass (' baz' );
38
+ });
39
+ });
You can’t perform that action at this time.
0 commit comments