InstallBuilder.test.js 2.3 KB

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