generated from nhcarrigan/template
style: fix strict clippy and TypeScript type errors
- Fix assertions on constants in clipboard.rs (use const blocks) - Fix unnecessary unwrap after is_ok check in git.rs - Remove redundant u64 >= 0 comparison in stats.rs - Add #[allow(clippy::useless_vec)] to sorting tests - Add missing beforeEach import to vitest.setup.ts - Change global.Audio to globalThis.Audio in notifications.test.ts - Add type annotations to fix null type narrowing in conversations.test.ts
This commit is contained in:
@@ -408,13 +408,15 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_max_history_size_is_reasonable() {
|
fn test_max_history_size_is_reasonable() {
|
||||||
assert_eq!(MAX_HISTORY_SIZE, 100);
|
assert_eq!(MAX_HISTORY_SIZE, 100);
|
||||||
assert!(MAX_HISTORY_SIZE > 0);
|
// Compile-time assertions for constant bounds
|
||||||
assert!(MAX_HISTORY_SIZE <= 1000); // Sanity check
|
const _: () = assert!(MAX_HISTORY_SIZE > 0);
|
||||||
|
const _: () = assert!(MAX_HISTORY_SIZE <= 1000); // Sanity check
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Pinned entry sorting tests ====================
|
// ==================== Pinned entry sorting tests ====================
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_pinned_entries_sorting() {
|
fn test_pinned_entries_sorting() {
|
||||||
let mut entries = vec![
|
let mut entries = vec![
|
||||||
ClipboardEntry {
|
ClipboardEntry {
|
||||||
@@ -464,6 +466,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_multiple_pinned_entries_sorting() {
|
fn test_multiple_pinned_entries_sorting() {
|
||||||
let mut entries = vec![
|
let mut entries = vec![
|
||||||
ClipboardEntry {
|
ClipboardEntry {
|
||||||
|
|||||||
@@ -733,8 +733,8 @@ mod tests {
|
|||||||
|
|
||||||
let result = git_log(working_dir, Some(10));
|
let result = git_log(working_dir, Some(10));
|
||||||
// May fail on empty repo or return empty
|
// May fail on empty repo or return empty
|
||||||
if result.is_ok() {
|
if let Ok(commits) = result {
|
||||||
assert!(result.unwrap().is_empty());
|
assert!(commits.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_quick_action_sorting_defaults_first() {
|
fn test_quick_action_sorting_defaults_first() {
|
||||||
let mut actions = vec![
|
let mut actions = vec![
|
||||||
create_test_action("custom-z", "Zebra", false),
|
create_test_action("custom-z", "Zebra", false),
|
||||||
@@ -354,6 +355,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_action_find_by_id() {
|
fn test_action_find_by_id() {
|
||||||
let actions = vec![
|
let actions = vec![
|
||||||
create_test_action("action-1", "First", false),
|
create_test_action("action-1", "First", false),
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_session_sorting_by_activity() {
|
fn test_session_sorting_by_activity() {
|
||||||
let old_time = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
|
let old_time = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
|
||||||
let new_time = Utc.with_ymd_and_hms(2024, 6, 15, 12, 0, 0).unwrap();
|
let new_time = Utc.with_ymd_and_hms(2024, 6, 15, 12, 0, 0).unwrap();
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_snippet_sorting_by_category_then_name() {
|
fn test_snippet_sorting_by_category_then_name() {
|
||||||
let mut snippets = vec![
|
let mut snippets = vec![
|
||||||
create_test_snippet("s1", "Zebra", "B-Category", false),
|
create_test_snippet("s1", "Zebra", "B-Category", false),
|
||||||
@@ -388,6 +389,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_snippet_find_by_id() {
|
fn test_snippet_find_by_id() {
|
||||||
let snippets = vec![
|
let snippets = vec![
|
||||||
create_test_snippet("snippet-1", "First", "Cat", false),
|
create_test_snippet("snippet-1", "First", "Cat", false),
|
||||||
@@ -404,6 +406,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::useless_vec)]
|
||||||
fn test_extract_categories_sorted_and_deduped() {
|
fn test_extract_categories_sorted_and_deduped() {
|
||||||
let snippets = vec![
|
let snippets = vec![
|
||||||
create_test_snippet("s1", "S1", "Zebra", false),
|
create_test_snippet("s1", "S1", "Zebra", false),
|
||||||
|
|||||||
@@ -523,9 +523,8 @@ mod tests {
|
|||||||
let mut stats = UsageStats::new();
|
let mut stats = UsageStats::new();
|
||||||
stats.session_start = Some(Instant::now());
|
stats.session_start = Some(Instant::now());
|
||||||
|
|
||||||
// The duration should be at least 0 seconds
|
// Verify duration is returned (u64 is always non-negative)
|
||||||
let duration = stats.get_session_duration();
|
let _duration = stats.get_session_duration();
|
||||||
assert!(duration >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class MockAudioElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store original Audio before mocking
|
// Store original Audio before mocking
|
||||||
const OriginalAudio = global.Audio;
|
const OriginalAudio = globalThis.Audio;
|
||||||
|
|
||||||
describe("notifications", () => {
|
describe("notifications", () => {
|
||||||
describe("NotificationType enum", () => {
|
describe("NotificationType enum", () => {
|
||||||
@@ -162,12 +162,12 @@ describe("notifications", () => {
|
|||||||
describe("SoundPlayer class", () => {
|
describe("SoundPlayer class", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Mock Audio constructor
|
// Mock Audio constructor
|
||||||
global.Audio = MockAudioElement as unknown as typeof Audio;
|
globalThis.Audio = MockAudioElement as unknown as typeof Audio;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// Restore original Audio
|
// Restore original Audio
|
||||||
global.Audio = OriginalAudio;
|
globalThis.Audio = OriginalAudio;
|
||||||
vi.resetModules();
|
vi.resetModules();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -232,12 +232,12 @@ describe("notifications", () => {
|
|||||||
|
|
||||||
describe("NotificationManager class", () => {
|
describe("NotificationManager class", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
global.Audio = MockAudioElement as unknown as typeof Audio;
|
globalThis.Audio = MockAudioElement as unknown as typeof Audio;
|
||||||
vi.resetModules();
|
vi.resetModules();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
global.Audio = OriginalAudio;
|
globalThis.Audio = OriginalAudio;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can import notificationManager singleton", async () => {
|
it("can import notificationManager singleton", async () => {
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ describe("scroll position handling", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("uses positive values for manual scroll position", () => {
|
it("uses positive values for manual scroll position", () => {
|
||||||
const scrollPosition = 500;
|
const scrollPosition: number = 500;
|
||||||
const isAutoScroll = scrollPosition === -1;
|
const isAutoScroll = scrollPosition === -1;
|
||||||
|
|
||||||
expect(isAutoScroll).toBe(false);
|
expect(isAutoScroll).toBe(false);
|
||||||
@@ -461,7 +461,7 @@ describe("derived store behavior", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("defaults to disconnected when no active conversation", () => {
|
it("defaults to disconnected when no active conversation", () => {
|
||||||
const activeConv = null;
|
const activeConv = null as { connectionStatus?: string } | null;
|
||||||
const derivedStatus = activeConv?.connectionStatus || "disconnected";
|
const derivedStatus = activeConv?.connectionStatus || "disconnected";
|
||||||
|
|
||||||
expect(derivedStatus).toBe("disconnected");
|
expect(derivedStatus).toBe("disconnected");
|
||||||
@@ -480,7 +480,7 @@ describe("derived store behavior", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("defaults to empty array when no active conversation", () => {
|
it("defaults to empty array when no active conversation", () => {
|
||||||
const activeConv = null;
|
const activeConv = null as { terminalLines?: Array<{ id: string; content: string }> } | null;
|
||||||
const derivedLines = activeConv?.terminalLines || [];
|
const derivedLines = activeConv?.terminalLines || [];
|
||||||
|
|
||||||
expect(derivedLines).toEqual([]);
|
expect(derivedLines).toEqual([]);
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import "@testing-library/jest-dom/vitest";
|
import "@testing-library/jest-dom/vitest";
|
||||||
import { vi } from "vitest";
|
import { vi, beforeEach } from "vitest";
|
||||||
|
|
||||||
// Mock Tauri invoke API
|
// Mock Tauri invoke API
|
||||||
const mockInvokeResults: Record<string, unknown> = {};
|
const mockInvokeResults: Record<string, unknown> = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user