Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: fixed links handling which lead to "/" #179

Merged
merged 1 commit into from
Jun 18, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ilc/client/ClientRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class ClientRouter {
const {specialRole} = this.#router.match(pathname);

if (specialRole === null) {
this.#navigateToUrl(pathname);
this.#navigateToUrl(href);
event.preventDefault();
}
};
Expand Down
42 changes: 38 additions & 4 deletions ilc/client/ClientRouter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ describe('client router', () => {
appName: apps['@portal/hero'].name,
},
},
},
{
routeId: 'rootRoute',
route: '/',
next: false,
template: 'baseTemplate',
slots: {
opponent: {
appName: apps['@portal/opponent'].name,
},
hero: {
appName: apps['@portal/hero'].name,
},
},
}
];

Expand Down Expand Up @@ -381,7 +395,7 @@ describe('client router', () => {
singleSpa.navigateToUrl.resetHistory();
});

it('should prevent click events on anchors and navigate to a registered micro front-end page', () => {
it('should handle click events on anchors and navigate to a registered micro front-end page', () => {
const anchor = {
id: 'click-me',
href: registryConfig.routes[2].route,
Expand All @@ -401,7 +415,27 @@ describe('client router', () => {
chai.expect(clickEvent.defaultPrevented).to.be.true;
});

it('should not prevent click events on anchors when anchors do not have href attribute', () => {
it('should handle click events on "http(s)://domain" anchors if we have "/" route', () => {
const anchor = {
id: 'click-me',
href: location.origin,
};

anchor.ref = html`
<a id="${anchor.id}" href="${anchor.href}">
Hi there! I am anchor tag and I have href attribute.
So I should forward you to registered micro front-end page.
</a>
`;

document.body.appendChild(anchor.ref);
document.getElementById(anchor.id).dispatchEvent(clickEvent);

chai.expect(singleSpa.navigateToUrl.calledOnceWithExactly(anchor.href)).to.be.true;
chai.expect(clickEvent.defaultPrevented).to.be.true;
});

it('should NOT handle click events on anchors when anchors do not have href attribute', () => {
const anchor = {
id: 'click-me',
};
Expand All @@ -420,7 +454,7 @@ describe('client router', () => {
chai.expect(clickEvent.defaultPrevented).to.be.false;
});

it('should not prevent click events on anchors when these events were already default prevented', () => {
it('should NOT handle click events on anchors when these events were already default prevented', () => {
const anchor = {
id: 'click-me',
href: registryConfig.routes[2].route,
Expand All @@ -443,7 +477,7 @@ describe('client router', () => {
chai.expect(singleSpa.navigateToUrl.called).to.be.false;
});

it('should not prevent click events on anchors when anchors are not going to a registered micro front-end page', () => {
it('should NOT handle click events on anchors when anchors are not going to a registered micro front-end page', () => {
const anchor = {
id: 'click-me',
href: '/undefined',
Expand Down