|
| 1 | +import inquirer from 'inquirer'; |
| 2 | +import { features } from '../features'; |
| 3 | + |
| 4 | +jest.mock('inquirer'); |
| 5 | + |
| 6 | +describe('features prompt', () => { |
| 7 | + beforeEach(() => { |
| 8 | + jest.clearAllMocks(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should handle case where all features are selected as must-have', async () => { |
| 12 | + const mockPrompt = jest.mocked(inquirer.prompt); |
| 13 | + |
| 14 | + // Mock initial feature selection - select all features |
| 15 | + mockPrompt.mockResolvedValueOnce({ |
| 16 | + selectedFeatures: ['auth', 'dashboard', 'crud', 'file-upload', 'realtime', 'email', 'search'], |
| 17 | + }); |
| 18 | + |
| 19 | + // Mock no custom features |
| 20 | + mockPrompt.mockResolvedValueOnce({ |
| 21 | + hasCustomFeatures: false, |
| 22 | + }); |
| 23 | + |
| 24 | + // Mock must-have selection - this should validate against selecting all |
| 25 | + mockPrompt.mockResolvedValueOnce({ |
| 26 | + mustHaveFeatures: ['auth', 'crud', 'dashboard'], |
| 27 | + }); |
| 28 | + |
| 29 | + // Mock nice-to-have selection - should have remaining features |
| 30 | + mockPrompt.mockResolvedValueOnce({ |
| 31 | + niceToHaveFeatures: ['search', 'email'], |
| 32 | + }); |
| 33 | + |
| 34 | + const result = await features('web'); |
| 35 | + |
| 36 | + expect(result).toHaveLength(7); |
| 37 | + expect(result.filter((f) => f.priority === 'must-have')).toHaveLength(3); |
| 38 | + expect(result.filter((f) => f.priority === 'nice-to-have')).toHaveLength(2); |
| 39 | + expect(result.filter((f) => f.priority === 'should-have')).toHaveLength(2); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should skip nice-to-have prompt when all features are must-have', async () => { |
| 43 | + const mockPrompt = jest.mocked(inquirer.prompt); |
| 44 | + |
| 45 | + // Mock initial feature selection - select only 2 features |
| 46 | + mockPrompt.mockResolvedValueOnce({ |
| 47 | + selectedFeatures: ['auth', 'crud'], |
| 48 | + }); |
| 49 | + |
| 50 | + // Mock no custom features |
| 51 | + mockPrompt.mockResolvedValueOnce({ |
| 52 | + hasCustomFeatures: false, |
| 53 | + }); |
| 54 | + |
| 55 | + // Mock must-have selection - select all available features |
| 56 | + mockPrompt.mockResolvedValueOnce({ |
| 57 | + mustHaveFeatures: ['auth', 'crud'], |
| 58 | + }); |
| 59 | + |
| 60 | + const result = await features('web'); |
| 61 | + |
| 62 | + // Should only call prompt 3 times (not 4) since nice-to-have is skipped |
| 63 | + expect(mockPrompt).toHaveBeenCalledTimes(3); |
| 64 | + expect(result).toHaveLength(2); |
| 65 | + expect(result.every((f) => f.priority === 'must-have')).toBe(true); |
| 66 | + }); |
| 67 | +}); |
0 commit comments