Apply repository-wide ESLint auto-fix formatting pass
Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
@@ -3,21 +3,21 @@
|
||||
// Authors:
|
||||
// imacat.yang@dsp.im (imacat), 2026/03/05
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { setActivePinia, createPinia } from "pinia";
|
||||
|
||||
vi.mock('@/module/apiError.js', () => ({
|
||||
vi.mock("@/module/apiError.js", () => ({
|
||||
default: vi.fn(),
|
||||
}));
|
||||
|
||||
const { mockGet } = vi.hoisted(() => ({ mockGet: vi.fn() }));
|
||||
vi.mock('@/api/client.js', () => ({
|
||||
vi.mock("@/api/client.js", () => ({
|
||||
default: { get: mockGet },
|
||||
}));
|
||||
|
||||
import { useCompareStore } from '@/stores/compare';
|
||||
import { useCompareStore } from "@/stores/compare";
|
||||
|
||||
describe('compareStore', () => {
|
||||
describe("compareStore", () => {
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -26,83 +26,76 @@ describe('compareStore', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('has correct default state', () => {
|
||||
it("has correct default state", () => {
|
||||
expect(store.allCompareDashboardData).toBeNull();
|
||||
});
|
||||
|
||||
it('compareDashboardData getter returns state', () => {
|
||||
it("compareDashboardData getter returns state", () => {
|
||||
store.allCompareDashboardData = { time: {} };
|
||||
expect(store.compareDashboardData).toEqual({ time: {} });
|
||||
});
|
||||
|
||||
describe('getCompare', () => {
|
||||
it('fetches compare data with encoded params', async () => {
|
||||
const params = [{ type: 'log', id: 1 }];
|
||||
describe("getCompare", () => {
|
||||
it("fetches compare data with encoded params", async () => {
|
||||
const params = [{ type: "log", id: 1 }];
|
||||
const mockData = { time: {}, freq: {} };
|
||||
mockGet.mockResolvedValue({ data: mockData });
|
||||
|
||||
await store.getCompare(params);
|
||||
|
||||
const encoded = encodeURIComponent(JSON.stringify(params));
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
`/api/compare?datasets=${encoded}`,
|
||||
);
|
||||
expect(mockGet).toHaveBeenCalledWith(`/api/compare?datasets=${encoded}`);
|
||||
expect(store.allCompareDashboardData).toEqual(mockData);
|
||||
});
|
||||
|
||||
it('does not throw on API failure', async () => {
|
||||
mockGet.mockRejectedValue(new Error('fail'));
|
||||
it("does not throw on API failure", async () => {
|
||||
mockGet.mockRejectedValue(new Error("fail"));
|
||||
|
||||
await expect(store.getCompare([]))
|
||||
.resolves.not.toThrow();
|
||||
await expect(store.getCompare([])).resolves.not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStateData', () => {
|
||||
it('fetches log discover stats', async () => {
|
||||
describe("getStateData", () => {
|
||||
it("fetches log discover stats", async () => {
|
||||
mockGet.mockResolvedValue({
|
||||
data: { stats: { cases: 100 } },
|
||||
});
|
||||
|
||||
const result = await store.getStateData('log', 1);
|
||||
const result = await store.getStateData("log", 1);
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
'/api/logs/1/discover',
|
||||
);
|
||||
expect(mockGet).toHaveBeenCalledWith("/api/logs/1/discover");
|
||||
expect(result).toEqual({ cases: 100 });
|
||||
});
|
||||
|
||||
it('fetches filter discover stats', async () => {
|
||||
it("fetches filter discover stats", async () => {
|
||||
mockGet.mockResolvedValue({
|
||||
data: { stats: { cases: 50 } },
|
||||
});
|
||||
|
||||
const result = await store.getStateData('filter', 3);
|
||||
const result = await store.getStateData("filter", 3);
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
'/api/filters/3/discover',
|
||||
);
|
||||
expect(mockGet).toHaveBeenCalledWith("/api/filters/3/discover");
|
||||
expect(result).toEqual({ cases: 50 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFileName', () => {
|
||||
it('finds file name by id', async () => {
|
||||
describe("getFileName", () => {
|
||||
it("finds file name by id", async () => {
|
||||
mockGet.mockResolvedValue({
|
||||
data: [
|
||||
{ id: 1, name: 'file1.csv' },
|
||||
{ id: 2, name: 'file2.csv' },
|
||||
{ id: 1, name: "file1.csv" },
|
||||
{ id: 2, name: "file2.csv" },
|
||||
],
|
||||
});
|
||||
|
||||
const result = await store.getFileName(1);
|
||||
|
||||
expect(result).toBe('file1.csv');
|
||||
expect(result).toBe("file1.csv");
|
||||
});
|
||||
|
||||
it('returns undefined for non-existent id', async () => {
|
||||
it("returns undefined for non-existent id", async () => {
|
||||
mockGet.mockResolvedValue({
|
||||
data: [{ id: 1, name: 'file1.csv' }],
|
||||
data: [{ id: 1, name: "file1.csv" }],
|
||||
});
|
||||
|
||||
const result = await store.getFileName(99);
|
||||
|
||||
Reference in New Issue
Block a user