Skip to content

Commit

Permalink
Remove arg passthrough and add unit test for v header internal
Browse files Browse the repository at this point in the history
  • Loading branch information
zackkrida committed Jun 19, 2023
1 parent 79ab281 commit 1021fa2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/VHeader/VHeaderInternal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ export default defineComponent({
deactivateFocusTrap,
})
const eventedOnTriggerClick = (...args) => {
const eventedOnTriggerClick = () => {
if (!isModalVisible.value) {
sendCustomEvent("OPEN_PAGES_MENU", {})
}
return onTriggerClick(...args)
return onTriggerClick()
}
// When clicking on an internal link in the modal, close the modal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { fireEvent } from "@testing-library/vue"

import { render } from "~~/test/unit/test-utils/render"

import { useAnalytics } from "~/composables/use-analytics"

import VHeaderInternal from "~/components/VHeader/VHeaderInternal.vue"

jest.mock("~/composables/use-analytics", () => ({
useAnalytics: jest.fn(),
}))

jest.mock("@nuxtjs/composition-api", () => {
const { ref } = require("vue")
return {
useContext: () => ({
app: {
localePath: jest.fn().mockReturnValue("/en"),
},
}),
useRoute: jest.fn().mockReturnValue(
ref({
name: "route_name__extra",
})
),
}
})

describe("VHeaderInternal", () => {
let options = null
const sendCustomEventMock = jest.fn()

beforeEach(() => {
useAnalytics.mockImplementation(() => ({
sendCustomEvent: sendCustomEventMock,
}))
options = {
stubs: ["ClientOnly"],
}
})

it("sends OPEN_PAGES_MENU analytics event when pages menu triggered", async () => {
const screen = render(VHeaderInternal, options)
const pagesMenuTrigger = screen.getByLabelText("menu")

await fireEvent.click(pagesMenuTrigger)

expect(sendCustomEventMock).toHaveBeenCalledWith("OPEN_PAGES_MENU", {})

await fireEvent.click(pagesMenuTrigger)
})
})

0 comments on commit 1021fa2

Please sign in to comment.