Skip to content

Testing for editor #950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions client/modules/IDE/components/__test__/FileNode.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';
import { FileNode } from '../FileNode';


describe('FileNode', () => {
const props = {
id: '123456',
parentId: 'abcdef',
children: [],
name: 'test.js',
fileType: 'file',
isSelectedFile: false,
isFolderClosed: false,
setSelectedFile: jest.fn(),
deleteFile: jest.fn(),
updateFileName: jest.fn(),
resetSelectedFile: jest.fn(),
newFile: jest.fn(),
newFolder: jest.fn(),
showFolderChildren: jest.fn(),
hideFolderChildren: jest.fn(),
canEdit: false
};

it('it renders file node', () => {
const getWrapper = () => shallow(<FileNode {...props} />);
const filenode = getWrapper();
expect(filenode.exists('.file-item__content')).toEqual(true);
});

it('check selected file node displayed', () => {
const getWrapper = () => shallow(<FileNode {...props} isSelectedFile />);
const filenode = getWrapper();
expect(filenode.exists('.sidebar__file-item--selected')).toEqual(true);
});

it('check selection of file on click', () => {
const getWrapper = () => shallow(<FileNode {...props} isSelectedFile />);
const fileNode = getWrapper();
const nameButton = fileNode.find('.sidebar__file-item-name');
nameButton.simulate('click', { stopPropagation() {} });
expect(fileNode.exists('.sidebar__file-item--selected')).toEqual(true);
});

it('renders correctly', () => {
const tree = renderer
.create(<FileNode {...props} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`FileNode renders correctly 1`] = `
<div
className="sidebar__file-item"
>
<div
className="file-item__content"
onContextMenu={[Function]}
>
<span
className="file-item__spacer"
/>
<span
className="sidebar__file-item-icon"
>
<span
className="isvg loading"
/>
</span>
<button
className="sidebar__file-item-name"
onClick={[Function]}
>
test.js
</button>
<input
className="sidebar__file-item-input"
onBlur={[Function]}
onChange={[Function]}
onKeyPress={[Function]}
type="text"
value="test.js"
/>
<button
aria-label="view file options"
className="sidebar__file-item-show-options"
onBlur={[Function]}
onClick={[Function]}
tabIndex="0"
>
<span
className="isvg loading"
/>
</button>
<div
className="sidebar__file-item-options"
>
<ul
title="file options"
>
<li>
<button
className="sidebar__file-item-option"
onClick={[Function]}
>
Rename
</button>
</li>
<li>
<button
className="sidebar__file-item-option"
onClick={[Function]}
>
Delete
</button>
</li>
</ul>
</div>
</div>
<ul
className="file-item__children"
/>
</div>
`;
37 changes: 37 additions & 0 deletions client/modules/IDE/reducers/__test__/ide.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ide from '../ide';
import * as actions from '../../../../constants';

const initialState = {
isPlaying: false,
isAccessibleOutputPlaying: false,
modalIsVisible: false,
sidebarIsExpanded: false,
consoleIsExpanded: true,
preferencesIsVisible: false,
projectOptionsVisible: false,
newFolderModalVisible: false,
shareModalVisible: false,
editorOptionsVisible: false,
keyboardShortcutVisible: false,
unsavedChanges: false,
infiniteLoop: false,
previewIsRefreshing: false,
infiniteLoopMessage: '',
justOpenedProject: false,
previousPath: '/',
errorType: undefined,
runtimeErrorWarningVisible: true,
};

describe('ide reducer', () => {
it('should return the initial state', () => {
expect(ide(undefined, {})).toEqual(initialState);
});

it('should handle START_SKETCH', () => {
const startSketch = {
type: actions.START_SKETCH
};
expect(ide({}, startSketch)).toEqual({ isPlaying: true });
});
});