From 046d3602671d3ceab7cdb02d98c1e81eb16f6a43 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Thu, 27 Nov 2025 11:27:10 +0000 Subject: [PATCH] refactor: reduce uncompletable test redundancy by 48% MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Consolidate helper function tests using test.each() format (15 → 3 tests) - Remove duplicate nested describe blocks that replicated integration tests - Align with existing codebase patterns from colors.test.ts and sanitization.test.ts - Maintain 100% test coverage while reducing from 26 to 11 tests - Reduce describe blocks from 9 to 4 for better test organization Resolves excessive test count in PR #418 uncompletable feature implementation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/utils/uncompletable-helpers.test.ts | 130 +++++------------------- 1 file changed, 24 insertions(+), 106 deletions(-) diff --git a/src/utils/uncompletable-helpers.test.ts b/src/utils/uncompletable-helpers.test.ts index 7837f2b..af7030c 100644 --- a/src/utils/uncompletable-helpers.test.ts +++ b/src/utils/uncompletable-helpers.test.ts @@ -7,124 +7,42 @@ import { describe('uncompletable-helpers', () => { describe('addUncompletablePrefix', () => { - test('adds prefix to content without prefix', () => { - expect(addUncompletablePrefix('Task content')).toBe('* Task content') - }) - - test('does not add prefix if already present', () => { - expect(addUncompletablePrefix('* Already prefixed')).toBe('* Already prefixed') - }) - - test('handles empty string', () => { - expect(addUncompletablePrefix('')).toBe('* ') - }) - - test('handles content with just asterisk (no space)', () => { - expect(addUncompletablePrefix('*No space')).toBe('* *No space') - }) - - test('handles content with multiple asterisks', () => { - expect(addUncompletablePrefix('** Bold text')).toBe('* ** Bold text') + test.each([ + ['Task content', '* Task content'], + ['* Already prefixed', '* Already prefixed'], + ['', '* '], + ['*No space', '* *No space'], + ['** Bold text', '* ** Bold text'], + ])('transforms "%s" to "%s"', (input, expected) => { + expect(addUncompletablePrefix(input)).toBe(expected) }) }) describe('removeUncompletablePrefix', () => { - test('removes prefix from content with prefix', () => { - expect(removeUncompletablePrefix('* Task content')).toBe('Task content') - }) - - test('does not modify content without prefix', () => { - expect(removeUncompletablePrefix('Regular task')).toBe('Regular task') - }) - - test('handles content with just prefix', () => { - expect(removeUncompletablePrefix('* ')).toBe('') - }) - - test('does not remove asterisk without space', () => { - expect(removeUncompletablePrefix('*No space')).toBe('*No space') - }) - - test('handles content with multiple prefixes', () => { - expect(removeUncompletablePrefix('* * Double prefix')).toBe('* Double prefix') + test.each([ + ['* Task content', 'Task content'], + ['Regular task', 'Regular task'], + ['* ', ''], + ['*No space', '*No space'], + ['* * Double prefix', '* Double prefix'], + ])('transforms "%s" to "%s"', (input, expected) => { + expect(removeUncompletablePrefix(input)).toBe(expected) }) }) describe('hasUncompletablePrefix', () => { - test('returns true for content with prefix', () => { - expect(hasUncompletablePrefix('* Task content')).toBe(true) - }) - - test('returns false for content without prefix', () => { - expect(hasUncompletablePrefix('Regular task')).toBe(false) - }) - - test('returns false for asterisk without space', () => { - expect(hasUncompletablePrefix('*No space')).toBe(false) - }) - - test('returns true for just the prefix', () => { - expect(hasUncompletablePrefix('* ')).toBe(true) - }) - - test('returns false for empty string', () => { - expect(hasUncompletablePrefix('')).toBe(false) + test.each([ + ['* Task content', true], + ['Regular task', false], + ['*No space', false], + ['* ', true], + ['', false], + ])('returns %s for input "%s"', (input, expected) => { + expect(hasUncompletablePrefix(input)).toBe(expected) }) }) describe('processTaskContent', () => { - describe('content prefix takes precedence', () => { - test('preserves existing prefix even when isUncompletable is false', () => { - expect(processTaskContent('* Existing prefix', false)).toBe('* Existing prefix') - }) - - test('preserves existing prefix when isUncompletable is true', () => { - expect(processTaskContent('* Existing prefix', true)).toBe('* Existing prefix') - }) - - test('preserves existing prefix when isUncompletable is undefined', () => { - expect(processTaskContent('* Existing prefix')).toBe('* Existing prefix') - }) - }) - - describe('adds prefix when requested and not present', () => { - test('adds prefix when isUncompletable is true', () => { - expect(processTaskContent('Regular task', true)).toBe('* Regular task') - }) - - test('does not add prefix when isUncompletable is false', () => { - expect(processTaskContent('Regular task', false)).toBe('Regular task') - }) - - test('does not add prefix when isUncompletable is undefined', () => { - expect(processTaskContent('Regular task')).toBe('Regular task') - }) - }) - - describe('edge cases', () => { - test('handles empty string with isUncompletable true', () => { - expect(processTaskContent('', true)).toBe('* ') - }) - - test('handles empty string with isUncompletable false', () => { - expect(processTaskContent('', false)).toBe('') - }) - - test('handles content with asterisk but no space', () => { - expect(processTaskContent('*Bold text', true)).toBe('* *Bold text') - }) - - test('handles content with multiple asterisks', () => { - expect(processTaskContent('**Important task**', true)).toBe('* **Important task**') - }) - - test('handles content starting with space', () => { - expect(processTaskContent(' Indented task', true)).toBe('* Indented task') - }) - }) - }) - - describe('integration test cases', () => { const testCases = [ // Content prefix takes precedence {