Skip to content

Commit e80b764

Browse files
committed
add tests
1 parent 4727697 commit e80b764

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

__mocks__/browser-mocks.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
function getSelection() {
3+
return {
4+
containsNode: function () { return false; }
5+
};
6+
}
7+
8+
Object.defineProperty(window, 'getSelection', {
9+
value: getSelection
10+
});

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"css-loader": "^0.23.1",
7575
"electron": "^1.4.6",
7676
"electron-builder": "7.24.1",
77+
"enzyme": "^2.6.0",
7778
"eslint": "^2.7.0",
7879
"eslint-loader": "^1.3.0",
7980
"eslint-plugin-react": "^5.0.1",
@@ -158,10 +159,16 @@
158159
"yargs": "^4.6.0"
159160
},
160161
"jest": {
162+
"bail": true,
163+
"collectCoverage": true,
164+
"collectCoverageFrom": [
165+
"src/browser/jsx/**/*{.js,.jsx}"
166+
],
161167
"moduleNameMapper": {
162168
"^ace$": "<rootDir>/__mocks__/ace.js",
163169
"(raw!.*|.*css|.*yml|.*md)": "<rootDir>/__mocks__/generic-stub.js"
164170
},
171+
"setupFiles":["<rootDir>/__mocks__/browser-mocks.js"],
165172
"testRegex": "/src/browser/.*\\.test\\.js$"
166173
}
167174
}

src/browser/jsx/containers/prompt-viewer/prompt-viewer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import _ from 'lodash';
22
import React from 'react';
33
import Prompt from '../../components/prompt/prompt';
44
import commonReact from '../../services/common-react';
5-
import defaultCommands from './default-commands.yml';
65
import client from '../../services/jupyter/client';
76
import promptUtils from '../../services/util/prompt-util';
87
import textUtil from '../../services/text-util';
8+
import defaultCommands from './default-commands.yml';
99

1010
function getTargetCommand(event) {
1111
const key = event.key,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* globals describe, it, expect, jest */
2+
3+
jest.mock('./default-commands.yml', function () {
4+
return {keyDown: [], keyDownByOS: [], keyPress: []};
5+
});
6+
7+
import _ from 'lodash';
8+
import React from 'react';
9+
import ReactDOM from 'react-dom';
10+
import TestUtils from 'react-addons-test-utils';
11+
import PromptViewer from './prompt-viewer';
12+
import { mount } from 'enzyme';
13+
14+
describe(__filename, () => {
15+
it('renders', () => {
16+
const handleNoop = _.noop,
17+
reactDocument = TestUtils.renderIntoDocument(
18+
<PromptViewer
19+
onAutocomplete={handleNoop}
20+
onCommand={handleNoop}
21+
onExecute={handleNoop}
22+
onInput={handleNoop}
23+
/>
24+
),
25+
el = ReactDOM.findDOMNode(reactDocument);
26+
27+
expect(el.className).toEqual('prompt prompt-viewer');
28+
});
29+
30+
it('supports international keys using alt and shift 1', () => {
31+
const handleNoop = _.noop,
32+
handleCommand = jest.fn(() => true),
33+
wrapper = mount(
34+
<PromptViewer
35+
onAutocomplete={handleNoop}
36+
onCommand={handleCommand}
37+
onExecute={handleNoop}
38+
onInput={handleNoop}
39+
/>
40+
);
41+
42+
wrapper.find('.prompt-viewer').simulate('keyPress', {
43+
key: '[',
44+
altKey: true,
45+
ctrlKey: false,
46+
metaKey: false,
47+
shiftKey: true
48+
});
49+
50+
expect(handleCommand).toBeCalledWith({name: 'insertKey', key: '['});
51+
});
52+
});

src/browser/jsx/services/common-tabs-actions.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import _ from 'lodash';
2-
import reselect from 'reselect';
32

43
/**
54
* @param {[object]} groups

src/browser/jsx/services/common-tabs-actions.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ describe(__filename, function () {
7070
tabGroupName = 'someTabGroup',
7171
contentType = 'c';
7272

73-
console.log('start');
74-
7573
let result = lib.isTabContentTypeInWindowList(contentType, windowList, tabGroupName);
7674

7775
expect(result).toEqual(true);

0 commit comments

Comments
 (0)