-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathau-button-test.gts
113 lines (95 loc) · 2.9 KB
/
au-button-test.gts
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
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
import { tracked } from '@glimmer/tracking';
import { hasDeprecationStartingWith } from 'dummy/tests/helpers/deprecations';
class TestState {
@tracked isDisabled?: boolean;
@tracked isLoading?: boolean;
@tracked loadingMessage?: string;
}
module('Integration | Component | au-button', function (hooks) {
setupRenderingTest(hooks);
test('it accepts block content and extra attributes', async function (assert) {
await render(
<template>
<AuButton data-test-button>
template block text
</AuButton>
</template>,
);
assert.dom('[data-test-button]').hasText('template block text');
});
test('it disables the button when `@disabled` is true', async function (assert) {
const state = new TestState();
state.isDisabled = false;
await render(
<template>
<AuButton @disabled={{state.isDisabled}} data-test-button>
Foo
</AuButton>
</template>,
);
assert.dom('[data-test-button]').isNotDisabled();
state.isDisabled = true;
await settled();
assert.dom('[data-test-button]').isDisabled();
});
test('it disables the button when `@loading` is true', async function (assert) {
const state = new TestState();
state.isLoading = false;
await render(
<template>
<AuButton
@loading={{state.isLoading}}
@disabled={{false}}
data-test-button
>
Foo
</AuButton>
</template>,
);
assert.dom('[data-test-button]').isNotDisabled();
state.isLoading = true;
await settled();
assert.dom('[data-test-button]').isDisabled();
});
test('the default loading message is deprecated', async function (assert) {
const state = new TestState();
state.isLoading = false;
await render(
<template>
<AuButton
@loading={{state.isLoading}}
@loadingMessage={{state.loadingMessage}}
data-test-button
>
Foo
</AuButton>
</template>,
);
assert.false(
showsDeprecationMessage(),
"it does't show the deprecation if @loading isn't true",
);
state.isLoading = true;
state.loadingMessage = 'Loading';
await settled();
assert.false(
showsDeprecationMessage(),
"it does't show the deprecation if @loadingMessage is set",
);
state.loadingMessage = undefined;
await settled();
assert.true(
showsDeprecationMessage(),
"it shows the deprecation message if @loadingMessage isn't set",
);
});
});
function showsDeprecationMessage() {
return hasDeprecationStartingWith(
'[AuButton] Not providing `@loadingMessage` when setting `@loading` to `true` is deprecated.',
);
}