test(cli): refactor tests for async render utilities (#23252)

This commit is contained in:
Tommaso Sciortino
2026-03-20 20:08:29 +00:00
committed by GitHub
parent 86a3a913b5
commit 6c78eb7a39
198 changed files with 3592 additions and 4802 deletions

View File

@@ -20,72 +20,65 @@ describe('QuotaDisplay', () => {
vi.unstubAllEnvs();
});
it('should not render when remaining is undefined', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={undefined} limit={100} />,
);
await waitUntilReady();
expect(lastFrame({ allowEmpty: true })).toBe('');
unmount();
});
it('should not render when limit is undefined', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={100} limit={undefined} />,
);
await waitUntilReady();
expect(lastFrame({ allowEmpty: true })).toBe('');
unmount();
});
it('should not render when limit is 0', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={100} limit={0} />,
);
await waitUntilReady();
expect(lastFrame({ allowEmpty: true })).toBe('');
unmount();
});
it('should not render when usage < 80%', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={85} limit={100} />,
);
await waitUntilReady();
expect(lastFrame({ allowEmpty: true })).toBe('');
unmount();
});
it('should render warning when used >= 80%', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={15} limit={100} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('should render critical when used >= 95%', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={4} limit={100} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('should render with reset time when provided', async () => {
const resetTime = new Date(Date.now() + 3600000).toISOString(); // 1 hour from now
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={15} limit={100} resetTime={resetTime} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('should NOT render reset time when terse is true', async () => {
const resetTime = new Date(Date.now() + 3600000).toISOString();
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay
remaining={15}
limit={100}
@@ -93,16 +86,14 @@ describe('QuotaDisplay', () => {
terse={true}
/>,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('should render terse limit reached message', async () => {
const { lastFrame, waitUntilReady, unmount } = render(
const { lastFrame, unmount } = await render(
<QuotaDisplay remaining={0} limit={100} terse={true} />,
);
await waitUntilReady();
expect(lastFrame()).toMatchSnapshot();
unmount();
});