1import { render, screen } from '@testing-library/react';
2import userEvent from '@testing-library/user-event';
3
4import { Terminal } from '.';
5
6describe(Terminal, () => {
7  it('generates correct copyCmd from single command', async () => {
8    render(
9      <>
10        <Terminal cmd={['$ expo install expo-updates']} />
11        <textarea />
12      </>
13    );
14    expect(screen.getByText('Copy')).toBeVisible();
15
16    const user = userEvent.setup();
17    await user.click(screen.getByText('Copy'));
18    await user.click(screen.getByRole('textbox'));
19    await user.paste();
20
21    expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe(
22      'expo install expo-updates'
23    );
24  });
25
26  it('generates correct copyCmd from single command with comments and blank lines', async () => {
27    render(
28      <>
29        <Terminal
30          cmd={[
31            '# This line is a comment',
32            '',
33            '$ expo install expo-dev-client',
34            '# One more to add!',
35          ]}
36        />
37        <textarea />
38      </>
39    );
40    expect(screen.getByText('Copy')).toBeVisible();
41
42    const user = userEvent.setup();
43    await user.click(screen.getByText('Copy'));
44    await user.click(screen.getByRole('textbox'));
45    await user.paste();
46
47    expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe(
48      'expo install expo-dev-client'
49    );
50  });
51
52  it('do not generate copyCmd if first line is a comment', () => {
53    render(<Terminal cmd={["# We don't want this to generate cmdCopy"]} />);
54    expect(screen.queryByText('Copy')).toBe(null);
55  });
56
57  it('do not generate copyCmd if there is more than one command', () => {
58    render(<Terminal cmd={['$ npx create-expo-app init test', '$ cd test']} />);
59    expect(screen.queryByText('Copy')).toBe(null);
60  });
61});
62