-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsl-alert-test.js
executable file
·138 lines (108 loc) · 3.43 KB
/
sl-alert-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { moduleForComponent, test } from 'ember-qunit';
import TooltipEnabledMixin from 'sl-ember-components/mixins/sl-tooltip-enabled';
import { Theme as ThemeEnum } from 'sl-ember-components/components/sl-alert';
import sinon from 'sinon';
import globalLibraries from '../../helpers/sl/synchronous/global-libraries';
import Ember from 'ember';
import * as warn from 'sl-ember-components/utils/warn';
const Theme = {
DANGER: 'danger',
INFO: 'info',
SUCCESS: 'success',
WARNING: 'warning'
};
moduleForComponent( 'sl-alert', 'Unit | Component | sl alert', {
unit: true
});
test( 'Expected Mixins are present', function( assert ) {
assert.ok(
TooltipEnabledMixin.detect( this.subject() ),
'TooltipEnabled Mixin is present'
);
});
test( 'Default property values are set correctly', function( assert ) {
const component = this.subject();
assert.strictEqual(
component.get( 'ariaRole' ),
'alert',
'ariaRole: "alert"'
);
assert.strictEqual(
component.get( 'dismissable' ),
false,
'dismissable: false'
);
assert.strictEqual(
component.get( 'theme' ),
Theme.INFO,
`theme: "${Theme.INFO}"`
);
assert.deepEqual(
ThemeEnum,
Theme,
'Theme enum values are correct'
);
});
test( 'Bound "dismiss" action is triggered when dismiss action is triggered', function( assert ) {
const component = this.subject();
const spy = sinon.spy( component, 'sendAction' );
component.send( 'dismiss' );
assert.strictEqual(
spy.args[0].join(),
'dismiss',
'Bound "dismiss" action is triggered when dismiss action is triggered'
);
});
test( 'themeClassName() returns expected value', function( assert ) {
const testThemeValue = 'testTheme';
const component = this.subject({
theme: testThemeValue
});
assert.strictEqual(
component.get( 'themeClassName' ),
`alert-${testThemeValue}`,
'themeClassName() returns expected value'
);
});
test( 'Dependent keys are correct', function( assert ) {
const component = this.subject();
const themeClassNameDependentKeys = [
'theme'
];
assert.deepEqual(
component.themeClassName._dependentKeys,
themeClassNameDependentKeys,
'Dependent keys are correct for themeClassName()'
);
});
test( 'There are no references to Ember.$, $ or jQuery', function( assert ) {
globalLibraries.setupSpies();
const component = this.subject();
this.render();
globalLibraries.triggerEvents( component );
assert.notOk(
globalLibraries.called(),
'Global libraries are not referenced in component'
);
globalLibraries.restoreSpies();
});
test( 'themeClassName() returns the correct class', function( assert ) {
const component = this.subject();
Object.keys( Theme ).forEach( ( key ) => {
const theme = Theme[ key ];
Ember.run( () => component.set( 'theme', theme ) );
assert.strictEqual(
component.get( 'themeClassName' ),
`alert-${theme}`,
'themeClassName() returns expected value'
);
});
const spy = sinon.spy( warn, 'default' );
component.set( 'theme', 'invalid value' );
component.get( 'themeClassName' );
assert.ok(
spy.calledOnce,
'warn() was called when invalid theme was set'
);
warn.default.restore();
});