Skip to content

Commit e3ffbc6

Browse files
pzrqSatya
authored andcommitted
COMPASS 301: Hide validation tab for servers < 3.2 (#615)
* COMPASS-301: Only show validation tab for mongod instances > 3.2.0-rc0 * Add <Collection /> test stub Several issues here: 1. _helper.js needs to be named that way so that it is executed first, before other tests. 2. The <Collection /> component has deep dependencies on the app.appRegistry and now also app.instance 3. I can’t see an easy way to mock those components, but will retry as time permits. * Rename NavBarComponent to TabNavBar It’s already named as such elsewhere, and is just confusing for enzyme tests. * Add enzyme tests for the validation tab on different server versions Note: Requires a new showView prop, just for testing for now so the component is actually rendered. * Fix React warning Comes from our super-highly decoupled hadron magic :) Also console.trace() is amazing! * Fix eslint warnings * Go back to tests failing on local npm run test -- --unit * Unit tests pass on local npm run test -- --unit Something upstream is being evil, but I don’t really want to spend the time now to track it down, and I think the test name is clear enough that something bad is going on.
1 parent bf46684 commit e3ffbc6

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

src/internal-packages/app/lib/components/tab-nav-bar.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const React = require('react');
22
const _ = require('lodash');
33
// const debug = require('debug')('mongodb-compass:app:nav-bar');
44

5-
class NavBarComponent extends React.Component {
5+
class TabNavBar extends React.Component {
66

77
constructor(props) {
88
super(props);
@@ -87,7 +87,7 @@ class NavBarComponent extends React.Component {
8787
}
8888
}
8989

90-
NavBarComponent.propTypes = {
90+
TabNavBar.propTypes = {
9191
theme: React.PropTypes.oneOf(['dark', 'light']),
9292
activeTabIndex: React.PropTypes.number,
9393
mountAllViews: React.PropTypes.bool,
@@ -96,12 +96,12 @@ NavBarComponent.propTypes = {
9696
onTabClicked: React.PropTypes.func
9797
};
9898

99-
NavBarComponent.defaultProps = {
99+
TabNavBar.defaultProps = {
100100
theme: 'light',
101101
activeTabIndex: 0,
102102
mountAllViews: true
103103
};
104104

105-
NavBarComponent.displayName = 'NavBarComponent';
105+
TabNavBar.displayName = 'TabNavBar';
106106

107-
module.exports = NavBarComponent;
107+
module.exports = TabNavBar;

src/internal-packages/collection/lib/components/index.jsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const React = require('react');
22
const app = require('ampersand-app');
3+
const semver = require('semver');
34
const toNS = require('mongodb-ns');
45
const NamespaceStore = require('hadron-reflux-store').NamespaceStore;
56

@@ -9,7 +10,7 @@ class Collection extends React.Component {
910

1011
this.state = {
1112
name: '',
12-
showView: false,
13+
showView: this.props.showView || false,
1314
activeTab: 0
1415
};
1516
this.Stats = app.appRegistry.getComponent('CollectionStats.CollectionStats');
@@ -39,20 +40,24 @@ class Collection extends React.Component {
3940
}
4041

4142
showCollection() {
43+
const serverVersion = app.instance.build.version;
44+
const DV_ENABLED = semver.gt(serverVersion, '3.2.0-rc0');
4245
const tabs = [
4346
'SCHEMA',
4447
'DOCUMENTS',
4548
'EXPLAIN PLAN',
46-
'INDEXES',
47-
'VALIDATION'
49+
'INDEXES'
4850
];
4951
const views = [
5052
<this.Schema />,
5153
<this.Document />,
5254
<this.Explain />,
53-
<this.Indexes />,
54-
<this.Validation />
55+
<this.Indexes />
5556
];
57+
if (DV_ENABLED) {
58+
tabs.push('VALIDATION');
59+
views.push(<this.Validation />);
60+
}
5661

5762
return (
5863
<div className="collection-view clearfix">
@@ -83,6 +88,10 @@ class Collection extends React.Component {
8388
}
8489
}
8590

91+
Collection.propTypes = {
92+
showView: React.PropTypes.bool
93+
};
94+
8695
Collection.displayName = 'Collection';
8796

8897
module.exports = Collection;

test/a-babel-global-test-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('babel-register')();

test/collection-component.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* eslint no-unused-vars: 0, no-unused-expressions: 0 */
2+
const app = require('ampersand-app');
3+
const chai = require('chai');
4+
const chaiEnzyme = require('chai-enzyme');
5+
const expect = chai.expect;
6+
const React = require('react');
7+
const sinon = require('sinon');
8+
const shallow = require('enzyme').shallow;
9+
const AppRegistry = require('hadron-app-registry');
10+
const Collection = require('../src/internal-packages/collection/lib/components/index');
11+
const TabNavBar = require('../src/internal-packages/app/lib/components/tab-nav-bar');
12+
13+
// const debug = require('debug')('compass:collection:test');
14+
15+
// use chai-enzyme assertions, see https://github.com/producthunt/chai-enzyme
16+
chai.use(chaiEnzyme());
17+
18+
describe('<Collection />', function() {
19+
let appRegistry = app.appRegistry;
20+
let appInstance = app.instance;
21+
beforeEach(function() {
22+
// Mock the AppRegistry with a new one so tests don't complain about
23+
// appRegistry.getComponent (i.e. appRegistry being undefined)
24+
app.appRegistry = new AppRegistry();
25+
app.appRegistry.registerComponent('App.TabNavBar', TabNavBar);
26+
27+
app.appRegistry.registerComponent('Schema.Schema', sinon.spy());
28+
app.appRegistry.registerComponent('CRUD.DocumentList', sinon.spy());
29+
app.appRegistry.registerComponent('Indexes.Indexes', sinon.spy());
30+
app.appRegistry.registerComponent('Explain.ExplainPlan', sinon.spy());
31+
app.appRegistry.registerComponent('Validation.Validation', sinon.spy());
32+
33+
// Fixes Warning: React.createElement:
34+
// type should not be null, undefined, boolean, or number.
35+
// It should be a string (for DOM elements)
36+
// or a ReactClass (for composite components).
37+
app.appRegistry.registerComponent('CollectionStats.CollectionStats', sinon.spy());
38+
});
39+
afterEach(function() {
40+
// Restore properties on the global app object,
41+
// so they don't affect other tests
42+
app.appRegistry = appRegistry;
43+
app.instance = appInstance;
44+
});
45+
46+
it('has 4 tabs with server version 3.0.6', function() {
47+
app.instance = {build: {version: '3.0.6'}};
48+
const component = shallow(<Collection showView={true} />);
49+
const tabs = component.find(TabNavBar).dive().find('.tab-nav-bar-tab');
50+
expect(tabs).to.have.length(4);
51+
});
52+
it('has 5 tabs inc a validation tab when serverVersion >= 3.2.0', function() {
53+
app.instance = {build: {version: '3.2.0'}};
54+
const component = shallow(<Collection showView={true} />);
55+
const tabs = component.find(TabNavBar).dive().find('.tab-nav-bar-tab');
56+
expect(tabs.find('#VALIDATION')).to.exist;
57+
expect(tabs).to.have.length(5);
58+
});
59+
});

0 commit comments

Comments
 (0)