diff --git a/core/frontend/helpers/comments.js b/core/frontend/helpers/comments.js index 15628f1d3b..75142a0471 100644 --- a/core/frontend/helpers/comments.js +++ b/core/frontend/helpers/comments.js @@ -20,6 +20,11 @@ async function comments(options) { avatarSaturation = 50; } + let accentColor = ''; + if (options.data.site.accent_color) { + accentColor = options.data.site.accent_color; + } + const frontendKey = await getFrontendKey(); const data = { @@ -30,7 +35,8 @@ async function comments(options) { 'post-id': this.id, 'sentry-dsn': '', /* todo: insert sentry dsn key here */ 'color-scheme': colorScheme, - 'avatar-saturation': avatarSaturation + 'avatar-saturation': avatarSaturation, + 'accent-color': accentColor }; let dataAttributes = ''; diff --git a/test/unit/frontend/helpers/comments.test.js b/test/unit/frontend/helpers/comments.test.js new file mode 100644 index 0000000000..ad0567223a --- /dev/null +++ b/test/unit/frontend/helpers/comments.test.js @@ -0,0 +1,58 @@ +const should = require('should'); +const sinon = require('sinon'); +const configUtils = require('../../../utils/configUtils'); +const {mockManager} = require('../../../utils/e2e-framework'); + +const comments = require('../../../../core/frontend/helpers/comments'); +const proxy = require('../../../../core/frontend/services/proxy'); +const {settingsCache} = proxy; + +describe('{{comments}} helper', function () { + let keyStub; + + before(function () { + keyStub = sinon.stub().resolves('xyz'); + const dataService = { + getFrontendKey: keyStub + }; + proxy.init({dataService}); + }); + + beforeEach(function () { + mockManager.mockMail(); + mockManager.mockLabsEnabled('comments'); + sinon.stub(settingsCache, 'get'); + }); + + afterEach(function () { + mockManager.restore(); + sinon.restore(); + configUtils.restore(); + }); + + it('returns undefined if not used withing post context', function (done) { + settingsCache.get.withArgs('members_enabled').returns(true); + + comments({}).then(function (rendered) { + should.not.exist(rendered); + done(); + }).catch(done); + }); + + it('returns a script tag', async function () { + settingsCache.get.withArgs('members_enabled').returns(true); + + const rendered = await comments.call({ + comment_id: 'post_test', + id: 'post_id_123' + }, { + hash: {}, + data: { + site: {} + } + }); + should.exist(rendered); + rendered.string.should.containEql('