Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #50 from Financial-Times/add-video-modifier
Browse files Browse the repository at this point in the history
Add 'type' of content as a modifier
  • Loading branch information
ironsidevsquincy authored Dec 8, 2016
2 parents e31f947 + e045fc9 commit dd9ea9c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/presenters/teaser-presenter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const hyphenatePascalCase = require('../utils/hyphenate-pascal-case');

const ONE_HOUR = 1000 * 60 * 60;
const MAX_RELATED_CONTENT = 3;
const HEADSHOT_BASE_URL = 'https://www.ft.com/__origami/service/image/v2/images/raw/';
Expand Down Expand Up @@ -51,6 +53,9 @@ const TeaserPresenter = class TeaserPresenter {
if (this.data.isEditorsChoice) {
mods.push('highlight');
}
if (this.data.type) {
mods.push(hyphenatePascalCase(this.data.type));
}
return mods;
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils/hyphenate-pascal-case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = value => {
return value.replace(/([a-z])([A-Z])/g, '$1-$2')
.toLowerCase();
};
24 changes: 22 additions & 2 deletions tests/presenters/teaser-presenter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ describe('Teaser Presenter', () => {
it('returns has-headshot when correct template and has-headshot', () => {
const content = Object.assign({}, articleOpinionAuthorFixture, {template: 'standard'});
subject = new Presenter(content);
expect(subject.classModifiers).to.deep.equal(['has-headshot']);
expect(subject.classModifiers).to.include('has-headshot');
});

it('does not add a modifier if wrong template but has headshot', () => {
const content = Object.assign({}, articleOpinionAuthorFixture, {template: 'no-headshot'});
subject = new Presenter(content);
expect(subject.classModifiers.length).to.equal(0);
expect(subject.classModifiers).to.not.include('has-headshot');
});

it('does not add a modifier if correct template but does not have a headshot', () => {
Expand Down Expand Up @@ -98,6 +98,26 @@ describe('Teaser Presenter', () => {
});
});

context('type', () => {
it('returns `article` when content has `type` set to `Article`', () => {
const content = {type: 'Article'};
subject = new Presenter(content);
expect(subject.classModifiers).to.deep.equal(['article']);
});

it('returns `video` when content has `type` set to `Video`', () => {
const content = {type: 'Video'};
subject = new Presenter(content);
expect(subject.classModifiers).to.deep.equal(['video']);
});

it('returns `live-blog` when content has `type` set to `LiveBlog`', () => {
const content = {type: 'LiveBlog'};
subject = new Presenter(content);
expect(subject.classModifiers).to.deep.equal(['live-blog']);
});
});

});

context('displayTag', () => {
Expand Down
23 changes: 23 additions & 0 deletions tests/utils/hyphenate-pascal-case.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('chai').should();

const hyphenatePascalCase = require('../../src/utils/hyphenate-pascal-case');

describe('Utils', () => {

describe('Hyphenate Pascal Case', () => {

it('should exist', () => {
hyphenatePascalCase.should.exist;
});

it('should hyphenate pascal case, e.g. `FooBar` to `foo-bar`', () => {
hyphenatePascalCase('FooBar').should.equal('foo-bar');
});

it('should handle a single ‘word’', () => {
hyphenatePascalCase('Foo').should.equal('foo');
});

});

});

0 comments on commit dd9ea9c

Please sign in to comment.