|
| 1 | +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; |
| 2 | +import { render, fireEvent, screen, cleanup, waitFor } from '@testing-library/vue'; |
| 3 | +import FloatingVue from 'floating-vue'; |
| 4 | +import InstallBuilder from './InstallBuilder.vue'; |
| 5 | + |
| 6 | +describe('InstallBuilder', () => { |
| 7 | + const options = [ |
| 8 | + { flag: 'option1', label: 'Option 1', description: 'Description for Option 1', default: 'no' }, |
| 9 | + { |
| 10 | + flag: 'option2', |
| 11 | + label: 'Option 2', |
| 12 | + description: 'Description for Option 2', |
| 13 | + type: 'text', |
| 14 | + default: '', |
| 15 | + }, |
| 16 | + { |
| 17 | + flag: 'option3', |
| 18 | + label: 'Option 3', |
| 19 | + description: 'Description for Option 3', |
| 20 | + type: 'select', |
| 21 | + options: [ |
| 22 | + { value: 'val1', label: 'Value 1' }, |
| 23 | + { value: 'val2', label: 'Value 2' }, |
| 24 | + ], |
| 25 | + default: 'val1', |
| 26 | + }, |
| 27 | + ]; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + render(InstallBuilder, { |
| 31 | + props: { options }, |
| 32 | + global: { |
| 33 | + plugins: [FloatingVue], |
| 34 | + }, |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + afterEach(() => { |
| 39 | + cleanup(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('renders all options correctly', () => { |
| 43 | + options.forEach((option) => { |
| 44 | + expect(screen.getByLabelText(option.label)).toBeTruthy(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('toggles an option when clicked', async () => { |
| 49 | + const option1 = screen.getByLabelText(options[0].label); |
| 50 | + await fireEvent.click(option1); |
| 51 | + expect(option1.checked).toBe(true); |
| 52 | + }); |
| 53 | + |
| 54 | + it('updates the installation command when an option is toggled', async () => { |
| 55 | + const option1 = screen.getByLabelText(options[0].label); |
| 56 | + await fireEvent.click(option1); |
| 57 | + waitFor(() => |
| 58 | + expect(screen.getByDisplayValue(/bash hst-install.sh --option1 yes/)).toBeTruthy(), |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it('updates the installation command when option text input changes', async () => { |
| 63 | + const option2 = screen.getByLabelText(options[1].label); |
| 64 | + await fireEvent.click(option2); |
| 65 | + |
| 66 | + const textInput = screen.getByLabelText(options[1].description); |
| 67 | + await fireEvent.update(textInput, 'custom-value'); |
| 68 | + |
| 69 | + expect(screen.getByDisplayValue(/bash hst-install.sh --option2 custom-value/)).toBeTruthy(); |
| 70 | + }); |
| 71 | + |
| 72 | + it('updates the installation command when option select input changes', async () => { |
| 73 | + const option3 = screen.getByLabelText(options[2].label); |
| 74 | + await fireEvent.click(option3); |
| 75 | + |
| 76 | + const selectInput = screen.getByLabelText(options[2].description); |
| 77 | + await fireEvent.update(selectInput, { target: { value: 'val2' } }); |
| 78 | + |
| 79 | + waitFor(() => |
| 80 | + expect(screen.getByDisplayValue(/bash hst-install.sh --option3 val2/)).toBeTruthy(), |
| 81 | + ); |
| 82 | + }); |
| 83 | +}); |
0 commit comments