Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
df9e6b67
Commit
df9e6b67
authored
5 years ago
by
Art Lowel
Browse files
Options
Downloads
Patches
Plain Diff
improve thumbnailcomponent test coverage
parent
6824ccb3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/thumbnail/thumbnail.component.spec.ts
+34
-20
34 additions, 20 deletions
src/app/thumbnail/thumbnail.component.spec.ts
src/app/thumbnail/thumbnail.component.ts
+6
-6
6 additions, 6 deletions
src/app/thumbnail/thumbnail.component.ts
with
40 additions
and
26 deletions
src/app/thumbnail/thumbnail.component.spec.ts
+
34
−
20
View file @
df9e6b67
...
...
@@ -4,7 +4,7 @@ import { By } from '@angular/platform-browser';
import
{
Bitstream
}
from
'
../core/shared/bitstream.model
'
;
import
{
SafeUrlPipe
}
from
'
../shared/utils/safe-url-pipe
'
;
import
{
ThumbnailComponent
}
from
'
./thumbnail.component
'
;
import
{
THUMBNAIL_PLACEHOLDER
,
ThumbnailComponent
}
from
'
./thumbnail.component
'
;
describe
(
'
ThumbnailComponent
'
,
()
=>
{
let
comp
:
ThumbnailComponent
;
...
...
@@ -25,26 +25,40 @@ describe('ThumbnailComponent', () => {
el
=
de
.
nativeElement
;
});
it
(
'
should display image
'
,
()
=>
{
const
thumbnail
=
new
Bitstream
();
thumbnail
.
_links
=
{
self
:
{
href
:
'
self.url
'
},
bundle
:
{
href
:
'
bundle.url
'
},
format
:
{
href
:
'
format.url
'
},
content
:
{
href
:
'
content.url
'
},
};
comp
.
thumbnail
=
thumbnail
;
fixture
.
detectChanges
();
const
image
:
HTMLElement
=
de
.
query
(
By
.
css
(
'
img
'
)).
nativeElement
;
expect
(
image
.
getAttribute
(
'
src
'
)).
toBe
(
comp
.
thumbnail
.
_links
.
content
.
href
);
describe
(
'
when the thumbnail exists
'
,
()
=>
{
it
(
'
should display an image
'
,
()
=>
{
const
thumbnail
=
new
Bitstream
();
thumbnail
.
_links
=
{
self
:
{
href
:
'
self.url
'
},
bundle
:
{
href
:
'
bundle.url
'
},
format
:
{
href
:
'
format.url
'
},
content
:
{
href
:
'
content.url
'
},
};
comp
.
thumbnail
=
thumbnail
;
fixture
.
detectChanges
();
const
image
:
HTMLElement
=
de
.
query
(
By
.
css
(
'
img
'
)).
nativeElement
;
expect
(
image
.
getAttribute
(
'
src
'
)).
toBe
(
comp
.
thumbnail
.
_links
.
content
.
href
);
});
});
it
(
'
should display placeholder
'
,
()
=>
{
const
thumbnail
=
new
Bitstream
();
comp
.
thumbnail
=
thumbnail
;
fixture
.
detectChanges
();
const
image
:
HTMLElement
=
de
.
query
(
By
.
css
(
'
img
'
)).
nativeElement
;
expect
(
image
.
getAttribute
(
'
src
'
)).
toBe
(
comp
.
defaultImage
);
describe
(
`when the thumbnail doesn't exist`
,
()
=>
{
describe
(
'
and there is a default image
'
,
()
=>
{
it
(
'
should display the default image
'
,
()
=>
{
comp
.
src
=
'
http://bit.stream
'
;
comp
.
defaultImage
=
'
http://default.img
'
;
comp
.
errorHandler
();
expect
(
comp
.
src
).
toBe
(
comp
.
defaultImage
);
});
});
describe
(
'
and there is no default image
'
,
()
=>
{
it
(
'
should display the placeholder
'
,
()
=>
{
comp
.
src
=
'
http://default.img
'
;
comp
.
defaultImage
=
'
http://default.img
'
;
comp
.
errorHandler
();
expect
(
comp
.
src
).
toBe
(
THUMBNAIL_PLACEHOLDER
);
})
});
});
;
});
This diff is collapsed.
Click to expand it.
src/app/thumbnail/thumbnail.component.ts
+
6
−
6
View file @
df9e6b67
...
...
@@ -5,7 +5,7 @@ import { hasValue } from '../shared/empty.util';
/**
* A fallback placeholder image as a base64 string
*/
const
placeholder
=
'
data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2293%22%20height%3D%22120%22%20viewBox%3D%220%200%2093%20120%22%20preserveAspectRatio%3D%22none%22%3E%3C!--%0ASource%20URL%3A%20holder.js%2F93x120%3Ftext%3DNo%20Thumbnail%0ACreated%20with%20Holder.js%202.8.2.%0ALearn%20more%20at%20http%3A%2F%2Fholderjs.com%0A(c)%202012-2015%20Ivan%20Malopinsky%20-%20http%3A%2F%2Fimsky.co%0A--%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%3C!%5BCDATA%5B%23holder_1543e460b05%20text%20%7B%20fill%3A%23AAAAAA%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A10pt%20%7D%20%5D%5D%3E%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_1543e460b05%22%3E%3Crect%20width%3D%2293%22%20height%3D%22120%22%20fill%3D%22%23FFFFFF%22%2F%3E%3Cg%3E%3Ctext%20x%3D%2235.6171875%22%20y%3D%2257%22%3ENo%3C%2Ftext%3E%3Ctext%20x%3D%2210.8125%22%20y%3D%2272%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E
'
;
export
const
THUMBNAIL_PLACEHOLDER
=
'
data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2293%22%20height%3D%22120%22%20viewBox%3D%220%200%2093%20120%22%20preserveAspectRatio%3D%22none%22%3E%3C!--%0ASource%20URL%3A%20holder.js%2F93x120%3Ftext%3DNo%20Thumbnail%0ACreated%20with%20Holder.js%202.8.2.%0ALearn%20more%20at%20http%3A%2F%2Fholderjs.com%0A(c)%202012-2015%20Ivan%20Malopinsky%20-%20http%3A%2F%2Fimsky.co%0A--%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%3C!%5BCDATA%5B%23holder_1543e460b05%20text%20%7B%20fill%3A%23AAAAAA%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A10pt%20%7D%20%5D%5D%3E%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_1543e460b05%22%3E%3Crect%20width%3D%2293%22%20height%3D%22120%22%20fill%3D%22%23FFFFFF%22%2F%3E%3Cg%3E%3Ctext%20x%3D%2235.6171875%22%20y%3D%2257%22%3ENo%3C%2Ftext%3E%3Ctext%20x%3D%2210.8125%22%20y%3D%2272%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E
'
;
/**
* This component renders a given Bitstream as a thumbnail.
...
...
@@ -27,7 +27,7 @@ export class ThumbnailComponent implements OnInit {
/**
* The default image, used if the thumbnail isn't set or can't be downloaded
*/
@
Input
()
defaultImage
?
=
placeholder
;
@
Input
()
defaultImage
?
=
THUMBNAIL_PLACEHOLDER
;
/**
* The src attribute used in the template to render the image.
...
...
@@ -51,11 +51,11 @@ export class ThumbnailComponent implements OnInit {
* If the image can't be found, use the defaultImage instead.
* If that also can't be found, use the base64 placeholder.
*/
errorHandler
(
event
)
{
if
(
event
.
currentTarget
.
src
!==
this
.
defaultImage
)
{
event
.
currentTarget
.
src
=
this
.
defaultImage
;
errorHandler
()
{
if
(
this
.
src
!==
this
.
defaultImage
)
{
this
.
src
=
this
.
defaultImage
;
}
else
{
event
.
currentTarget
.
src
=
placeholder
;
this
.
src
=
THUMBNAIL_PLACEHOLDER
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment