Skip to content

Commit

Permalink
Add test for DestinationTag
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Lerch <rlerch@redhat.com>
  • Loading branch information
ryanlerch committed Apr 13, 2023
1 parent df934b8 commit 22857d0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions frontend/src/components/DestinationTag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Contributors to the Fedora Project
//
// SPDX-License-Identifier: MIT

import { cleanup } from "@testing-library/vue";
import { afterEach, describe, expect, it, vi } from "vitest";
import DestinationTag from "./DestinationTag.vue";
import { render } from "./test-utils";
import type { Destination } from "@/api/types";

vi.mock("../auth");

describe("DestinationTag", () => {
afterEach(() => {
cleanup();
});

it("check we show the text when icononly is false", () => {
const dest: Destination = {
protocol: "irc",
address: "freednode.net",
};
const props = { destination: dest, icononly: false };
const { getByText } = render(DestinationTag, props);
expect(getByText("freednode.net")).toBeInTheDocument();
expect(getByText("irc:")).toBeInTheDocument();
});
it("check we show the text when icononly is true", () => {
const dest: Destination = {
protocol: "irc",
address: "freednode.net",
};
const props = { destination: dest, icononly: true };
const { queryByText } = render(DestinationTag, props);
expect(queryByText("freednode.net")).toBeNull();
expect(queryByText("irc:")).toBeNull();
});
});
7 changes: 6 additions & 1 deletion frontend/src/components/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Component } from "vue";
import { createI18n } from "vue-i18n";
import router from "../router";
import { vi } from "vitest";
import type { Destination } from "@/api/types";

export const loginUser = (userStore: ReturnType<typeof useUserStore>) => {
userStore.$patch({
Expand All @@ -29,7 +30,10 @@ export const loginAdmin = (userStore: ReturnType<typeof useUserStore>) => {
});
};

export const render = (component: Component) => {
export const render = (
component: Component,
props?: Record<string, boolean | Destination>
) => {
const pinia = getActivePinia() as Pinia;
const i18n = createI18n({
legacy: false,
Expand All @@ -38,6 +42,7 @@ export const render = (component: Component) => {
messages: {},
});
return baseRender(component, {
props: props,
global: {
plugins: [router, pinia, i18n],
provide: {
Expand Down

0 comments on commit 22857d0

Please sign in to comment.