Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(IngredientAnchorLink): Use alchemy-icon setAttribute #2859

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/javascript/alchemy_admin/ingredient_anchor_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ export default class IngredientAnchorLink {
)
if (ingredientEditor) {
const icon = ingredientEditor.querySelector(
".edit-ingredient-anchor-link > a > .icon"
".edit-ingredient-anchor-link alchemy-icon"
)
icon?.classList.toggle("ri-bookmark-fill", active)
icon?.classList.toggle("ri-bookmark-line", !active)
icon.setAttribute("icon-style", active ? "fill" : "line")
}
}
}
39 changes: 39 additions & 0 deletions spec/javascript/alchemy_admin/ingredient_anchor_link.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import IngredientAnchorLink from "alchemy_admin/ingredient_anchor_link"

describe("IngredientAnchorLink", () => {
beforeEach(() => {
document.body.innerHTML = `
<div data-ingredient-id="1">
<a class="edit-ingredient-anchor-link">
<alchemy-icon icon-style="line"></alchemy-icon>
</a>
</div>
`
})

describe(".updateIcon", () => {
it("sets icon-style to fill if active", () => {
IngredientAnchorLink.updateIcon(1, true)
const icon = document.querySelector(
".edit-ingredient-anchor-link alchemy-icon"
)
expect(icon.getAttribute("icon-style")).toEqual("fill")
})

it("sets icon-style to line if not active", () => {
IngredientAnchorLink.updateIcon(1, false)
const icon = document.querySelector(
".edit-ingredient-anchor-link alchemy-icon"
)
expect(icon.getAttribute("icon-style")).toEqual("line")
})

it("does nothing if ingredient editor is not found", () => {
IngredientAnchorLink.updateIcon(2, true)
const icon = document.querySelector(
".edit-ingredient-anchor-link alchemy-icon"
)
expect(icon.getAttribute("icon-style")).toEqual("line")
})
})
})