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

Handle absolute image path #159

Merged
merged 1 commit into from
Feb 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addon/services/responsive-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export default class ResponsiveImageService extends Service {
}

getMeta(imageName: string): Meta {
if (imageName.charAt(0) === '/') {
imageName = imageName.slice(1);
}
assert(
`There is no data for image ${imageName}: ${this.meta}`,
Object.prototype.hasOwnProperty.call(this.meta, imageName)
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/components/responsive-image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ module('Integration: Responsive Image Component', function (hooks) {
assert.dom('img').hasNoClass('eri-fixed');
});

test('handles absolute paths', async function (assert) {
await render(
hbs`<ResponsiveImage @src="/assets/images/tests/test.png"/>`
);

assert.dom('img').exists();
});

test('it renders width and height attributes', async function (assert) {
await render(hbs`<ResponsiveImage @src="assets/images/tests/test.png"/>`);

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/services/responsive-image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ module('ResponsiveImageService', function (hooks) {
assert.deepEqual(images, meta['test.png'].images);
});

test('handle absolute pats', function (assert) {
let service = this.owner.lookup('service:responsive-image');
let images = service.getImages('/test.png');
assert.deepEqual(images, meta['test.png'].images);
});

test('retrieve generated images by name and type', function (assert) {
let service = this.owner.lookup('service:responsive-image');
let images = service.getImages('test.png', 'png');
Expand Down