test(img): allow datauris

This commit is contained in:
Adam Bradley
2016-12-08 15:24:27 -06:00
parent 8104cfac57
commit ad4519c2a9
3 changed files with 30 additions and 2 deletions

View File

@ -189,8 +189,14 @@ export class Img implements OnDestroy {
// update to the new src
this._src = newSrc;
// reset any existing datauri we might be holding onto
this._tmpDataUri = null;
if (newSrc.indexOf('data:') === 0) {
// they're using an actual datauri already
this._tmpDataUri = newSrc;
} else {
// reset any existing datauri we might be holding onto
this._tmpDataUri = null;
}
// run update to kick off requests or render if everything is good
this.update();

View File

@ -51,6 +51,20 @@
</ion-item>
<ion-item>
<ion-avatar item-left>
<ion-img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=="></ion-img>
</ion-avatar>
Datauri
<ion-thumbnail item-right>
<ion-img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=="></ion-img>
</ion-thumbnail>
</ion-item>
<ion-item>
<ion-thumbnail item-left>

View File

@ -42,6 +42,14 @@ describe('Img', () => {
expect(img._tmpDataUri).toEqual(null);
});
it('should set datauri src', () => {
spyOn(img, 'update');
img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
expect(img.src).toEqual('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==');
expect(img._tmpDataUri).toEqual(`data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==`);
expect(img.update).toHaveBeenCalled();
});
it('should set src', () => {
spyOn(img, 'update');
img.src = 'image.jpg';