|
| 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