|
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
| 2 | + |
| 3 | +import { InstallState } from '../../src/interfaces'; |
| 4 | +import { Runner } from '../../src/renderer/components/commands-runner'; |
| 5 | +import { AppState } from '../../src/renderer/state'; |
| 6 | +import { renderClassComponentWithInstanceRef } from '../test-utils/renderClassComponentWithInstanceRef'; |
| 7 | + |
| 8 | +vi.mock('../../src/renderer/file-manager'); |
| 9 | + |
| 10 | +describe('Runner component', () => { |
| 11 | + let store: AppState; |
| 12 | + |
| 13 | + beforeEach(() => { |
| 14 | + ({ state: store } = window.app); |
| 15 | + }); |
| 16 | + |
| 17 | + it('is runnable when Electron is installed', () => { |
| 18 | + store.currentElectronVersion.state = InstallState.installed; |
| 19 | + const { renderResult } = renderClassComponentWithInstanceRef(Runner, { |
| 20 | + appState: store, |
| 21 | + }); |
| 22 | + |
| 23 | + const button = renderResult.getByRole('button', { name: /run/i }); |
| 24 | + expect(button).toBeInTheDocument(); |
| 25 | + expect(button).not.toBeDisabled(); |
| 26 | + expect(button.textContent).toContain('Run'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('can be stopped if Fiddle is running', () => { |
| 30 | + store.currentElectronVersion.state = InstallState.installed; |
| 31 | + store.isRunning = true; |
| 32 | + const { renderResult } = renderClassComponentWithInstanceRef(Runner, { |
| 33 | + appState: store, |
| 34 | + }); |
| 35 | + |
| 36 | + const button = renderResult.getByRole('button', { name: /stop/i }); |
| 37 | + expect(button).toBeInTheDocument(); |
| 38 | + expect(button).not.toBeDisabled(); |
| 39 | + expect(button.textContent).toContain('Stop'); |
| 40 | + expect(button).toHaveClass('bp3-active'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('disables the button when installing modules', () => { |
| 44 | + store.currentElectronVersion.state = InstallState.installed; |
| 45 | + store.isInstallingModules = true; |
| 46 | + const { renderResult } = renderClassComponentWithInstanceRef(Runner, { |
| 47 | + appState: store, |
| 48 | + }); |
| 49 | + |
| 50 | + const button = renderResult.getByRole('button', { |
| 51 | + name: /installing modules/i, |
| 52 | + }); |
| 53 | + expect(button).toBeInTheDocument(); |
| 54 | + expect(button).toBeDisabled(); |
| 55 | + expect(button.textContent).toContain('Installing modules'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('disables the button when downloading Electron', () => { |
| 59 | + store.currentElectronVersion.state = InstallState.downloading; |
| 60 | + store.currentElectronVersion.downloadProgress = 50; |
| 61 | + const { renderResult } = renderClassComponentWithInstanceRef(Runner, { |
| 62 | + appState: store, |
| 63 | + }); |
| 64 | + |
| 65 | + const button = renderResult.getByRole('button', { name: /downloading/i }); |
| 66 | + expect(button).toBeInTheDocument(); |
| 67 | + expect(button).toBeDisabled(); |
| 68 | + expect(button.textContent).toContain('Downloading'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('disables the button when unzipping Electron', () => { |
| 72 | + store.currentElectronVersion.state = InstallState.installing; |
| 73 | + const { renderResult } = renderClassComponentWithInstanceRef(Runner, { |
| 74 | + appState: store, |
| 75 | + }); |
| 76 | + |
| 77 | + const button = renderResult.getByRole('button', { name: /unzipping/i }); |
| 78 | + expect(button).toBeInTheDocument(); |
| 79 | + expect(button).toBeDisabled(); |
| 80 | + expect(button.textContent).toContain('Unzipping'); |
| 81 | + }); |
| 82 | + |
| 83 | + it('disables the button when Electron is missing', () => { |
| 84 | + store.currentElectronVersion.state = InstallState.missing; |
| 85 | + const { renderResult } = renderClassComponentWithInstanceRef(Runner, { |
| 86 | + appState: store, |
| 87 | + }); |
| 88 | + |
| 89 | + const button = renderResult.getByRole('button', { |
| 90 | + name: /checking status/i, |
| 91 | + }); |
| 92 | + expect(button).toBeInTheDocument(); |
| 93 | + expect(button).toBeDisabled(); |
| 94 | + expect(button.textContent).toContain('Checking status'); |
| 95 | + }); |
| 96 | +}); |
0 commit comments