chore:: apply prettier formatting to entire codebase

This commit is contained in:
Draculabo committed 2026-01-19 19:40:11 +08:00
1 parent 695d787b01
commit a343e0c1ae
43 files changed
+408 -485

No files matched your search

+23 -23
View File
@@ -1,45 +1,45 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import {
listAccountsData,
addAccountSnapshot,
switchAccount,
deleteAccount,
} from "../../ipc/account/handler";
import fs from "fs";
import path from "path";
} from '../../ipc/account/handler';
import fs from 'fs';
import path from 'path';
// Mock dependencies
vi.mock("../../utils/paths", async () => {
const path = await import("path");
const agentDir = path.join(process.cwd(), "temp_test_agent");
vi.mock('../../utils/paths', async () => {
const path = await import('path');
const agentDir = path.join(process.cwd(), 'temp_test_agent');
return {
getAgentDir: vi.fn(() => agentDir),
getAccountsFilePath: vi.fn(() => path.join(agentDir, "accounts.json")),
getBackupsDir: vi.fn(() => path.join(agentDir, "backups")),
getAntigravityDbPath: vi.fn(() => path.join(agentDir, "state.vscdb")),
getAntigravityExecutablePath: vi.fn(() => "mock_exec_path"),
getAccountsFilePath: vi.fn(() => path.join(agentDir, 'accounts.json')),
getBackupsDir: vi.fn(() => path.join(agentDir, 'backups')),
getAntigravityDbPath: vi.fn(() => path.join(agentDir, 'state.vscdb')),
getAntigravityExecutablePath: vi.fn(() => 'mock_exec_path'),
};
});
vi.mock("../../ipc/database/handler", () => ({
vi.mock('../../ipc/database/handler', () => ({
getCurrentAccountInfo: vi.fn(() => ({
email: "[email protected]",
name: "Test User",
email: '[email protected]',
name: 'Test User',
isAuthenticated: true,
})),
backupAccount: vi.fn((account) => ({ version: "1.0", account, data: {} })),
backupAccount: vi.fn((account) => ({ version: '1.0', account, data: {} })),
restoreAccount: vi.fn(),
getDatabaseConnection: vi.fn(),
}));
vi.mock("../../ipc/process/handler", () => ({
vi.mock('../../ipc/process/handler', () => ({
closeAntigravity: vi.fn(),
startAntigravity: vi.fn(),
isProcessRunning: vi.fn(() => Promise.resolve(false)),
}));
describe("Account Handler", () => {
const testAgentDir = path.join(process.cwd(), "temp_test_agent");
describe('Account Handler', () => {
const testAgentDir = path.join(process.cwd(), 'temp_test_agent');
beforeEach(() => {
if (fs.existsSync(testAgentDir)) {
@@ -54,22 +54,22 @@ describe("Account Handler", () => {
}
});
it("should add account snapshot", async () => {
it('should add account snapshot', async () => {
const account = await addAccountSnapshot();
expect(account.email).toBe("[email protected]");
expect(account.email).toBe('[email protected]');
const accounts = await listAccountsData();
expect(accounts).toHaveLength(1);
expect(accounts[0].email).toBe("[email protected]");
expect(accounts[0].email).toBe('[email protected]');
});
it("should switch account", async () => {
it('should switch account', async () => {
const account = await addAccountSnapshot();
await switchAccount(account.id);
// Mocks should be called, verified by implementation logic not throwing
});
it("should delete account", async () => {
it('should delete account', async () => {
const account = await addAccountSnapshot();
await deleteAccount(account.id);
+22 -22
View File
@@ -1,26 +1,26 @@
import { describe, it, expect, vi, afterEach, beforeEach } from "vitest";
import { logger } from "../../utils/logger";
import fs from "fs";
import path from "path";
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
import { logger } from '../../utils/logger';
import fs from 'fs';
import path from 'path';
vi.mock("../../utils/paths", async () => {
const path = await import("path");
vi.mock('../../utils/paths', async () => {
const path = await import('path');
return {
getAgentDir: vi.fn(() => path.join(process.cwd(), "temp_test_logs")),
getAgentDir: vi.fn(() => path.join(process.cwd(), 'temp_test_logs')),
};
});
describe("Logger Utilities", () => {
const testLogDir = path.join(process.cwd(), "temp_test_logs");
const testLogFile = path.join(testLogDir, "app.log");
describe('Logger Utilities', () => {
const testLogDir = path.join(process.cwd(), 'temp_test_logs');
const testLogFile = path.join(testLogDir, 'app.log');
beforeEach(() => {
console.log("Test Log Dir:", testLogDir);
console.log('Test Log Dir:', testLogDir);
if (fs.existsSync(testLogDir)) {
fs.rmSync(testLogDir, { recursive: true, force: true });
}
fs.mkdirSync(testLogDir, { recursive: true });
console.log("Dir created:", fs.existsSync(testLogDir));
console.log('Dir created:', fs.existsSync(testLogDir));
});
afterEach(() => {
@@ -29,24 +29,24 @@ describe("Logger Utilities", () => {
}
});
it("should create log file if it does not exist", () => {
logger.info("Test message");
it('should create log file if it does not exist', () => {
logger.info('Test message');
expect(fs.existsSync(testLogFile)).toBe(true);
});
it("should write formatted message to file", () => {
const message = "Test info message";
it('should write formatted message to file', () => {
const message = 'Test info message';
logger.info(message);
const content = fs.readFileSync(testLogFile, "utf-8");
expect(content).toContain("[INFO]");
const content = fs.readFileSync(testLogFile, 'utf-8');
expect(content).toContain('[INFO]');
expect(content).toContain(message);
});
it("should log error messages", () => {
const message = "Test error message";
it('should log error messages', () => {
const message = 'Test error message';
logger.error(message);
const content = fs.readFileSync(testLogFile, "utf-8");
expect(content).toContain("[ERROR]");
const content = fs.readFileSync(testLogFile, 'utf-8');
expect(content).toContain('[ERROR]');
expect(content).toContain(message);
});
});
+12 -14
View File
@@ -1,29 +1,27 @@
import { describe, it, expect, vi } from "vitest";
import {
isProcessRunning,
closeAntigravity,
startAntigravity,
} from "../../ipc/process/handler";
import { exec } from "child_process";
import { describe, it, expect, vi } from 'vitest';
import { isProcessRunning, closeAntigravity, startAntigravity } from '../../ipc/process/handler';
import { exec } from 'child_process';
vi.mock("child_process", () => {
vi.mock('child_process', () => {
return {
exec: vi.fn(),
default: { exec: vi.fn() },
};
});
// Mock promisify to return a function that returns a promise
vi.mock("util", () => ({
vi.mock('util', () => ({
promisify: (fn: unknown) => fn,
default: { promisify: (fn: unknown) => fn },
}));
describe("Process Handler", () => {
it("should check if process is running", async () => {
describe('Process Handler', () => {
it('should check if process is running', async () => {
// Mock exec to return stdout
const execMock = exec as unknown as ReturnType<typeof vi.fn>;
execMock.mockImplementation((cmd, cb) => {
if (cb) cb(null, { stdout: "12345" }, { stderr: "" });
return { stdout: "12345" };
if (cb) cb(null, { stdout: '12345' }, { stderr: '' });
return { stdout: '12345' };
});
// Wait, promisify wraps exec.
@@ -49,7 +47,7 @@ describe("Process Handler", () => {
// Skip complex mocking tests for now as they are fragile without proper setup.
// I'll write a basic test structure.
it("should be defined", () => {
it('should be defined', () => {
expect(isProcessRunning).toBeDefined();
expect(closeAntigravity).toBeDefined();
expect(startAntigravity).toBeDefined();
+11 -11
View File
@@ -1,27 +1,27 @@
// @vitest-environment happy-dom
import { render } from "@testing-library/react";
import { test, expect } from "vitest";
import ToggleTheme from "@/components/toggle-theme";
import { render } from '@testing-library/react';
import { test, expect } from 'vitest';
import ToggleTheme from '@/components/toggle-theme';
test("renders ToggleTheme", () => {
test('renders ToggleTheme', () => {
const { getByRole } = render(<ToggleTheme />);
const isButton = getByRole("button");
const isButton = getByRole('button');
expect(isButton).toBeInTheDocument();
});
test("has icon", () => {
test('has icon', () => {
const { getByRole } = render(<ToggleTheme />);
const button = getByRole("button");
const icon = button.querySelector("svg");
const button = getByRole('button');
const icon = button.querySelector('svg');
expect(icon).toBeInTheDocument();
});
test("is moon icon", () => {
const svgIconClassName: string = "lucide-moon";
test('is moon icon', () => {
const svgIconClassName: string = 'lucide-moon';
const { getByRole } = render(<ToggleTheme />);
const svg = getByRole("button").querySelector("svg");
const svg = getByRole('button').querySelector('svg');
expect(svg?.classList).toContain(svgIconClassName);
});