forked from WordPress/openverse
/
v-back-to-search-results-link.spec.js
45 lines (35 loc) · 1.16 KB
/
v-back-to-search-results-link.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { createLocalVue } from "@vue/test-utils"
import { fireEvent, render } from "@testing-library/vue"
import { PiniaVuePlugin, createPinia } from "~~/test/unit/test-utils/pinia"
import { useAnalytics } from "~/composables/use-analytics"
import VBackToSearchResultsLink from "~/components/VBackToSearchResultsLink.vue"
jest.mock("~/composables/use-analytics", () => ({
useAnalytics: jest.fn(() => ({
sendCustomEvent: jest.fn(),
})),
}))
const localVue = createLocalVue()
localVue.use(PiniaVuePlugin)
describe("VBackToSearchResultsLink", () => {
it("should send analytics event when clicked", async () => {
const sendCustomEventMock = jest.fn()
useAnalytics.mockImplementation(() => ({
sendCustomEvent: sendCustomEventMock,
}))
const propsData = {
id: "123",
href: "/search",
}
const screen = render(VBackToSearchResultsLink, {
localVue,
pinia: createPinia(),
propsData,
})
const link = screen.getByText("single-result.back")
await fireEvent.click(link)
expect(sendCustomEventMock).toHaveBeenCalledWith("BACK_TO_SEARCH", {
id: propsData.id,
searchType: "all",
})
})
})