-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
256 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
frontend/test/unit/specs/components/VHeader/v-header-desktop.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { fireEvent } from "@testing-library/vue" | ||
|
||
import { ref } from "vue" | ||
|
||
import { render } from "~~/test/unit/test-utils/render" | ||
|
||
import { useAnalytics } from "~/composables/use-analytics" | ||
|
||
import { IsHeaderScrolledKey, IsSidebarVisibleKey } from "~/types/provides" | ||
|
||
import VHeaderDesktop from "~/components/VHeader/VHeaderDesktop.vue" | ||
|
||
jest.mock("~/composables/use-analytics", () => ({ | ||
useAnalytics: jest.fn(), | ||
})) | ||
jest.mock("~/composables/use-match-routes", () => ({ | ||
// mocking `Ref<boolean>` as `{ value: boolean }` | ||
useMatchSearchRoutes: jest.fn(() => ({ matches: { value: true } })), | ||
})) | ||
|
||
describe("VHeaderDesktop", () => { | ||
const routerMock = { push: jest.fn() } | ||
const sendCustomEventMock = jest.fn() | ||
window.scrollTo = jest.fn() | ||
|
||
let options = null | ||
|
||
beforeEach(() => { | ||
useAnalytics.mockImplementation(() => ({ | ||
sendCustomEvent: sendCustomEventMock, | ||
})) | ||
options = { | ||
mocks: { $router: routerMock }, | ||
stubs: ["ClientOnly"], | ||
provide: { | ||
[IsHeaderScrolledKey]: ref(false), | ||
[IsSidebarVisibleKey]: ref(false), | ||
}, | ||
} | ||
}) | ||
it("sends SUBMIT_SEARCH analytics event when submitted", async () => { | ||
const screen = render(VHeaderDesktop, options) | ||
const input = screen.getByRole("combobox") | ||
|
||
await fireEvent.update(input, "cat") | ||
await fireEvent.submit(input) | ||
|
||
expect(sendCustomEventMock).toHaveBeenCalledWith("SUBMIT_SEARCH", { | ||
query: "cat", | ||
searchType: "all", | ||
}) | ||
}) | ||
}) |
52 changes: 52 additions & 0 deletions
52
frontend/test/unit/specs/components/VHeader/v-header-mobile.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { fireEvent } from "@testing-library/vue" | ||
import { ref } from "vue" | ||
|
||
import { render } from "~~/test/unit/test-utils/render" | ||
|
||
import { useAnalytics } from "~/composables/use-analytics" | ||
|
||
import { IsHeaderScrolledKey, IsSidebarVisibleKey } from "~/types/provides" | ||
|
||
import VHeaderMobile from "~/components/VHeader/VHeaderMobile/VHeaderMobile.vue" | ||
|
||
jest.mock("~/composables/use-analytics", () => ({ | ||
useAnalytics: jest.fn(), | ||
})) | ||
jest.mock("~/composables/use-match-routes", () => ({ | ||
// mocking `Ref<boolean>` as `{ value: boolean }` | ||
useMatchSearchRoutes: jest.fn(() => ({ matches: { value: true } })), | ||
})) | ||
|
||
describe("VHeaderMobile", () => { | ||
const routerMock = { push: jest.fn() } | ||
const sendCustomEventMock = jest.fn() | ||
useAnalytics.mockImplementation(() => ({ | ||
sendCustomEvent: sendCustomEventMock, | ||
})) | ||
window.scrollTo = jest.fn() | ||
|
||
let options = null | ||
|
||
beforeEach(() => { | ||
options = { | ||
mocks: { $router: routerMock }, | ||
stubs: ["ClientOnly"], | ||
provide: { | ||
[IsHeaderScrolledKey]: ref(false), | ||
[IsSidebarVisibleKey]: ref(false), | ||
}, | ||
} | ||
}) | ||
it("sends SUBMIT_SEARCH analytics event when submitted", async () => { | ||
const screen = render(VHeaderMobile, options) | ||
const input = screen.getByRole("combobox") | ||
|
||
await fireEvent.update(input, "cat") | ||
await fireEvent.submit(input) | ||
|
||
expect(sendCustomEventMock).toHaveBeenCalledWith("SUBMIT_SEARCH", { | ||
query: "cat", | ||
searchType: "all", | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { fireEvent, screen } from "@testing-library/vue" | ||
|
||
import { render } from "~~/test/unit/test-utils/render" | ||
|
||
import { useAnalytics } from "~/composables/use-analytics" | ||
|
||
import VFourOhFour from "~/components/VFourOhFour.vue" | ||
|
||
jest.mock("~/composables/use-analytics", () => ({ | ||
useAnalytics: jest.fn(), | ||
})) | ||
describe("VFourOhFour", () => { | ||
let options | ||
const sendCustomEventMock = jest.fn() | ||
useAnalytics.mockImplementation(() => ({ | ||
sendCustomEvent: sendCustomEventMock, | ||
})) | ||
const query = "cat" | ||
beforeEach(() => { | ||
options = { | ||
mocks: { $router: { push: jest.fn() } }, | ||
} | ||
}) | ||
|
||
it("should send SUBMIT_SEARCH analytics event when search submitted", async () => { | ||
render(VFourOhFour, options) | ||
|
||
const input = screen.getByRole("searchbox") | ||
await fireEvent.update(input, query) | ||
await fireEvent.submit(input) | ||
|
||
expect(sendCustomEventMock).toHaveBeenCalledWith("SUBMIT_SEARCH", { | ||
query, | ||
searchType: "all", | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { fireEvent, screen } from "@testing-library/vue" | ||
|
||
import { render } from "~~/test/unit/test-utils/render" | ||
|
||
import IndexPage from "~/pages/index.vue" | ||
|
||
import { useAnalytics } from "~/composables/use-analytics" | ||
|
||
jest.mock("~/composables/use-analytics", () => ({ | ||
useAnalytics: jest.fn(), | ||
})) | ||
describe("IndexPage", () => { | ||
let options | ||
const sendCustomEventMock = jest.fn() | ||
useAnalytics.mockImplementation(() => ({ | ||
sendCustomEvent: sendCustomEventMock, | ||
})) | ||
const query = "cat" | ||
beforeEach(() => { | ||
options = { | ||
mocks: { $router: { push: jest.fn() } }, | ||
stubs: ["VHomeGallery"], | ||
} | ||
}) | ||
|
||
it("should send SUBMIT_SEARCH analytics event when search submitted", async () => { | ||
render(IndexPage, options) | ||
|
||
const input = screen.getByRole("searchbox") | ||
await fireEvent.update(input, query) | ||
await fireEvent.submit(input) | ||
|
||
expect(sendCustomEventMock).toHaveBeenCalledWith("SUBMIT_SEARCH", { | ||
query, | ||
searchType: "all", | ||
}) | ||
}) | ||
|
||
it("should send SUBMIT_SEARCH analytics event with correct mediaType when search submitted", async () => { | ||
render(IndexPage, options) | ||
|
||
const button = screen.getByRole("button", { | ||
name: "Select a content type: All content", | ||
}) | ||
await fireEvent.click(button) | ||
|
||
const audio = screen.getByRole("radio", { name: "Audio" }) | ||
await fireEvent.click(audio) | ||
|
||
const input = screen.getByRole("searchbox") | ||
await fireEvent.update(input, query) | ||
await fireEvent.submit(input) | ||
|
||
expect(sendCustomEventMock).toHaveBeenCalledWith("SUBMIT_SEARCH", { | ||
query, | ||
searchType: "audio", | ||
}) | ||
}) | ||
}) |