FIX: Missing category badge for category with color stored as 3-digit hex code (#18579)

On the server side, the only limitation for `Category#color` is a length
limit of 6. Therefore, we cannot assume on the client side that the hex
code is always 6 digits.
This commit is contained in:
Alan Guo Xiang Tan 2022-10-13 17:00:46 +08:00 committed by GitHub
parent 7e94fa86d7
commit c16cb0e00b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -53,11 +53,13 @@ export default class SectionLink extends Component {
get prefixElementColors() {
const prefixElementColors = this.args.prefixElementColors.filter((color) =>
color?.match(/^\w{6}$/)
color?.slice(0, 6)
);
if (prefixElementColors.length === 1) {
prefixElementColors.push(prefixElementColors[0]);
}
return prefixElementColors.map((color) => `#${color} 50%`).join(", ");
}
}

View File

@ -291,6 +291,20 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
);
});
test("category section link for category with 3-digit hex code for color", async function (assert) {
const { category1 } = setupUserSidebarCategories();
category1.set("color", "888");
await visit("/");
assert.ok(
exists(
`.sidebar-section-link-${category1.slug} .sidebar-section-link-prefix .prefix-span[style="background: linear-gradient(90deg, #888 50%, #888 50%)"]`
),
"category1 section link is rendered with the right solid prefix icon color"
);
});
test("category section link have the right title", async function (assert) {
const categories = Site.current().categories;