diff --git a/migrations/settings/0002-migrate-custom-header-links.js b/migrations/settings/0002-migrate-custom-header-links.js index 46648f0..63d5421 100644 --- a/migrations/settings/0002-migrate-custom-header-links.js +++ b/migrations/settings/0002-migrate-custom-header-links.js @@ -16,13 +16,16 @@ export default function migrate(settings) { .split(",") .map((s) => s.trim()); - if (text && title && url) { + if (text && url) { const newLink = { text, - title, url, }; + if (title) { + newLink.title = title; + } + if (["vdm", "vdo", "vmo"].includes(view)) { newLink.view = view; } else { diff --git a/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js b/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js index bde6ef1..ac71c72 100644 --- a/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js +++ b/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js @@ -156,6 +156,35 @@ module( ); }); + test("migrate when title is not provided", function (assert) { + const settings = new Map( + Object.entries({ + custom_header_links: "External link, , https://meta.discourse.org", + }) + ); + + const result = migrate(settings); + + const expectedResult = new Map( + Object.entries({ + custom_header_links: [ + { + text: "External link", + url: "https://meta.discourse.org", + view: "vdm", + target: "blank", + hide_on_scroll: "keep", + }, + ], + }) + ); + + assert.deepEqual( + Object.fromEntries(result.entries()), + Object.fromEntries(expectedResult.entries()) + ); + }); + test("migrate", function (assert) { const settings = new Map( Object.entries({