Fix tests to wrap all calls changing the UI with act. (#12268)

This commit is contained in:
Jacob Richman
2025-10-30 11:50:26 -07:00
committed by GitHub
parent cc081337b7
commit 54fa26ef0e
69 changed files with 2002 additions and 1291 deletions

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { render } from 'ink-testing-library';
import { render } from '../../../test-utils/render.js';
import { vi, describe, beforeEach, it, expect } from 'vitest';
import { useUIState } from '../../contexts/UIStateContext.js';
import { ExtensionUpdateState } from '../../state/extensions.js';
@@ -57,27 +57,30 @@ describe('<ExtensionsList />', () => {
it('should render "No extensions installed." if there are no extensions', () => {
mockUIState(new Map());
const { lastFrame } = render(<ExtensionsList extensions={[]} />);
const { lastFrame, unmount } = render(<ExtensionsList extensions={[]} />);
expect(lastFrame()).toContain('No extensions installed.');
unmount();
});
it('should render a list of extensions with their version and status', () => {
mockUIState(new Map());
const { lastFrame } = render(
const { lastFrame, unmount } = render(
<ExtensionsList extensions={mockExtensions} />,
);
const output = lastFrame();
expect(output).toContain('ext-one (v1.0.0) - active');
expect(output).toContain('ext-two (v2.1.0) - active');
expect(output).toContain('ext-disabled (v3.0.0) - disabled');
unmount();
});
it('should display "unknown state" if an extension has no update state', () => {
mockUIState(new Map());
const { lastFrame } = render(
const { lastFrame, unmount } = render(
<ExtensionsList extensions={[mockExtensions[0]]} />,
);
expect(lastFrame()).toContain('(unknown state)');
unmount();
});
const stateTestCases = [
@@ -115,10 +118,11 @@ describe('<ExtensionsList />', () => {
it(`should correctly display the state: ${state}`, () => {
const updateState = new Map([[mockExtensions[0].name, state]]);
mockUIState(updateState);
const { lastFrame } = render(
const { lastFrame, unmount } = render(
<ExtensionsList extensions={[mockExtensions[0]]} />,
);
expect(lastFrame()).toContain(expectedText);
unmount();
});
}
});