Skip to content

Commit

Permalink
Merge pull request #317 from pulibrary/menubar-main-menu-event
Browse files Browse the repository at this point in the history
[LuxMenuBar] Emit menu-item-clicked event even when type=main-menu
  • Loading branch information
christinach authored Aug 6, 2024
2 parents a84daa1 + 8d481ba commit 1e9a4ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/LuxMenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
:target="child.target"
:data-method="child.method"
class="lux-nav-item"
@click="menuItemClicked(child)"
>{{ child.name }}</a
>
</li>
Expand All @@ -112,6 +113,7 @@
:title="item.name"
:data-method="item.method"
class="lux-nav-item"
@click="menuItemClicked(item)"
>
{{ item.name }}
</a>
Expand Down Expand Up @@ -231,6 +233,7 @@ export default {
},
},
},
emits: ["input", "menu-item-clicked"],
}
</script>

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/specs/components/luxMenuBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,17 @@ describe("LuxMenuBar.vue", () => {
it("has the expected html structure", () => {
expect(wrapper.element).toMatchSnapshot()
})

describe("when type is main-menu", () => {
it("emits menu-item-clicked with metadata about the clicked menu item", async () => {
wrapper.setProps({ type: "main-menu" })
await nextTick()
wrapper.findAll(".lux-nav-item")[1].trigger("click")

expect(wrapper.emitted()["menu-item-clicked"].length).toEqual(1)
expect(wrapper.emitted()["menu-item-clicked"][0]).toEqual([
{ name: "Bar", component: "Bar", href: "/example/" },
])
})
})
})

0 comments on commit 1e9a4ea

Please sign in to comment.