Skip to content

Commit

Permalink
FIX: Allow title to be blank when migrating custom_header_links
Browse files Browse the repository at this point in the history
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 167bc8c
  • Loading branch information
tgxworld committed Apr 26, 2024
1 parent 167bc8c commit 54a4b3f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions migrations/settings/0002-migrate-custom-header-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 54a4b3f

Please sign in to comment.