-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathshell-content.spec.tsx
66 lines (55 loc) · 1.87 KB
/
shell-content.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import { expect } from '../../testing/chai';
import { screen, render, waitFor, cleanup } from '@testing-library/react';
import type { ShellOutputEntry } from './shell-output-line';
import { ShellContent } from './shell-content';
function WrappedShellOutput(props: Partial<React.ComponentProps<typeof ShellContent>>) {
return (
<div style={{ height: '200px' }}>
<ShellContent
output={[]}
InputPrompt={<div />}
__TEST_LIST_HEIGHT={200}
{...props}
/>
</div>
);
}
describe('<ShellContent />', function () {
beforeEach(cleanup);
it('renders no output lines if none are passed', function () {
render(<WrappedShellOutput output={[]} />);
expect(screen.queryByTestId('shell-output-line')).to.not.exist;
});
it('renders an output line if one is passed', function () {
const line1: ShellOutputEntry = {
type: 'output',
value: 'line 1',
format: 'output',
};
render(<WrappedShellOutput output={[line1]} />);
expect(screen.getByText(/line 1/i)).to.exist;
expect(screen.getAllByTestId('shell-output-line')).to.have.lengthOf(1);
});
it('scrolls to the newly added item', async function () {
const output: ShellOutputEntry[] = Array.from({ length: 100 }, (_, i) => ({
type: 'output',
value: `line ${i}`,
format: 'output',
}));
const { rerender } = render(<WrappedShellOutput output={output} />);
const newLine: ShellOutputEntry = {
type: 'output',
value: 'new line',
format: 'output',
};
rerender(<WrappedShellOutput output={[...output, newLine]} />);
await waitFor(() => {
expect(screen.getByText(/new line/i)).to.exist;
});
});
it('renders input prompt', function () {
render(<WrappedShellOutput InputPrompt={<p>Enter here</p>} />);
expect(screen.getByText(/enter here/i)).to.exist;
});
});