diff --git a/ghost/announcement-bar/src/utils/api.test.js b/ghost/announcement-bar/src/utils/api.test.js new file mode 100644 index 0000000000..f4f64f373b --- /dev/null +++ b/ghost/announcement-bar/src/utils/api.test.js @@ -0,0 +1,24 @@ +import setupGhostApi from './api'; + +test('should call settings endpoint on init', () => { + jest.spyOn(window, 'fetch'); + window.fetch.mockResolvedValueOnce({ + ok: true, + json: async () => ({success: true}) + }); + + const api = setupGhostApi({apiKey: 'key', apiUrl: 'http://localhost'}); + + api.init(); + + expect(window.fetch).toHaveBeenCalledTimes(1); + expect(window.fetch).toHaveBeenCalledWith( + 'http://localhost/settings/?key=key&keys=announcement,announcement_background', + expect.objectContaining({ + method: 'GET', + headers: {'Content-Type': 'application/json'}, + credentials: undefined, + body: undefined + }), + ); +}); diff --git a/ghost/core/core/frontend/helpers/ghost_head.js b/ghost/core/core/frontend/helpers/ghost_head.js index ec24505749..bedb804261 100644 --- a/ghost/core/core/frontend/helpers/ghost_head.js +++ b/ghost/core/core/frontend/helpers/ghost_head.js @@ -88,6 +88,9 @@ function getSearchHelper(frontendKey) { } function getAnnouncementBarHelper(frontendKey) { + if (!settingsCache.get('announcement_content')) { + return ''; + } const adminUrl = urlUtils.getAdminUrl() || urlUtils.getSiteUrl(); const {scriptUrl} = getFrontendAppConfig('announcementBar'); const attrs = { diff --git a/ghost/core/test/unit/frontend/helpers/__snapshots__/ghost_head.test.js.snap b/ghost/core/test/unit/frontend/helpers/__snapshots__/ghost_head.test.js.snap index 5e865ded19..31e9fbaeb8 100644 --- a/ghost/core/test/unit/frontend/helpers/__snapshots__/ghost_head.test.js.snap +++ b/ghost/core/test/unit/frontend/helpers/__snapshots__/ghost_head.test.js.snap @@ -132,6 +132,7 @@ Object { opacity: 0.92; } + ", } @@ -275,6 +276,7 @@ Object { + ", } `; @@ -285,6 +287,7 @@ Object { + ", } `; @@ -358,6 +361,7 @@ Object { + ", } `; @@ -430,6 +434,7 @@ Object { + ", } `; @@ -822,6 +827,7 @@ Object { opacity: 0.92; } + ", } @@ -935,6 +941,7 @@ Object { opacity: 0.92; } + ", } `; @@ -1047,6 +1054,7 @@ Object { opacity: 0.92; } + ", } @@ -1160,6 +1168,7 @@ Object { opacity: 0.92; } + ", } @@ -1210,6 +1219,7 @@ Object { + ", } `; @@ -1322,6 +1332,7 @@ Object { opacity: 0.92; } + ", } @@ -1372,6 +1383,7 @@ Object { + ", } `; @@ -1385,6 +1397,7 @@ Object { + ", } `; @@ -1398,6 +1411,7 @@ Object { + ", } @@ -1412,6 +1426,7 @@ Object { + ", } @@ -1426,6 +1441,7 @@ Object { + post-codeinjection", @@ -1441,6 +1457,7 @@ Object { + ", } @@ -1525,6 +1542,7 @@ Object { + ", } `; @@ -1540,6 +1558,7 @@ Object { + ", } `; @@ -1565,6 +1584,7 @@ Object { + ", } `; @@ -1614,6 +1634,7 @@ Object { + ", } `; @@ -1626,6 +1647,7 @@ Object { + ", } `; @@ -1638,6 +1660,7 @@ Object { + ", } `; @@ -1697,6 +1720,7 @@ Object { + ", } @@ -1747,6 +1771,7 @@ Object { + ", } @@ -1769,6 +1794,7 @@ Object { + ", } `; @@ -1833,6 +1859,7 @@ Object { + ", } `; @@ -1882,6 +1909,7 @@ Object { + ", } `; @@ -1903,6 +1931,7 @@ Object { + ", } `; @@ -1915,6 +1944,7 @@ Object { + ", } `; @@ -1929,6 +1959,7 @@ Object { + ", } `; @@ -1943,6 +1974,7 @@ Object { + ", } `; @@ -1994,6 +2026,7 @@ Object { + ", } `; @@ -2043,6 +2076,7 @@ Object { + ", } `; @@ -2123,6 +2157,7 @@ Object { + ", } `; @@ -2248,6 +2283,7 @@ Object { + ", } `; @@ -2328,6 +2364,7 @@ Object { + ", } `; @@ -2408,6 +2445,7 @@ Object { + ", } `; @@ -2476,6 +2514,7 @@ Object { + ", } `; @@ -2548,6 +2587,7 @@ Object { + ", } `; @@ -2620,6 +2660,7 @@ Object { + ", } `; @@ -2692,6 +2733,7 @@ Object { + ", } `; @@ -2765,6 +2807,7 @@ Object { + ", } `; @@ -2830,6 +2873,7 @@ Object { + ", } `; @@ -2877,6 +2921,7 @@ Object { + ", } `; @@ -2928,6 +2973,7 @@ Object { + ", } `;