Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/internal-packages/indexes/lib/component/usage-column.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const React = require('react');
const _ = require('lodash');

// const debug = require('debug')('mongodb-compass:indexes:usage-column');

/**
* No usage stats constant.
Expand All @@ -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 (
<div className="usage-since">
since&nbsp;
<span>
{this.props.since ? this.props.since.toDateString() : 'N/A'}
</span>
</div>
);
}

/**
Expand All @@ -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 (
<td className="usage-column">
<span className="usage">
<div className="quantity" title={this.tooltip()}>
{this.props.usage || 'N/A'}
</div>
<div className="usage-since">
since&nbsp;
<span>
{this.props.since ? this.props.since.toDateString() : 'N/A'}
</span>
{usage}
</div>
{this.renderSince()}
</span>
</td>
);
Expand Down
26 changes: 26 additions & 0 deletions test/compass-functional.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});
});
Expand Down
13 changes: 13 additions & 0 deletions test/support/spectron-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

/**
Expand Down