diff --git a/src/internal-packages/indexes/lib/component/usage-column.jsx b/src/internal-packages/indexes/lib/component/usage-column.jsx index 72729a72704..ff3c1b7f661 100644 --- a/src/internal-packages/indexes/lib/component/usage-column.jsx +++ b/src/internal-packages/indexes/lib/component/usage-column.jsx @@ -1,4 +1,7 @@ const React = require('react'); +const _ = require('lodash'); + +// const debug = require('debug')('mongodb-compass:indexes:usage-column'); /** * No usage stats constant. @@ -16,10 +19,24 @@ class UsageColumn extends React.Component { * @returns {String} The tooltip. */ tooltip() { - if (this.props.usage) { - return `${this.props.usage} index hits since index creation or last\n server restart`; + if (_.isUndefined(this.props.usage)) { + return NO_USAGE_STATS; + } + return `${this.props.usage} index hits since index creation or last\n server restart`; + } + + renderSince() { + if (_.isUndefined(this.props.since)) { + return null; } - return NO_USAGE_STATS; + return ( +
+ since  + + {this.props.since ? this.props.since.toDateString() : 'N/A'} + +
+ ); } /** @@ -28,18 +45,14 @@ class UsageColumn extends React.Component { * @returns {React.Component} The usage column. */ render() { + const usage = _.isUndefined(this.props.usage) ? 'N/A' : this.props.usage; return (
- {this.props.usage || 'N/A'} -
-
- since  - - {this.props.since ? this.props.since.toDateString() : 'N/A'} - + {usage}
+ {this.renderSince()}
); diff --git a/test/compass-functional.test.js b/test/compass-functional.test.js index e1503370e90..95b18b7cf7c 100644 --- a/test/compass-functional.test.js +++ b/test/compass-functional.test.js @@ -182,6 +182,32 @@ describe('Compass #spectron', function() { .eventually .include('_id_'); }); + it('shows a number in the usage column', function() { + return client + .getText('span.usage div.quantity') + .should + .eventually + .match(/\d+/); + }); + it('open create index', function() { + return client.selectCreateIndex() + .getText('h4.modal-title') + .should + .eventually + .include('Create Index'); + }); + it('try empty create index', function() { + return client.submitCreateIndexForm() + .getText('.modal-status-error-message') + .should + .eventually + .include('You must select a field name and type'); + }); + // @KeyboardTsundoku it would be great to have test that creates an + // index here + it('close create index', function() { + return client.cancelCreateIndexForm(); // test required here + }); }); }); }); diff --git a/test/support/spectron-support.js b/test/support/spectron-support.js index a758bbee392..07f2c9c20d7 100644 --- a/test/support/spectron-support.js +++ b/test/support/spectron-support.js @@ -225,6 +225,19 @@ function addCommands(client) { .waitForVisible('#statusbar', ms) .waitForVisible('#statusbar', ms, true); }); + + client.addCommand('selectCreateIndex', function() { + return this.click('.create-index-btn button').waitForVisible('h4.modal-title', 15000); + }); + + client.addCommand('submitCreateIndexForm', function() { + this.click('#field-name-select-dropdown'); + return this.submitForm('.modal-body form'); + }); + + client.addCommand('cancelCreateIndexForm', function() { + return this.click('.create-index-confirm-buttons-cancel'); + }); } /**