5
5
6
6
import { module , test } from 'qunit' ;
7
7
import { setupRenderingTest } from 'ember-qunit' ;
8
- import { render , resetOnerror , setupOnerror } from '@ember/test-helpers' ;
8
+ import {
9
+ render ,
10
+ resetOnerror ,
11
+ setupOnerror ,
12
+ waitFor ,
13
+ } from '@ember/test-helpers' ;
9
14
import { hbs } from 'ember-cli-htmlbars' ;
10
15
11
16
module ( 'Integration | Component | hds/tag/index' , function ( hooks ) {
@@ -25,6 +30,7 @@ module('Integration | Component | hds/tag/index', function (hooks) {
25
30
await render ( hbs `<Hds::Tag @text="My tag" />` ) ;
26
31
assert . dom ( 'button.hds-tag__dismiss' ) . doesNotExist ( ) ;
27
32
} ) ;
33
+
28
34
test ( 'it should render the "dismiss" button if a callback function is passed to the @onDismiss argument' , async function ( assert ) {
29
35
this . set ( 'NOOP' , ( ) => { } ) ;
30
36
await render ( hbs `<Hds::Tag @text="My tag" @onDismiss={{this.NOOP}} />` ) ;
@@ -44,6 +50,7 @@ module('Integration | Component | hds/tag/index', function (hooks) {
44
50
. dom ( 'button.hds-tag__dismiss' )
45
51
. hasAttribute ( 'aria-label' , 'Please dismiss My tag' ) ;
46
52
} ) ;
53
+
47
54
// COLOR
48
55
49
56
test ( 'it should render the primary color as the default if no @color prop is declared when the text is a link' , async function ( assert ) {
@@ -52,12 +59,14 @@ module('Integration | Component | hds/tag/index', function (hooks) {
52
59
) ;
53
60
assert . dom ( '#test-link-tag' ) . hasClass ( 'hds-tag--color-primary' ) ;
54
61
} ) ;
62
+
55
63
test ( 'it should render the correct CSS color class if the @color prop is declared when the text is a link' , async function ( assert ) {
56
64
await render (
57
65
hbs `<Hds::Tag @text="My text tag" @href="/" @color="secondary" id="test-link-tag"/>`
58
66
) ;
59
67
assert . dom ( '#test-link-tag' ) . hasClass ( 'hds-tag--color-secondary' ) ;
60
68
} ) ;
69
+
61
70
test ( 'it should throw an assertion if an incorrect value for @color is provided when the text is a link' , async function ( assert ) {
62
71
const errorMessage =
63
72
'@color for "Hds::Tag" must be one of the following: primary, secondary; received: foo' ;
@@ -70,6 +79,7 @@ module('Integration | Component | hds/tag/index', function (hooks) {
70
79
throw new Error ( errorMessage ) ;
71
80
} ) ;
72
81
} ) ;
82
+
73
83
test ( 'it should throw an assertion if @color is provided without @href or @route' , async function ( assert ) {
74
84
const errorMessage =
75
85
'@color can only be applied to "Hds::Tag" along with either @href or @route' ;
@@ -82,4 +92,23 @@ module('Integration | Component | hds/tag/index', function (hooks) {
82
92
throw new Error ( errorMessage ) ;
83
93
} ) ;
84
94
} ) ;
95
+
96
+ // OVERFLOW
97
+
98
+ test ( 'it should not render a tooltip if the text does not overflow' , async function ( assert ) {
99
+ await render ( hbs `
100
+ <Hds::Tag @text="My text tag" id="test-tag"/>
101
+ ` ) ;
102
+ assert . dom ( '.hds-tooltip-button' ) . doesNotExist ( ) ;
103
+ } ) ;
104
+
105
+ test ( 'it should render a tooltip if the text overflows' , async function ( assert ) {
106
+ await render ( hbs `
107
+ <div style="width: 50px;">
108
+ <Hds::Tag @text="This is a very long text that should go on multiple lines" id="test-tag"/>
109
+ </div>
110
+ ` ) ;
111
+ await waitFor ( '.hds-tooltip-button' , { timeout : 1000 } ) ;
112
+ assert . dom ( '.hds-tooltip-button' ) . exists ( ) ;
113
+ } ) ;
85
114
} ) ;
0 commit comments