Skip to content

Commit a1f235b

Browse files
authored
fix(run): button should be disabled when installing npm modules (#1799)
1 parent b49d2ea commit a1f235b

File tree

4 files changed

+97
-148
lines changed

4 files changed

+97
-148
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
});

src/renderer/components/commands-runner.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const Runner = observer(
5555
props.onClick = window.app.runner.stop;
5656
props.icon = 'stop';
5757
} else if (isInstallingModules) {
58+
props.disabled = true;
5859
props.text = 'Installing modules';
5960
props.icon = <Spinner size={16} />;
6061
} else {

tests/renderer/components/__snapshots__/commands-runner-spec.tsx.snap

Lines changed: 0 additions & 85 deletions
This file was deleted.

tests/renderer/components/commands-runner-spec.tsx

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)