Skip to content

Commit

Permalink
test(cat): add integration test for cat and images
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaylo21 committed Dec 23, 2019
1 parent 74bdf6f commit 9042720
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ exports[`cat should show error when cat on invalid path 1`] = `"<li><div id=\\"i
exports[`cat should show error when cat on non file 1`] = `"<li><div id=\\"input-container\\" spellcheck=\\"false\\"><form><span data-testid=\\"input-prompt-path\\">/</span>&nbsp;<span id=\\"inputPrompt\\">$&gt;</span><input aria-label=\\"terminal-input\\" type=\\"text\\" readonly=\\"\\" value=\\"cat home\\"></form></div><span class=\\"commandResult\\">Error: Target is not a file</span></li>"`;
exports[`cat should support cat on images 1`] = `"<li><div id=\\"input-container\\" spellcheck=\\"false\\"><form><span data-testid=\\"input-prompt-path\\">/</span>&nbsp;<span id=\\"inputPrompt\\">$&gt;</span><input aria-label=\\"terminal-input\\" type=\\"text\\" readonly=\\"\\" value=\\"cat home/dog.png\\"></form></div><span class=\\"commandResult\\"><img src=\\"abc/dog.png\\"></span></li>"`;
exports[`cd should cd one level 1`] = `"<li><div id=\\"input-container\\" spellcheck=\\"false\\"><form><span data-testid=\\"input-prompt-path\\">/</span>&nbsp;<span id=\\"inputPrompt\\">$&gt;</span><input aria-label=\\"terminal-input\\" type=\\"text\\" readonly=\\"\\" value=\\"cd home\\"></form></div><span class=\\"commandResult\\"></span></li>"`;
exports[`cd should handle invalid cd 1`] = `"<li><div id=\\"input-container\\" spellcheck=\\"false\\"><form><span data-testid=\\"input-prompt-path\\">/</span>&nbsp;<span id=\\"inputPrompt\\">$&gt;</span><input aria-label=\\"terminal-input\\" type=\\"text\\" readonly=\\"\\" value=\\"cd invalid\\"></form></div><span class=\\"commandResult\\">Error: path does not exist: invalid</span></li>"`;
Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import {
} from '@testing-library/react';
import { Terminal } from '..';
import exampleFileSystem from '../data/exampleFileSystem';
jest.mock('../../images/dog.png', () => 'abc/dog.png');

beforeAll((): void => {
Element.prototype.scrollIntoView = jest.fn();
});

afterEach(cleanup);

afterAll(() => {
jest.clearAllMocks();
});

describe('initialization', (): void => {
test('custom input prompt', async (): Promise<void> => {
const { getByText } = render(
Expand Down Expand Up @@ -493,6 +498,22 @@ describe('cat', (): void => {

expect(history.innerHTML).toMatchSnapshot();
});

test('should support cat on images', async (): Promise<void> => {
const { container, getByLabelText } = render(
<Terminal fileSystem={exampleFileSystem} />,
);

const input = getByLabelText('terminal-input');

fireEvent.change(input, { target: { value: 'cat home/dog.png' } });
fireEvent.submit(input);

const history = await findByLabelText(container, 'terminal-history');

expect(history.innerHTML).toContain('<img src="abc/dog.png">');
expect(history.innerHTML).toMatchSnapshot();
});
});

describe('history', (): void => {
Expand Down

0 comments on commit 9042720

Please sign in to comment.