ui_migration bugfix(component) Fix innerText tag error from test
This commit is contained in:
parent
13b5e86269
commit
8afc7a61f3
3 changed files with 35 additions and 40 deletions
|
|
@ -225,7 +225,7 @@ export default {
|
||||||
},
|
},
|
||||||
escapeText: function (unsafeText) {
|
escapeText: function (unsafeText) {
|
||||||
let div = document.createElement("div");
|
let div = document.createElement("div");
|
||||||
div.innerText = unsafeText;
|
div.textContent = unsafeText;
|
||||||
return div.innerHTML;
|
return div.innerHTML;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,18 @@
|
||||||
// File: LoggingContent.spec.js
|
import { mount } from "@vue/test-utils";
|
||||||
// Component: loggingContent.vue
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
// This file mocks AXIOS for simulated requests and VUEUSE as its not standard JSDOM.
|
import { createTestingPinia } from "@pinia/testing";
|
||||||
|
import axios from "axios";
|
||||||
import { mount } from '@vue/test-utils';
|
import LoggingContent from "../../components/tabContentComponents/loggingContent.vue";
|
||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
||||||
import { createTestingPinia } from '@pinia/testing';
|
|
||||||
import axios from 'axios';
|
|
||||||
import LoggingContent from '../../components/tabContentComponents/loggingContent.vue';
|
|
||||||
|
|
||||||
// Mock Axios
|
// Mock Axios
|
||||||
vi.mock('axios');
|
vi.mock("axios");
|
||||||
|
|
||||||
// Mock VueUse to prevent IntersectionObserver crashes in JSDOM
|
// Mock VueUse to prevent IntersectionObserver crashes in JSDOM
|
||||||
vi.mock('@vueuse/core', () => ({
|
vi.mock("@vueuse/core", () => ({
|
||||||
useIntersectionObserver: vi.fn(),
|
useIntersectionObserver: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('LoggingContent.vue', () => {
|
describe("LoggingContent.vue", () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
// A sample log string matching backend's format
|
// A sample log string matching backend's format
|
||||||
|
|
@ -29,7 +25,7 @@ describe('LoggingContent.vue', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Reset mocks before each test
|
// Reset mocks before each test
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|
||||||
// Set axios to return our fake logs
|
// Set axios to return our fake logs
|
||||||
axios.get.mockResolvedValue({ data: mockLogData });
|
axios.get.mockResolvedValue({ data: mockLogData });
|
||||||
|
|
||||||
|
|
@ -40,51 +36,51 @@ describe('LoggingContent.vue', () => {
|
||||||
createTestingPinia({
|
createTestingPinia({
|
||||||
createSpy: vi.fn,
|
createSpy: vi.fn,
|
||||||
initialState: {
|
initialState: {
|
||||||
settings: { baseUri: 'http://localhost:3000/api/v3' }
|
settings: { baseUri: "http://localhost:3000/api/v3" },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
// Simplify child components
|
// Simplify child components
|
||||||
stubs: ['PaginateLinks', 'EndpointButton']
|
stubs: ["PaginateLinks", "EndpointButton"],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Render check
|
// Render check
|
||||||
it('renders the component correctly', () => {
|
it("renders the component correctly", () => {
|
||||||
expect(wrapper.exists()).toBe(true);
|
expect(wrapper.exists()).toBe(true);
|
||||||
expect(wrapper.find('.logging-navbar').exists()).toBe(true);
|
expect(wrapper.find(".logging-navbar").exists()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fetches logs and parses them correctly when updateLogs is called', async () => {
|
it("fetches logs and parses them correctly when updateLogs is called", async () => {
|
||||||
// Trigger the method
|
// Trigger the method
|
||||||
await wrapper.vm.updateLogs();
|
await wrapper.vm.updateLogs();
|
||||||
|
|
||||||
// Verify Axios was called with the correct URI from the Pinia store
|
// Verify Axios was called with the correct URI from the Pinia store
|
||||||
expect(axios.get).toHaveBeenCalledWith('http://localhost:3000/api/v3/log/');
|
expect(axios.get).toHaveBeenCalledWith("http://localhost:3000/api/v3/log/");
|
||||||
|
|
||||||
// Verify the logs array was populated and reversed (newest first)
|
// Verify the logs array was populated and reversed (newest first)
|
||||||
expect(wrapper.vm.logs.length).toBe(3);
|
expect(wrapper.vm.logs.length).toBe(3);
|
||||||
|
|
||||||
// Check if the most recent log (ERROR) is first due to .reverse()
|
// Check if the most recent log (ERROR) is first due to .reverse()
|
||||||
expect(wrapper.vm.logs[0].level).toBe('ERROR');
|
expect(wrapper.vm.logs[0].level).toBe("ERROR");
|
||||||
|
|
||||||
// Check if the multi-line traceback was appended correctly to the ERROR log
|
// Check if the multi-line traceback was appended correctly to the ERROR log
|
||||||
expect(wrapper.vm.logs[0].message).toContain('Traceback');
|
expect(wrapper.vm.logs[0].message).toContain("Traceback");
|
||||||
expect(wrapper.vm.logs[0].summary).toContain('connect()');
|
expect(wrapper.vm.logs[0].summary).toContain("connect()");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filters logs based on the selected level', async () => {
|
it("filters logs based on the selected level", async () => {
|
||||||
await wrapper.vm.updateLogs();
|
await wrapper.vm.updateLogs();
|
||||||
|
|
||||||
// Set filter to ERROR (should only show ERROR and CRITICAL)
|
// Set filter to ERROR (should only show ERROR and CRITICAL)
|
||||||
wrapper.vm.filterLevel = 'ERROR';
|
wrapper.vm.filterLevel = "ERROR";
|
||||||
|
|
||||||
// wait for Vue reactivity to update computed properties
|
// wait for Vue reactivity to update computed properties
|
||||||
await wrapper.vm.$nextTick();
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
// Only the 1 ERROR log should remain in filteredItems
|
// Only the 1 ERROR log should remain in filteredItems
|
||||||
expect(wrapper.vm.filteredItems.length).toBe(1);
|
expect(wrapper.vm.filteredItems.length).toBe(1);
|
||||||
expect(wrapper.vm.filteredItems[0].level).toBe('ERROR');
|
expect(wrapper.vm.filteredItems[0].level).toBe("ERROR");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,22 @@
|
||||||
|
|
||||||
// File: vitest.config.js
|
// File: vitest.config.js
|
||||||
// Generic configuration for vitest
|
// Generic configuration for vitest
|
||||||
|
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from "vitest/config";
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from "@vitejs/plugin-vue";
|
||||||
import path from 'path';
|
import path from "path";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
|
|
||||||
test: {
|
test: {
|
||||||
environment: 'jsdom',
|
environment: "jsdom",
|
||||||
|
|
||||||
globals: true,
|
globals: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
"@": path.resolve(__dirname, "./src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue