|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | + |
| 3 | +import { buildLegacyNewsFeed } from './legacy-news-feed' |
| 4 | + |
| 5 | +const DESKTOP_LINE_BREAK = '<br /><br />' |
| 6 | +const MOBILE_LINE_BREAK = '\n\n' |
| 7 | + |
| 8 | +/** A Ghost item shaped the way the shipped clients receive it today. */ |
| 9 | +const GHOST_FEED = (body: string) => |
| 10 | + '<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">' + |
| 11 | + '<channel>' + |
| 12 | + '<item>' + |
| 13 | + '<title><![CDATA[Fixes & tweaks <beta>]]></title>' + |
| 14 | + `<description><![CDATA[${body}]]></description>` + |
| 15 | + `<content:encoded><![CDATA[${body}]]></content:encoded>` + |
| 16 | + '</item>' + |
| 17 | + '</channel>' + |
| 18 | + '</rss>' |
| 19 | + |
| 20 | +const LIST_BODY = |
| 21 | + '<p>Fixes:</p>' + |
| 22 | + '<ul><li>High CPU usage</li>' + |
| 23 | + '<li>Endless loading, see the <a href="https://wikipedia.org/">test link</a> for details</li></ul>' |
| 24 | + |
| 25 | +const BUTTON_CARD = |
| 26 | + '<p>Fixes for high CPU usage.</p>' + |
| 27 | + '<p>Thanks for testing.</p>' + |
| 28 | + '<div class="kg-card kg-button-card kg-align-center">' + |
| 29 | + '<a href="https://status.app/" class="kg-btn kg-btn-accent">Update your Status</a>' + |
| 30 | + '</div>' |
| 31 | + |
| 32 | +describe('buildLegacyNewsFeed', () => { |
| 33 | + it('carries the call-to-action outside of any namespace', () => { |
| 34 | + const feed = buildLegacyNewsFeed(GHOST_FEED(BUTTON_CARD), MOBILE_LINE_BREAK) |
| 35 | + |
| 36 | + expect(feed).toContain('<newsLink>https://status.app/</newsLink>') |
| 37 | + expect(feed).toContain('<newsLinkLabel>Update your Status</newsLinkLabel>') |
| 38 | + expect(feed).not.toContain('xmlns:status') |
| 39 | + }) |
| 40 | + |
| 41 | + it('joins the paragraphs with the line break the feed asks for', () => { |
| 42 | + expect( |
| 43 | + buildLegacyNewsFeed(GHOST_FEED(BUTTON_CARD), DESKTOP_LINE_BREAK) |
| 44 | + ).toContain( |
| 45 | + '<description>Fixes for high CPU usage.<br /><br />Thanks for testing.</description>' |
| 46 | + ) |
| 47 | + expect( |
| 48 | + buildLegacyNewsFeed(GHOST_FEED(BUTTON_CARD), MOBILE_LINE_BREAK) |
| 49 | + ).toContain( |
| 50 | + '<description>Fixes for high CPU usage.\n\nThanks for testing.</description>' |
| 51 | + ) |
| 52 | + }) |
| 53 | + |
| 54 | + /** |
| 55 | + * The bugs below are the ones `/v2` exists to fix -- an unescaped title makes |
| 56 | + * the feed invalid XML, list items run together and the anchor label is lost. |
| 57 | + * They are locked here because the shipped clients read around them, so this |
| 58 | + * test failing means a fix has leaked into the frozen feed. |
| 59 | + */ |
| 60 | + it('reproduces what production serves, bugs included', () => { |
| 61 | + const feed = buildLegacyNewsFeed(GHOST_FEED(LIST_BODY), MOBILE_LINE_BREAK) |
| 62 | + |
| 63 | + expect(feed.slice(feed.indexOf('<item>'))).toBe( |
| 64 | + '<item>' + |
| 65 | + '<title>Fixes & tweaks <beta></title>' + |
| 66 | + '<description>Fixes:\n\nHigh CPU usageEndless loading, see the for details</description>' + |
| 67 | + '<content:encoded>Fixes:\n\nHigh CPU usageEndless loading, see the for details</content:encoded>' + |
| 68 | + '<newsLink>https://wikipedia.org/</newsLink>' + |
| 69 | + '<newsLinkLabel>test link</newsLinkLabel>' + |
| 70 | + '</item></channel></rss>' |
| 71 | + ) |
| 72 | + }) |
| 73 | + |
| 74 | + it('leaves Ghost values escaped the way they arrive', () => { |
| 75 | + const feed = buildLegacyNewsFeed( |
| 76 | + GHOST_FEED('<p>Fixes & tweaks</p>'), |
| 77 | + MOBILE_LINE_BREAK |
| 78 | + ) |
| 79 | + |
| 80 | + expect(feed).toContain('<description>Fixes & tweaks</description>') |
| 81 | + }) |
| 82 | +}) |
0 commit comments