generated from PrivateAIM/typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 1
325 add unit tests for event viewer #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3a216c
feat: update event filtering and bind to meter group
brucetony d237fb0
test: fix unit tests and imports
brucetony c733a9c
test: limit TZ check to date
brucetony 05610d2
test: add suggested fixes
brucetony a7ae8e8
test: add suggested fixes
brucetony File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { flushPromises, mount } from "@vue/test-utils"; | ||
| import DateFilterGraph from "~/components/events/DateFilterGraph.vue"; | ||
| import { fakeEventResponse } from "~/test/components/events/constants"; | ||
|
|
||
| vi.mock("#app", () => ({ | ||
| useNuxtApp: () => ({ | ||
| $hubApi: vi.fn().mockResolvedValue(fakeEventResponse), | ||
| }), | ||
| })); | ||
|
|
||
| describe("DateFilterGraph.vue", () => { | ||
| it("Show event count", () => { | ||
| const wrapper = mount(DateFilterGraph, { | ||
| props: { eventCount: 2 }, | ||
| }); | ||
|
|
||
| expect(wrapper.text()).toContain("Event Viewer"); | ||
| expect(wrapper.html()).toContain("2 events"); | ||
| }); | ||
|
|
||
| it("Shows singular form when eventCount is 1", () => { | ||
| const wrapper = mount(DateFilterGraph, { | ||
| props: { eventCount: 1 }, | ||
| }); | ||
|
|
||
| expect(wrapper.html()).toContain("1 event"); | ||
| }); | ||
|
|
||
| it("Emits showRequestedEvents when submit clicked", async () => { | ||
| const wrapper = mount(DateFilterGraph, { props: { eventCount: 1 } }); | ||
|
|
||
| const submit = wrapper.find(".custom-date-filter-submit-btn button"); | ||
| expect(submit.exists()).toBe(true); | ||
| await submit.trigger("click"); | ||
| await flushPromises(); | ||
|
|
||
| expect(wrapper.emitted("showRequestedEvents")).toHaveLength(1); | ||
| }); | ||
| }); |
This file contains hidden or 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,84 @@ | ||
| import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { flushPromises, mount } from "@vue/test-utils"; | ||
| import EventViewer from "~/components/events/EventViewer.vue"; | ||
| import { type DefineComponent, defineComponent } from "vue"; | ||
| import { fakeEventResponse } from "~/test/components/events/constants"; | ||
| import { getEvents } from "~/composables/useAPIFetch"; | ||
| import type { EventLogResponse } from "~/services/Api"; | ||
|
|
||
| vi.mock("~/composables/useAPIFetch", () => ({ | ||
| getEvents: vi.fn(), | ||
| })); | ||
|
|
||
| describe("EventViewer.vue", () => { | ||
| let EventViewerComponent: DefineComponent<typeof EventViewer>; | ||
|
|
||
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| // Render the component with the fake params | ||
| beforeAll(async () => { | ||
| EventViewerComponent = defineComponent({ | ||
| components: { EventViewer }, | ||
| template: "<Suspense><EventViewer/></Suspense>", | ||
| }); | ||
| }); | ||
|
|
||
| it("Loads events into table", async () => { | ||
| vi.mocked(getEvents).mockResolvedValue({ | ||
| data: ref(fakeEventResponse), | ||
| pending: ref(false), | ||
| error: ref(null), | ||
| status: ref("success"), | ||
| refresh: vi.fn(), | ||
| execute: vi.fn(), | ||
| clear: vi.fn(), | ||
| }); | ||
|
|
||
| const wrapper = mount(EventViewerComponent); | ||
|
|
||
| // Wait for async setup to resolve | ||
| await flushPromises(); | ||
| expect(wrapper.text()).toContain("Event Viewer"); // Title of the page | ||
| expect(wrapper.text()).toContain("1 event"); | ||
|
|
||
| // Find header and check content | ||
| const headerRow = wrapper.findAll("thead tr th"); | ||
| expect(headerRow[0].text()).toBe("DateTime"); // First col | ||
| expect(headerRow[1].text()).toBe("Event"); // Second col | ||
|
|
||
| // Find row and check content | ||
| const rows = wrapper.findAll("tbody tr"); | ||
| expect(rows.length).toBe(1); | ||
|
|
||
| const rowCells = rows[0].findAll("td"); | ||
| expect(rowCells[0].text()).toContain("2/19/26"); // Datetime, limit to date due to TZ issues in runner | ||
| expect(rowCells[1].text()).toBe( | ||
| "NODE-SETTINGS-GET-SUCCESSHub AdapterNodeInfoA user fetched the node's configurations settings", | ||
| ); | ||
| }); | ||
|
|
||
| it("No events in response", async () => { | ||
| vi.mocked(getEvents).mockResolvedValue({ | ||
| data: ref<EventLogResponse>({ | ||
| data: [], | ||
| meta: { count: 0, total: 0, limit: 0, offset: 0 }, | ||
| }), | ||
| pending: ref(false), | ||
| error: ref(null), | ||
| status: ref("success"), | ||
| refresh: vi.fn(), | ||
| execute: vi.fn(), | ||
| clear: vi.fn(), | ||
| }); | ||
|
|
||
| const wrapper = mount(EventViewerComponent); | ||
|
|
||
| // Wait for async setup to resolve | ||
| await flushPromises(); | ||
|
|
||
| expect(wrapper.text()).toContain("No events found"); | ||
| expect(wrapper.text()).toContain("0 events"); | ||
| }); | ||
| }); |
This file contains hidden or 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,18 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { mount } from "@vue/test-utils"; | ||
| import TagFilterSidePanel from "~/components/events/TagFilterSidePanel.vue"; | ||
|
|
||
| describe("TagFilterSidePanel.vue", () => { | ||
| it("renders categories and emits clearTagFilter when clear button clicked", async () => { | ||
| const wrapper = mount(TagFilterSidePanel); | ||
|
|
||
| // The menu has the two categories | ||
| expect(wrapper.text()).toContain("Services"); | ||
| expect(wrapper.text()).toContain("Log Level"); | ||
|
|
||
| const button = wrapper.find("button"); | ||
| await button.trigger("click"); | ||
|
|
||
| expect(wrapper.emitted()).toHaveProperty("clearTagFilter"); | ||
| }); | ||
| }); |
This file contains hidden or 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,29 @@ | ||
| import type { EventLogResponse } from "~/services/Api"; | ||
|
|
||
| export const fakeEventResponse: EventLogResponse = { | ||
| data: [ | ||
| { | ||
| id: 683, | ||
| event_name: "node.settings.get.success", | ||
| service_name: "hub_adapter", | ||
| timestamp: "2026-02-19T07:50:14Z", | ||
| body: "A user fetched the node's configurations settings", | ||
| attributes: { | ||
| url: "http://localhost:5000/node/settings", | ||
| path: "/node/settings", | ||
| tags: ["Hub Adapter", "Node", "Info"], | ||
| user: { | ||
| email: "foo@bar.baz", | ||
| user_id: "f464efc6-0b39-484c-8c24-248fc628dcaf", | ||
| username: "someuser", | ||
| client_id: "node-ui", | ||
| }, | ||
| client: ["127.0.0.1", 55580], | ||
| method: "GET", | ||
| service: "node", | ||
| status_code: 200, | ||
| }, | ||
| }, | ||
| ], | ||
| meta: { count: 1, total: 1, limit: 1, offset: 0 }, | ||
| }; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.