FIX: Allow title to be blank when migrating `custom_header_links` (#56)

This commit allows setting value of `Link Name, ,/some/path` to be
migrated. This format of the setting was allowed and the current
migration will not migrate the link if the title is empty which isn't
what we want.

Follows-up to 167bc8cee9
This commit is contained in:
Alan Guo Xiang Tan 2024-04-26 15:46:20 +08:00 committed by GitHub
parent 167bc8cee9
commit 4cc2a57c21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View File

@ -16,13 +16,16 @@ export default function migrate(settings) {
.split(",") .split(",")
.map((s) => s.trim()); .map((s) => s.trim());
if (text && title && url) { if (text && url) {
const newLink = { const newLink = {
text, text,
title,
url, url,
}; };
if (title) {
newLink.title = title;
}
if (["vdm", "vdo", "vmo"].includes(view)) { if (["vdm", "vdo", "vmo"].includes(view)) {
newLink.view = view; newLink.view = view;
} else { } else {

View File

@ -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) { test("migrate", function (assert) {
const settings = new Map( const settings = new Map(
Object.entries({ Object.entries({