Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BIGFIX release] Fix <LinkTo> with nested children #19597

Merged
merged 1 commit into from Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -138,7 +138,7 @@ class LinkTo extends InternalComponent implements DeprecatingInternalComponent {
return;
}

let element = event.target;
let element = event.currentTarget;
assert('[BUG] must be an <a> element', element instanceof HTMLAnchorElement);

let isSelf = element.target === '' || element.target === '_self';
Expand Down
Expand Up @@ -92,6 +92,47 @@ moduleFor(
);
}

async ['@test [GH#19546] it navigates into the named route when containing other elements'](
assert
) {
this.addTemplate(
'about',
`
<h3 class="about">About</h3>
<LinkTo @route='index' id='home-link'><span id='inside'>Home</span></LinkTo>
<LinkTo @route='about' id='self-link'>Self</LinkTo>
`
);

await this.visit('/about');

assert.equal(this.$('h3.about').length, 1, 'The about template was rendered');
assert.equal(
this.$('#self-link.active').length,
1,
'The self-link was rendered with active class'
);
assert.equal(
this.$('#home-link:not(.active)').length,
1,
'The other link was rendered without active class'
);

await this.click('#inside');

assert.equal(this.$('h3.home').length, 1, 'The home template was rendered');
assert.equal(
this.$('#self-link.active').length,
1,
'The self-link was rendered with active class'
);
assert.equal(
this.$('#about-link:not(.active)').length,
1,
'The other link was rendered without active class'
);
}

async [`@test [DEPRECATED] it doesn't add an href when the tagName isn't 'a'`](assert) {
this.addTemplate(
'index',
Expand Down
Expand Up @@ -92,6 +92,47 @@ moduleFor(
);
}

async ['@test [GH#19546] it navigates into the named route when containing other elements'](
assert
) {
this.addTemplate(
'about',
`
<h3 class="about">About</h3>
<div id="home-link">{{#link-to route='index'}}<span id='inside'>Home</span>{{/link-to}}</div>
<div id="self-link">{{#link-to route='about'}}Self{{/link-to}}</div>
`
);

await this.visit('/about');

assert.equal(this.$('h3.about').length, 1, 'The about template was rendered');
assert.equal(
this.$('#self-link > a.active').length,
1,
'The self-link was rendered with active class'
);
assert.equal(
this.$('#home-link > a:not(.active)').length,
1,
'The other link was rendered without active class'
);

await this.click('#inside');

assert.equal(this.$('h3.home').length, 1, 'The home template was rendered');
assert.equal(
this.$('#self-link > a.active').length,
1,
'The self-link was rendered with active class'
);
assert.equal(
this.$('#about-link > a:not(.active)').length,
1,
'The other link was rendered without active class'
);
}

async [`@test [DEPRECATED] it doesn't add an href when the tagName isn't 'a'`](assert) {
this.addTemplate(
'index',
Expand Down