Skip to content

Commit b83aa11

Browse files
committed
added integration tests for link standalone and inline to cover this bug
1 parent f384a90 commit b83aa11

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

packages/components/tests/integration/components/hds/link/inline-test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ module('Integration | Component | hds/link/inline', function (hooks) {
6363
assert.dom('#test-link > span').hasText('test');
6464
});
6565

66+
// TARGET/REL ATTRIBUTES
67+
68+
test('it should render a <a> link with the right "target" and "rel" attributes if @href is passed', async function (assert) {
69+
assert.expect(2);
70+
await render(hbs`<Hds::Link::Inline @href="/" id="test-link" />`);
71+
assert.dom('#test-link').hasAttribute('target', '_blank');
72+
assert.dom('#test-link').hasAttribute('rel', 'noopener noreferrer');
73+
});
74+
test('it should render a <a> link with custom "target" and "rel" attributes if they are passed as attributes', async function (assert) {
75+
assert.expect(2);
76+
await render(
77+
hbs`<Hds::Link::Inline @href="/" id="test-link" target="test-target" rel="test-rel" />`
78+
);
79+
assert.dom('#test-link').hasAttribute('target', 'test-target');
80+
assert.dom('#test-link').hasAttribute('rel', 'test-rel');
81+
});
82+
test('it should render a <a> link withhout "target" and "rel" attributes if @isHrefExternal is false', async function (assert) {
83+
assert.expect(2);
84+
await render(
85+
hbs`<Hds::Link::Inline @href="/" @isHrefExternal={{false}} id="test-link" />`
86+
);
87+
assert.dom('#test-link').doesNotHaveAttribute('target');
88+
assert.dom('#test-link').doesNotHaveAttribute('rel');
89+
});
90+
6691
// ASSERTIONS
6792

6893
test('it should throw an assertion if both @href and @route are not defined', async function (assert) {
@@ -79,13 +104,13 @@ module('Integration | Component | hds/link/inline', function (hooks) {
79104
});
80105
test('it should throw an assertion if an incorrect value for @color is provided', async function (assert) {
81106
const errorMessage =
82-
'@color for "Hds::Link::Standalone" must be one of the following: primary, secondary; received: foo';
107+
'@color for "Hds::Link::Inline" must be one of the following: primary, secondary; received: foo';
83108
assert.expect(2);
84109
setupOnerror(function (error) {
85110
assert.strictEqual(error.message, `Assertion Failed: ${errorMessage}`);
86111
});
87112
await render(
88-
hbs`<Hds::Link::Standalone @icon="film" @text="watch video" @href="/" @color="foo" />`
113+
hbs`<Hds::Link::Inline @icon="film" @text="watch video" @href="/" @color="foo" />`
89114
);
90115
assert.throws(function () {
91116
throw new Error(errorMessage);

packages/components/tests/integration/components/hds/link/standalone-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ module('Integration | Component | hds/link/standalone', function (hooks) {
7676
assert.dom('#test-link').hasText('Copy to clipboard');
7777
});
7878

79+
// TARGET/REL ATTRIBUTES
80+
81+
test('it should render a <a> link with the right "target" and "rel" attributes if @href is passed', async function (assert) {
82+
assert.expect(2);
83+
await render(
84+
hbs`<Hds::Link::Standalone @text="watch video" @href="/" @icon="film" id="test-link" />`
85+
);
86+
assert.dom('#test-link').hasAttribute('target', '_blank');
87+
assert.dom('#test-link').hasAttribute('rel', 'noopener noreferrer');
88+
});
89+
test('it should render a <a> link with custom "target" and "rel" attributes if they are passed as attributes', async function (assert) {
90+
assert.expect(2);
91+
await render(
92+
hbs`<Hds::Link::Standalone @text="watch video" @href="/" @icon="film" id="test-link" target="test-target" rel="test-rel" />`
93+
);
94+
assert.dom('#test-link').hasAttribute('target', 'test-target');
95+
assert.dom('#test-link').hasAttribute('rel', 'test-rel');
96+
});
97+
test('it should render a <a> link withhout "target" and "rel" attributes if @isHrefExternal is false', async function (assert) {
98+
assert.expect(2);
99+
await render(
100+
hbs`<Hds::Link::Standalone @text="watch video" @href="/" @icon="film" @isHrefExternal={{false}} id="test-link" />`
101+
);
102+
assert.dom('#test-link').doesNotHaveAttribute('target');
103+
assert.dom('#test-link').doesNotHaveAttribute('rel');
104+
});
105+
79106
// ASSERTIONS
80107

81108
test('it should throw an assertion if both @href and @route are not defined', async function (assert) {

0 commit comments

Comments
 (0)