takt/src/__tests__/selectorUtils.test.ts
nrslib 620e384251 interactiveモジュールの分割とタスク再キュー方式への移行
interactive.tsからsummary/runSelector/runSessionReader/selectorUtilsを分離し、
run session参照をrouting層からinstructMode層に移動。instructBranchで新タスク
作成の代わりに既存タスクのrequeueを使用する方式に変更。worktree確認プロンプトを
廃止し常時有効化。
2026-02-18 18:49:21 +09:00

61 lines
1.7 KiB
TypeScript

/**
* Tests for selector shared utilities
*/
import { describe, it, expect } from 'vitest';
import { truncateForLabel, formatDateForSelector } from '../features/interactive/selectorUtils.js';
describe('truncateForLabel', () => {
it('should return text as-is when within max length', () => {
const result = truncateForLabel('Short text', 20);
expect(result).toBe('Short text');
});
it('should truncate text exceeding max length with ellipsis', () => {
const longText = 'A'.repeat(100);
const result = truncateForLabel(longText, 60);
expect(result).toHaveLength(61); // 60 + '…'
expect(result).toBe('A'.repeat(60) + '…');
});
it('should replace newlines with spaces', () => {
const result = truncateForLabel('Line one\nLine two\nLine three', 50);
expect(result).toBe('Line one Line two Line three');
expect(result).not.toContain('\n');
});
it('should trim surrounding whitespace', () => {
const result = truncateForLabel(' padded text ', 50);
expect(result).toBe('padded text');
});
it('should handle text exactly at max length', () => {
const exactText = 'A'.repeat(60);
const result = truncateForLabel(exactText, 60);
expect(result).toBe(exactText);
});
});
describe('formatDateForSelector', () => {
it('should format date for English locale', () => {
const result = formatDateForSelector('2026-02-01T10:30:00Z', 'en');
expect(result).toBeTruthy();
expect(typeof result).toBe('string');
});
it('should format date for Japanese locale', () => {
const result = formatDateForSelector('2026-02-01T10:30:00Z', 'ja');
expect(result).toBeTruthy();
expect(typeof result).toBe('string');
});
});