UNPKG

create-datadao

Version:

A CLI tool to generate and deploy DataDAOs on the Vana network

369 lines (292 loc) â€ĸ 12.9 kB
const output = require('../output'); // Mock chalk jest.mock('chalk', () => ({ blue: { bold: jest.fn((text) => `[blue.bold]${text}[/blue.bold]`) }, gray: jest.fn((text) => `[gray]${text}[/gray]`), green: jest.fn((text) => `[green]${text}[/green]`), yellow: jest.fn((text) => `[yellow]${text}[/yellow]`), red: jest.fn((text) => `[red]${text}[/red]`), cyan: jest.fn((text) => `[cyan]${text}[/cyan]`), bgBlue: { white: { bold: jest.fn((text) => `[bgBlue.white.bold]${text}[/bgBlue.white.bold]`) } } })); describe.skip('Output Manager', () => { // TODO: These tests have complex chalk mocking issues beforeEach(() => { jest.clearAllMocks(); // Mock console.log jest.spyOn(console, 'log').mockImplementation(() => {}); // Reset quiet mode output.setQuiet(false); }); afterEach(() => { jest.restoreAllMocks(); }); describe('constructor and setup', () => { test('initializes with correct default values', () => { expect(output.isQuiet).toBe(false); expect(output.userInputMarker).toBe('👤'); }); test('setQuiet changes quiet mode', () => { expect(output.isQuiet).toBe(false); output.setQuiet(true); expect(output.isQuiet).toBe(true); output.setQuiet(false); expect(output.isQuiet).toBe(false); output.setQuiet(); // defaults to true expect(output.isQuiet).toBe(true); }); }); describe('step', () => { test('displays step title only', () => { output.step('Test Step'); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]🔄 Test Step[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(); }); test('displays step title with description', () => { output.step('Test Step', 'This is a description'); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]🔄 Test Step[/blue.bold]'); expect(console.log).toHaveBeenCalledWith('[gray] This is a description[/gray]'); expect(console.log).toHaveBeenCalledWith(); }); test('handles empty description', () => { output.step('Test Step', ''); expect(console.log).toHaveBeenCalledWith('[blue.bold]🔄 Test Step[/blue.bold]'); expect(console.log).not.toHaveBeenCalledWith(expect.stringContaining('[gray]')); }); }); describe('success', () => { test('displays success message', () => { output.success('Operation completed'); expect(console.log).toHaveBeenCalledWith('[green]✅ Operation completed[/green]'); }); }); describe('warning', () => { test('displays warning message', () => { output.warning('This is a warning'); expect(console.log).toHaveBeenCalledWith('[yellow]âš ī¸ This is a warning[/yellow]'); }); }); describe('error', () => { test('displays error message', () => { output.error('Something went wrong'); expect(console.log).toHaveBeenCalledWith('[red]❌ Something went wrong[/red]'); }); }); describe('info', () => { test('displays info message in normal mode', () => { output.setQuiet(false); output.info('This is information'); expect(console.log).toHaveBeenCalledWith('[cyan]â„šī¸ This is information[/cyan]'); }); test('suppresses info message in quiet mode', () => { output.setQuiet(true); output.info('This is information'); expect(console.log).not.toHaveBeenCalledWith('[cyan]â„šī¸ This is information[/cyan]'); }); test('forces info message even in quiet mode', () => { output.setQuiet(true); output.info('This is important information', true); expect(console.log).toHaveBeenCalledWith('[cyan]â„šī¸ This is important information[/cyan]'); }); }); describe('progress', () => { test('displays progress message in normal mode', () => { output.setQuiet(false); output.progress('Loading data'); expect(console.log).toHaveBeenCalledWith('[blue]âŗ Loading data[/blue]'); }); test('suppresses progress message in quiet mode', () => { output.setQuiet(true); output.progress('Loading data'); expect(console.log).not.toHaveBeenCalledWith('[blue]âŗ Loading data[/blue]'); }); }); describe('userInput', () => { test('displays user input prompt', () => { output.userInput('Please enter your name'); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[bgBlue.white.bold] 👤 USER INPUT REQUIRED [/bgBlue.white.bold]'); expect(console.log).toHaveBeenCalledWith('[blue.bold]Please enter your name[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(); }); }); describe('userResponse', () => { test('displays user response', () => { output.userResponse('John Doe'); expect(console.log).toHaveBeenCalledWith('[green]👤 John Doe[/green]'); expect(console.log).toHaveBeenCalledWith(); }); }); describe('summary', () => { test('displays summary with string items', () => { const items = ['Item 1', 'Item 2', 'Item 3']; output.summary('Summary Title', items); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]📋 Summary Title[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(' â€ĸ Item 1'); expect(console.log).toHaveBeenCalledWith(' â€ĸ Item 2'); expect(console.log).toHaveBeenCalledWith(' â€ĸ Item 3'); expect(console.log).toHaveBeenCalledWith(); }); test('displays summary with object items', () => { const items = [ { label: 'Name', value: 'John' }, { label: 'Age', value: '30' }, 'Mixed string item' ]; output.summary('User Info', items); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]📋 User Info[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(' â€ĸ [cyan]Name[/cyan]: John'); expect(console.log).toHaveBeenCalledWith(' â€ĸ [cyan]Age[/cyan]: 30'); expect(console.log).toHaveBeenCalledWith(' â€ĸ Mixed string item'); expect(console.log).toHaveBeenCalledWith(); }); test('handles empty items array', () => { output.summary('Empty Summary', []); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]📋 Empty Summary[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(); }); }); describe('nextSteps', () => { test('displays numbered next steps', () => { const steps = [ 'First step', 'Second step', 'Third step' ]; output.nextSteps(steps); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]🚀 Next Steps:[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(' 1. First step'); expect(console.log).toHaveBeenCalledWith(' 2. Second step'); expect(console.log).toHaveBeenCalledWith(' 3. Third step'); expect(console.log).toHaveBeenCalledWith(); }); test('handles empty steps array', () => { output.nextSteps([]); expect(console.log).toHaveBeenCalledWith(); expect(console.log).toHaveBeenCalledWith('[blue.bold]🚀 Next Steps:[/blue.bold]'); expect(console.log).toHaveBeenCalledWith(); }); test('handles single step', () => { output.nextSteps(['Only step']); expect(console.log).toHaveBeenCalledWith(' 1. Only step'); }); }); describe('divider', () => { test('displays divider in normal mode', () => { output.setQuiet(false); output.divider(); expect(console.log).toHaveBeenCalledWith('[gray]──────────────────────────────────────────────────[/gray]'); }); test('suppresses divider in quiet mode', () => { output.setQuiet(true); output.divider(); expect(console.log).not.toHaveBeenCalledWith(expect.stringContaining('──')); }); }); describe('clearLine', () => { test('clears current line', () => { const originalWrite = process.stdout.write; process.stdout.write = jest.fn(); output.clearLine(); expect(process.stdout.write).toHaveBeenCalledWith('\r\x1b[K'); process.stdout.write = originalWrite; }); }); describe('progressBar', () => { let originalWrite; beforeEach(() => { originalWrite = process.stdout.write; process.stdout.write = jest.fn(); }); afterEach(() => { process.stdout.write = originalWrite; }); test('displays progress bar at 0%', () => { output.progressBar(0, 100, 'Starting'); expect(process.stdout.write).toHaveBeenCalledWith( expect.stringContaining('░░░░░░░░░░░░░░░░░░░░ 0% Starting') ); }); test('displays progress bar at 50%', () => { output.progressBar(50, 100, 'Half way'); expect(process.stdout.write).toHaveBeenCalledWith( expect.stringContaining('██████████░░░░░░░░░░ 50% Half way') ); }); test('displays progress bar at 100%', () => { output.progressBar(100, 100, 'Complete'); expect(process.stdout.write).toHaveBeenCalledWith( expect.stringContaining('████████████████████ 100% Complete') ); expect(console.log).toHaveBeenCalledWith(); // New line when complete }); test('handles progress without message', () => { output.progressBar(25, 100); expect(process.stdout.write).toHaveBeenCalledWith( expect.stringContaining('█████░░░░░░░░░░░░░░░ 25% ') ); }); test('handles fractional progress correctly', () => { output.progressBar(33, 100); expect(process.stdout.write).toHaveBeenCalledWith( expect.stringContaining('██████░░░░░░░░░░░░░░ 33%') ); }); test('calculates bar segments correctly for small totals', () => { output.progressBar(1, 4); expect(process.stdout.write).toHaveBeenCalledWith( expect.stringContaining('█████░░░░░░░░░░░░░░░ 25%') ); }); }); describe('singleton behavior', () => { test('maintains state across imports', () => { const output1 = require('../output'); const output2 = require('../output'); expect(output1).toBe(output2); output1.setQuiet(true); expect(output2.isQuiet).toBe(true); }); }); describe('integration scenarios', () => { test('typical workflow sequence', () => { output.step('Starting process', 'This will take a few moments'); output.progress('Initializing'); output.info('Loading configuration'); output.userInput('Enter your name:'); output.userResponse('John Doe'); output.success('Configuration loaded'); output.summary('Configuration', [ { label: 'Name', value: 'John Doe' }, { label: 'Status', value: 'Ready' } ]); output.nextSteps(['Deploy application', 'Run tests', 'Monitor logs']); // Verify the sequence was called correctly expect(console.log).toHaveBeenCalledWith('[blue.bold]🔄 Starting process[/blue.bold]'); expect(console.log).toHaveBeenCalledWith('[blue]âŗ Initializing[/blue]'); expect(console.log).toHaveBeenCalledWith('[green]✅ Configuration loaded[/green]'); expect(console.log).toHaveBeenCalledWith(' 1. Deploy application'); }); test('quiet mode workflow', () => { output.setQuiet(true); output.step('Step in quiet mode'); output.info('This should be suppressed'); output.info('This should show', true); output.progress('This should be suppressed'); output.success('This should always show'); output.divider(); expect(console.log).toHaveBeenCalledWith('[blue.bold]🔄 Step in quiet mode[/blue.bold]'); expect(console.log).not.toHaveBeenCalledWith('[cyan]â„šī¸ This should be suppressed[/cyan]'); expect(console.log).toHaveBeenCalledWith('[cyan]â„šī¸ This should show[/cyan]'); expect(console.log).not.toHaveBeenCalledWith('[blue]âŗ This should be suppressed[/blue]'); expect(console.log).toHaveBeenCalledWith('[green]✅ This should always show[/green]'); expect(console.log).not.toHaveBeenCalledWith(expect.stringContaining('──')); }); }); });