Skip to content

Commit abd2aac

Browse files
committed
updated integration tests for “button”
1 parent 011de8d commit abd2aac

File tree

1 file changed

+37
-2
lines changed
  • packages/components/tests/integration/components/hds/button

1 file changed

+37
-2
lines changed

packages/components/tests/integration/components/hds/button/index-test.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ module('Integration | Component | hds/button/index', function (hooks) {
1010
resetOnerror();
1111
});
1212

13-
test('it renders a button with the defined text', async function (assert) {
13+
test('it renders the button', async function (assert) {
1414
await render(hbs`<Hds::Button @text="Copy to clipboard" />`);
15-
assert.dom(this.element).hasText('Copy to clipboard');
15+
assert.dom(this.element).exists();
1616
});
1717
test('it should render with a CSS class that matches the component name', async function (assert) {
1818
await render(
@@ -91,6 +91,15 @@ module('Integration | Component | hds/button/index', function (hooks) {
9191
.doesNotHaveAria('label', 'copy to clipboard');
9292
});
9393

94+
// TEXT
95+
96+
test('it renders a button with the defined text', async function (assert) {
97+
await render(
98+
hbs`<Hds::Button @text="Copy to clipboard" id="test-toggle-button" />`
99+
);
100+
assert.dom('#test-toggle-button').hasText('Copy to clipboard');
101+
});
102+
94103
// A11Y
95104

96105
test('it should have aria-label on the button element if isIconOnly is set to true', async function (assert) {
@@ -99,6 +108,18 @@ module('Integration | Component | hds/button/index', function (hooks) {
99108
);
100109
assert.dom('#test-button').hasAria('label', 'copy to clipboard');
101110
});
111+
test('it should have "button" type by default', async function (assert) {
112+
await render(
113+
hbs`<Hds::Button @text="copy to clipboard" id="test-button" />`
114+
);
115+
assert.dom('#test-button').hasAttribute('type', 'button');
116+
});
117+
test('it should have a custom type if @type is set', async function (assert) {
118+
await render(
119+
hbs`<Hds::Button @text="copy to clipboard" @type="submit" id="test-button" />`
120+
);
121+
assert.dom('#test-button').hasAttribute('type', 'submit');
122+
});
102123

103124
// OTHER
104125

@@ -146,6 +167,20 @@ module('Integration | Component | hds/button/index', function (hooks) {
146167
throw new Error(errorMessage);
147168
});
148169
});
170+
test('it should throw an assertion if @type is provided together with @href', async function (assert) {
171+
const errorMessage =
172+
'@type for "Hds::Button" should be passed only to generate a <button> (you\'re passing @href or @route so this will generate a <a> link)';
173+
assert.expect(2);
174+
setupOnerror(function (error) {
175+
assert.strictEqual(error.message, `Assertion Failed: ${errorMessage}`);
176+
});
177+
await render(
178+
hbs`<Hds::Button @text="copy to clipboard" @href="#" @type="submit" />`
179+
);
180+
assert.throws(function () {
181+
throw new Error(errorMessage);
182+
});
183+
});
149184
test('it should throw an assertion if an incorrect value for @size is provided', async function (assert) {
150185
const errorMessage =
151186
'@size for "Hds::Button" must be one of the following: small, medium, large; received: tiny';

0 commit comments

Comments
 (0)