Skip to content

Commit

Permalink
studio - unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janavlachova committed Jan 12, 2025
1 parent f0e2f12 commit 780041e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 99 deletions.
17 changes: 14 additions & 3 deletions agdb_studio/src/components/base/menu/AgdbMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ import { describe, beforeEach, vi, it, expect } from "vitest";
import { mount } from "@vue/test-utils";
import AgdbMenu from "./AgdbMenu.vue";
import { dbActions } from "@/composables/db/dbConfig";
import { db_backup } from "@/tests/apiMock";

describe("AgdbMenu", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("should run action on click", () => {
const actionMock = vi.fn();
const wrapper = mount(AgdbMenu, {
props: {
actions: dbActions,
actions: [
{
key: "convert",
label: "Convert",
action: vi.fn(),
},
{
key: "backup",
label: "Backup",
action: actionMock,
},
],
},
});

Expand All @@ -20,7 +31,7 @@ describe("AgdbMenu", () => {

const backup = wrapper.find(".menu-item[data-key='backup']");
backup.trigger("click");
expect(db_backup).toHaveBeenCalled();
expect(actionMock).toHaveBeenCalled();
});

it("should render the sub menu on hover", async () => {
Expand Down
85 changes: 0 additions & 85 deletions agdb_studio/src/components/notification/NotificationViewer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { mount } from "@vue/test-utils";
import { describe, beforeEach, vi, it, expect } from "vitest";
import NotificationViewer from "./NotificationViewer.vue";
import { ref } from "vue";
import * as notificationStore from "@/composables/notification/notificationStore";

// vi.mock("@/composables/notification/notificationStore");

// const toggleViewerOpenedMock = vi.mocked(toggleViewerOpened);
// const closeViewerMock = vi.mocked(closeViewer);
// const clearNotificationsMock = vi.mocked(clearNotifications);

// const notificationsReversedMock = vi.mocked(notificationsReversed);
// const newNotificationsMock = vi.mocked(newNotifications);
// const viewerOpenedMock = vi.mocked(viewerOpened);
// const hasUnreadNotificationsMock = vi.mocked(hasUnreadNotifications);

const toggleViewerOpenedMock = vi.spyOn(
notificationStore,
"toggleViewerOpened",
Expand All @@ -24,79 +12,6 @@ const clearNotificationsMock = vi.spyOn(
notificationStore,
"clearNotifications",
);

// notificationsReversedMock.value = [
// {
// id: "testId",
// type: "info",
// title: "Test",
// message: "This is a test notification",
// timestamp: Date.now(),
// },
// ];

// const {
// closeViewer,
// clearNotifications,
// toggleViewerOpened,
// notificationsReversed,
// newNotifications,
// hasUnreadNotifications,
// viewerOpened,
// } = vi.hoisted(() => {
// return {
// closeViewer: vi.fn(),
// clearNotifications: vi.fn(),
// toggleViewerOpened: vi.fn(),
// notificationsReversed: [
// {
// id: "testId",
// type: "info",
// title: "Test",
// message: "This is a test notification",
// timestamp: Date.now(),
// },
// ],
// newNotifications: {
// value: [
// {
// id: "testId2",
// type: "info",
// title: "Test2",
// message: "This is a test notification 2",
// timestamp: Date.now(),
// },
// ],
// },
// hasUnreadNotifications: { value: false },
// viewerOpened: { value: true },
// };
// });

// vi.mock("@/composables/notification/notificationStore", () => {
// return {
// notificationsReversed,
// newNotifications,
// hasUnreadNotifications,
// viewerOpened,
// // notificationsReversed: ref([
// // {
// // id: "testId",
// // type: "info",
// // title: "Test",
// // message: "This is a test notification",
// // timestamp: Date.now(),
// // },
// // ]),
// // newNotifications: ref([]),
// // hasUnreadNotifications: ref(false),
// // viewerOpened: ref(false),
// toggleViewerOpened,
// clearNotifications,
// closeViewer,
// };
// });

const testNotifications: notificationStore.AddNotificationProps[] = [
{
type: "info",
Expand Down
1 change: 1 addition & 0 deletions agdb_studio/src/composables/db/dbConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const dbActions: Action[] = [
label: "Backup",
action: ({ params }: DbActionProps) =>
client.value?.db_backup(params).then(() => {
console.log("Backup created", params);
addNotification({
type: "success",
title: "Backup created",
Expand Down
22 changes: 11 additions & 11 deletions agdb_studio/src/tests/apiMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ export const get_token = vi.fn();
export const user_status = vi.fn();
export const db_list = vi.fn();
export const db_add = vi.fn();
export const db_backup = vi.fn();
export const db_restore = vi.fn();
export const db_clear = vi.fn();
export const db_convert = vi.fn();
export const db_remove = vi.fn();
export const db_delete = vi.fn();
export const db_optimize = vi.fn();
export const db_backup = vi.fn().mockResolvedValue({});
export const db_restore = vi.fn().mockResolvedValue({});
export const db_clear = vi.fn().mockResolvedValue({});
export const db_convert = vi.fn().mockResolvedValue({});
export const db_remove = vi.fn().mockResolvedValue({});
export const db_delete = vi.fn().mockResolvedValue({});
export const db_optimize = vi.fn().mockResolvedValue({});
export const db_audit = vi.fn().mockResolvedValue({ data: [] });
export const db_copy = vi.fn();
export const db_rename = vi.fn();
export const db_copy = vi.fn().mockResolvedValue({});
export const db_rename = vi.fn().mockResolvedValue({});
export const db_user_list = vi.fn();
export const db_user_add = vi.fn();
export const db_user_remove = vi.fn();
export const db_user_add = vi.fn().mockResolvedValue({});
export const db_user_remove = vi.fn().mockResolvedValue({});

export const client = vi.fn().mockResolvedValue({
login: vi.fn().mockResolvedValue("token"),
Expand Down

0 comments on commit 780041e

Please sign in to comment.