Skip to content
Snippets Groups Projects
Commit 9e5071e0 authored by Albert (AJ) St. Aubin's avatar Albert (AJ) St. Aubin
Browse files

[MICROBA-746] Improve this code to check for the availability of banner_images

parent e49e899f
No related branches found
No related tags found
No related merge requests found
......@@ -12,9 +12,9 @@ class ProgramModel extends Backbone.Model {
subtitle: data.subtitle,
authoring_organizations: data.authoring_organizations,
detailUrl: data.detail_url,
xsmallBannerUrl: data.banner_image['x-small'].url,
smallBannerUrl: data.banner_image.small.url,
mediumBannerUrl: data.banner_image.medium.url,
xsmallBannerUrl: (data.banner_image && data.banner_image['x-small']) ? data.banner_image['x-small'].url : '',
smallBannerUrl: (data.banner_image && data.banner_image.small) ? data.banner_image.small.url : '',
mediumBannerUrl: (data.banner_image && data.banner_image.medium) ? data.banner_image.medium.url : '',
breakpoints: {
max: {
xsmall: '320px',
......
......@@ -88,6 +88,7 @@ describe('Program card View', () => {
it('should load the program-card based on passed in context', () => {
cardRenders(view.$el);
expect(view.$el.find('.banner-image').attr('srcset')).toEqual(program.banner_image.small.url);
});
it('should call reEvaluatePicture if reLoadBannerImage is called', () => {
......@@ -127,4 +128,32 @@ describe('Program card View', () => {
cardRenders(view.$el);
expect(view.$('.progress').length).toEqual(0);
});
it('should render cards if there are missing banner images', () => {
view.remove();
const programNoBanner = JSON.parse(JSON.stringify(program));
delete programNoBanner.banner_image;
programModel = new ProgramModel(programNoBanner);
view = new ProgramCardView({
model: programModel,
context: {},
});
cardRenders(view.$el);
expect(view.$el.find('.banner-image').attr('srcset')).toEqual('');
});
it('should render cards if there are missing banner image sizes', () => {
view.remove();
const programNoBanner = JSON.parse(JSON.stringify(program));
delete programNoBanner.banner_image['x-small'];
delete programNoBanner.banner_image.small;
programModel = new ProgramModel(programNoBanner);
view = new ProgramCardView({
model: programModel,
context: {},
});
cardRenders(view.$el);
expect(view.$el.find('.banner-image').attr('srcset')).toEqual('');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment