Skip to content

Commit

Permalink
Merge pull request #81 from Financial-Times/rich_articles-not-article
Browse files Browse the repository at this point in the history
ACC-544 rich_articles not rich article
  • Loading branch information
tolujimoh authored Oct 29, 2020
2 parents be4e8a4 + b9d29ca commit 183d076
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
38 changes: 29 additions & 9 deletions src/js/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,50 @@ export function getMessage (item, {MAINTENANCE_MODE, contributor_content}) {
return interpolate(message, item);
}

export function getAdditionalMessages (item, user) {
const richContentMessages = richContentMessage(item, user);

return richContentMessages
.map(messageTemplate)
.join('');
}

export function richContentMessage (
{ hasGraphics = false, canAllGraphicsBeSyndicated = false } = {},
{ download_format = 'plain', allowed = {} } = {}
) {

const messagesContent = [];

if (allowed.rich_article) {
if (allowed.rich_articles) {
if (hasGraphics && !canAllGraphicsBeSyndicated) {
messagesContent.push({
messageType: 'neutral',
message: MESSAGES.GRAPHICS,
});
}

//Nested condition because only required if first condition true
if (download_format && download_format !== 'docx') {

messagesContent.push({
messageType: 'error',
message: MESSAGES.WORD_FORMAT,
});
}
if (hasGraphics && download_format !== 'docx') {
messagesContent.push({
messageType: 'error',
message: MESSAGES.WORD_FORMAT,
});
}

}

return messagesContent;
}

function messageTemplate ({ messageType = 'neutral', message = '' }) {

return `<div class="o-message o-message--alert o-message--${messageType} n-syndication-rich-content-message" data-o-component="o-message">
<div class="o-message__container">
<div class="o-message__content">
<p class="o-message__content-main">
<span class="o-message__content-highlight n-syndication-rich-message_content-highlight">${message}</span>
</p>
</div>
</div>
</div>`;
}
31 changes: 2 additions & 29 deletions src/js/modal-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {TRACKING} from './config';

import {toElement} from './util';
import {getAllItemsForID, getItemByHTMLElement} from './data-store';
import {getMessage, richContentMessage } from './messages';
import {getMessage, getAdditionalMessages } from './messages';

const MAX_LOCAL_FORMAT_TIME_MS = 300000;
const localStore = new Superstore('local', 'syndication');
Expand Down Expand Up @@ -171,7 +171,7 @@ function createElement (item) {
<div class="n-syndication-modal-message">
${getMessage(item, USER_DATA)}
</div>
${richContentWarnings (item)}
${getAdditionalMessages (item, USER_DATA)}
<div class="n-syndication-actions" data-content-id="${item.id}" data-iso-lang="${item.lang}">
<a class="n-syndication-action" data-action="save" ${disableSaveButton ? 'disabled' : ''} data-trackable="${saveTrackingId}" href="${saveHref}">${saveText}</a>
<a class="n-syndication-action n-syndication-action-primary" data-action="download" ${disableDownloadButton ? 'disabled' : ''} ${downloadTrackingId ? `data-trackable="${downloadTrackingId}"` : ''} href="${downloadHref}">${downloadText}</a>
Expand Down Expand Up @@ -301,33 +301,6 @@ function visible () {
return !!(OVERLAY_MODAL_ELEMENT && document.body.contains(OVERLAY_MODAL_ELEMENT));
}

function messageTemplate (messageType = 'neutral', messageText) {

return `<div class="o-message o-message--alert o-message--${messageType} n-syndication-rich-content-message" data-o-component="o-message">
<div class="o-message__container">
<div class="o-message__content">
<p class="o-message__content-main">
<span class="o-message__content-highlight n-syndication-rich-message_content-highlight">${messageText}</span>
</p>
</div>
</div>
</div>`;
}

function richContentWarnings (item) {
const theMessages = richContentMessage(item, USER_DATA);

if (theMessages.length === -1) {
return null;
}

const richContentWarningsMessages = theMessages
.map((message) => messageTemplate(message.messageType, message.message))
.join('');

return richContentWarningsMessages;
}


export {
init
Expand Down
14 changes: 13 additions & 1 deletion test/src/js/messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('messages', () => {
const msg2 = { messageType: 'error', message: MESSAGES.WORD_FORMAT };

beforeEach(() => {
userStatusFixture.allowed.rich_article = true;
userStatusFixture.allowed.rich_articles = true;
});

it('returns an empty string if item does not have graphics', () => {
Expand Down Expand Up @@ -91,5 +91,17 @@ describe('messages', () => {
expect(richContentMsg[0]).toEqual(msg1);
expect(richContentMsg[1]).toEqual(msg2);
});

it('returns a string of HTML that contains the graphics unavailable message AND the word format message if hasGraphics is TRUE and canAllGraphicsBeSyndicated is TRUE and download_format is NOT docx', () => {
const items = Object.assign({}, itemsFixture, { hasGraphics: true, canAllGraphicsBeSyndicated: true });
const userStatus = Object.assign({}, userStatusFixture, {
download_format: 'plain',
});
const richContentMsg = richContentMessage(items, userStatus);

expect(Array.isArray(richContentMsg)).toBe(true);
expect(richContentMsg.length).toBe(1);
expect(richContentMsg[0]).toEqual(msg2);
});
});
});

0 comments on commit 183d076

Please sign in to comment.