Skip to content

Commit 1ea43dc

Browse files
authored
Merge pull request #75 from oslabs-beta/dev
Dev to master
2 parents 793ec4b + 39fbd22 commit 1ea43dc

27 files changed

+263
-886
lines changed

sapling/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"vscode": "^1.60.0"
1111
},
1212
"categories": [
13-
"Other"
13+
"Visualization"
1414
],
15+
"keywords": ["react", "component hierarchy", "devtools"],
1516
"activationEvents": [
1617
"onStartupFinished"
1718
],
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as assert from 'assert';
1+
import { describe, suite , test, before} from 'mocha';
2+
import { expect } from 'chai';
23

34
// You can import and use all API from the 'vscode' module
45
// as well as import your extension to test it
@@ -8,13 +9,36 @@ import * as vscode from 'vscode';
89
suite('Extension Test Suite', () => {
910
vscode.window.showInformationMessage('Start all tests.');
1011

11-
test('Sample test', () => {
12-
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
13-
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
14-
});
12+
describe('Sapling loads correctly', () => {
13+
let saplingExtension;
14+
before (() => {
15+
saplingExtension = vscode.extensions.getExtension('team-sapling.sapling');
16+
});
1517

16-
test('Sample test 2', () => {
17-
assert.strictEqual(1, 1);
18-
});
18+
test('Sapling is registered as an extension', () => {
19+
expect(saplingExtension).to.not.be.undefined;
20+
});
1921

22+
test('Sapling extension is activated after VSCode startup', () => {
23+
expect(saplingExtension.isActive).to.be.true;
24+
});
25+
26+
test('Sapling extension package.json exists', () => {
27+
expect(saplingExtension.packageJSON).to.not.be.undefined;
28+
});
29+
});
30+
31+
// describe('It registers saplings commands successfully', () => {
32+
// let commandList;
33+
// before( (done) => {
34+
// vscode.commands.getCommands().then(commands => {
35+
// commandList = commands;
36+
// done();
37+
// });
38+
// });
39+
40+
// test('It registers the sapling.generateTree command', () => {
41+
// expect(commandList).to.be.an('array').that.does.include('sapling.generateTree');
42+
// });
43+
// });
2044
});

sapling/src/test/suite/parser.test.ts

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ suite('Parser Test Suite', () => {
8383
tree = parser.parse();
8484
});
8585

86-
test('Should parse destructured imports', () => {
87-
expect(tree.children).to.have.lengthOf(2);
86+
test('Should parse destructured and third party imports', () => {
87+
expect(tree.children).to.have.lengthOf(3);
8888
expect(tree.children[0]).to.have.own.property('name').that.is.oneOf(['Switch', 'Route']);
8989
expect(tree.children[1]).to.have.own.property('name').that.is.oneOf(['Switch', 'Route']);
90+
expect(tree.children[2]).to.have.own.property('name').that.is.equal('Tippy');
91+
9092
});
9193

9294
test('reactRouter should be designated as third party and reactRouter', () => {
@@ -97,10 +99,28 @@ suite('Parser Test Suite', () => {
9799
expect(tree.children[1]).to.have.own.property('reactRouter').to.be.true;
98100
});
99101

100-
//test for third party without reactRouter
102+
test('Tippy should be designated as third party and not reactRouter', () => {
103+
expect(tree.children[2]).to.have.own.property('thirdParty').to.be.true;
104+
expect(tree.children[2]).to.have.own.property('reactRouter').to.be.false;
105+
});
101106
});
102107

103-
// TEST 3: WOBBEGAINZ
108+
// TEST 3: IDENTIFIES REDUX STORE CONNECTION
109+
describe('It identifies a Redux store connection and designates the component as such', () => {
110+
before(() => {
111+
file = path.join(__dirname, '../../../src/test/test_apps/test_3/index.js');
112+
parser = new SaplingParser(file);
113+
tree = parser.parse();
114+
});
115+
116+
test('The reduxConnect properties of the connected component and the unconnected component should be true and false, respectively', () => {
117+
expect(tree.children[1].children[0].name).to.equal('ConnectedContainer');
118+
expect(tree.children[1].children[0]).to.have.own.property('reduxConnect').that.is.true;
119+
120+
expect(tree.children[1].children[1].name).to.equal('UnconnectedContainer');
121+
expect(tree.children[1].children[1]).to.have.own.property('reduxConnect').that.is.false;
122+
});
123+
});
104124

105125
// TEST 4: ALIASED IMPORTS
106126
describe('It works for aliases', () => {
@@ -156,7 +176,7 @@ suite('Parser Test Suite', () => {
156176
});
157177
});
158178

159-
// TEST 6: Bad import of App2 from App1 Component
179+
// TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
160180
describe('It works for badly imported children nodes', () => {
161181
before(() => {
162182
file = path.join(__dirname, '../../../src/test/test_apps/test_6/index.js');
@@ -170,7 +190,7 @@ suite('Parser Test Suite', () => {
170190
});
171191
});
172192

173-
// TEST 7: Syntax error in app file causes parser error
193+
// TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
174194
describe('It should log an error when the parser encounters a javascript syntax error', () => {
175195
before(() => {
176196
file = path.join(__dirname, '../../../src/test/test_apps/test_7/index.js');
@@ -185,14 +205,33 @@ suite('Parser Test Suite', () => {
185205
});
186206
});
187207

188-
// Test 8: Props check
208+
// TEST 8: MULTIPLE PROPS ON ONE COMPONENT
189209
describe('It should properly count repeat components and consolidate and grab their props', () => {
190210
before(() => {
191211
file = path.join(__dirname, '../../../src/test/test_apps/test_8/index.js');
192212
parser = new SaplingParser(file);
193213
tree = parser.parse();
194214
});
195215

216+
test('Grandchild should have a count of 1', () => {
217+
expect(tree.children[0].children[0]).to.have.own.property('count').that.equals(1);
218+
});
219+
220+
test('Grandchild should have the correct three props', () => {
221+
expect(tree.children[0].children[0].props).has.own.property('prop1').that.is.true;
222+
expect(tree.children[0].children[0].props).has.own.property('prop2').that.is.true;
223+
expect(tree.children[0].children[0].props).has.own.property('prop3').that.is.true;
224+
});
225+
});
226+
227+
// TEST 9: FINDING DIFFERENT PROPS ACROSS TWO OR MORE IDENTICAL COMPONENTS
228+
describe('It should properly count repeat components and consolidate and grab their props', () => {
229+
before(() => {
230+
file = path.join(__dirname, '../../../src/test/test_apps/test_9/index.js');
231+
parser = new SaplingParser(file);
232+
tree = parser.parse();
233+
});
234+
196235
test('Grandchild should have a count of 2', () => {
197236
expect(tree.children[0].children[0]).to.have.own.property('count').that.equals(2);
198237
});
@@ -203,7 +242,7 @@ suite('Parser Test Suite', () => {
203242
});
204243
});
205244

206-
// Test 10: check children works and component works
245+
// TEST 10: CHECK CHILDREN WORKS AND COMPONENTS WORK
207246
describe('It should render children when children are rendered as values of prop called component', () => {
208247
before(() => {
209248
file = path.join(__dirname, '../../../src/test/test_apps/test_10/index.jsx');
@@ -219,4 +258,28 @@ suite('Parser Test Suite', () => {
219258
expect(tree.children[1].children[4]).to.have.own.property('name').that.is.equal('HistoryDisplay');
220259
});
221260
});
261+
262+
// TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS
263+
describe('It should render the second call of mutually recursive components, but no further', () => {
264+
before(() => {
265+
file = path.join(__dirname, '../../../src/test/test_apps/test_11/index.js');
266+
parser = new SaplingParser(file);
267+
tree = parser.parse();
268+
});
269+
270+
test('Tree should not be undefined', () => {
271+
expect(tree).to.not.be.undefined;
272+
});
273+
274+
test('Tree should have an index component while child App1, grandchild App2, great-grandchild App1', () => {
275+
expect(tree).to.have.own.property('name').that.is.equal('index');
276+
expect(tree.children).to.have.lengthOf(1);
277+
expect(tree.children[0]).to.have.own.property('name').that.is.equal('App1');
278+
expect(tree.children[0].children).to.have.lengthOf(1);
279+
expect(tree.children[0].children[0]).to.have.own.property('name').that.is.equal('App2');
280+
expect(tree.children[0].children[0].children).to.have.lengthOf(1);
281+
expect(tree.children[0].children[0].children[0]).to.have.own.property('name').that.is.equal('App1');
282+
expect(tree.children[0].children[0].children[0].children).to.have.lengthOf(0);
283+
});
284+
});
222285
});

sapling/src/test/test_apps/test_2/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { render } from 'react-dom';
33
import { Switch, Route } from 'react-router-dom';
4+
import Tippy from 'tippy';
45

56
// TEST 2 - Third Party Components, Destructuring Import
67

@@ -9,5 +10,6 @@ render(
910
<Switch >
1011
<Route component={App}>
1112
</Route>
13+
<Tippy />
1214
</Switch>
1315
</div>, document.getElementById('root'));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { Component } from 'react';
2+
import ConnectedContainer from './containers/ConnectedContainer'
3+
import UnconnectedContainer from './containers/UnconnectedContainer'
4+
5+
6+
class App extends Component {
7+
constructor(props) {
8+
super(props);
9+
}
10+
11+
render() {
12+
return (
13+
<div>
14+
<ConnectedContainer />
15+
<UnconnectedContainer />
16+
</div>
17+
);
18+
}
19+
}
20+
21+
export default App;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as types from '../constants/actionTypes';
2+
3+
export const fakeAction1Creator = () => ({
4+
type: types.FAKE_ACTION_1,
5+
});
6+
7+
export const fakeAction2Creator = () => ({
8+
type: types.FAKE_ACTION_2,
9+
});
10+

sapling/src/test/test_apps/test_3/components/App.jsx

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)