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

fix(browser_adapter.ts): baseElement.getAttribute #3214

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion modules/angular2/src/dom/browser_adapter.ts
Expand Up @@ -292,6 +292,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
}
return relativePath(href);
}
resetBaseElement(): void { baseElement = null; }
getUserAgent(): string { return window.navigator.userAgent; }
setData(element, name: string, value: string) { element.dataset[name] = value; }
getData(element, name: string): string { return element.dataset[name]; }
Expand All @@ -308,7 +309,7 @@ function getBaseElementHref(): string {
return null;
}
}
return baseElement.attr('href');
return baseElement.getAttribute('href');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, could you add a unit test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests but ran into a problem with baseElement cache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a resetBaseElement method to the DomAdapter (and all implementations). You can narrow it down to only the JS/Dart adapter via if (DOM.supportsDOMEvents()) {...}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did something wrong here when adding resetBaseElement and getBaseHref to the other adapters

}

// based on urlUtils.js in AngularJS 1
Expand Down
1 change: 1 addition & 0 deletions modules/angular2/src/dom/dom_adapter.ts
Expand Up @@ -127,6 +127,7 @@ export class DomAdapter {
getHistory(): History { throw _abstract(); }
getLocation(): Location { throw _abstract(); }
getBaseHref(): string { throw _abstract(); }
resetBaseElement(): void { throw _abstract(); }
getUserAgent(): string { throw _abstract(); }
setData(element, name: string, value: string) { throw _abstract(); }
getData(element, name: string): string { throw _abstract(); }
Expand Down
4 changes: 4 additions & 0 deletions modules/angular2/src/dom/html_adapter.dart
Expand Up @@ -400,6 +400,10 @@ class Html5LibDomAdapter implements DomAdapter {
throw 'not implemented';
}

resetBaseElement() {
throw 'not implemented';
}

String getUserAgent() {
throw 'not implemented';
}
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/src/dom/parse5_adapter.ts
Expand Up @@ -529,6 +529,8 @@ export class Parse5DomAdapter extends DomAdapter {
return this.defaultDoc().body;
}
}
getBaseHref(): string { throw 'not implemented'; }
resetBaseElement(): void { throw 'not implemented'; }
getHistory(): History { throw 'not implemented'; }
getLocation(): Location { throw 'not implemented'; }
getUserAgent(): string { return "Fake user agent"; }
Expand Down
53 changes: 52 additions & 1 deletion modules/angular2/test/dom/dom_adapter_spec.ts
Expand Up @@ -49,5 +49,56 @@ export function main() {
expect(DOM.isElementNode(secondChild)).toBe(true);

});

if (DOM.supportsDOMEvents()) {
it('should getBaseHref should return null if blank', () => {

var subject = DOM.getBaseHref();
var result = null;

expect(subject).toEqual(result);
});

it('should getBaseHref correctly', () => {

DOM.resetBaseElement();
var result = '/drop/bass/connon/';

var $base = DOM.createElement('base');
DOM.setAttribute($base, 'href', result);
var $head = DOM.defaultDoc().head;
DOM.appendChild($head, $base);


var subject = DOM.getBaseHref();
DOM.removeChild($head, $base);
DOM.resetBaseElement();

expect(subject).toEqual(result);

});

it('should getBaseHref relative url', () => {

DOM.resetBaseElement();
var initialValue = 'bass';

var $base = DOM.createElement('base');
DOM.setAttribute($base, 'href', initialValue);
var $head = DOM.defaultDoc().head;
DOM.appendChild($head, $base);


var result = '/' + initialValue;
var subject = DOM.getBaseHref();
DOM.removeChild($head, $base);
DOM.resetBaseElement();

expect(subject).toEqual(result);

});
}


});
}
}