File tree Expand file tree Collapse file tree 3 files changed +62
-10
lines changed
src/internal-packages/indexes/lib/component Expand file tree Collapse file tree 3 files changed +62
-10
lines changed Original file line number Diff line number Diff line change 11const React = require ( 'react' ) ;
2+ const _ = require ( 'lodash' ) ;
3+
4+ // const debug = require('debug')('mongodb-compass:indexes:usage-column');
25
36/**
47 * No usage stats constant.
@@ -16,10 +19,24 @@ class UsageColumn extends React.Component {
1619 * @returns {String } The tooltip.
1720 */
1821 tooltip ( ) {
19- if ( this . props . usage ) {
20- return `${ this . props . usage } index hits since index creation or last\n server restart` ;
22+ if ( _ . isUndefined ( this . props . usage ) ) {
23+ return NO_USAGE_STATS ;
24+ }
25+ return `${ this . props . usage } index hits since index creation or last\n server restart` ;
26+ }
27+
28+ renderSince ( ) {
29+ if ( _ . isUndefined ( this . props . since ) ) {
30+ return null ;
2131 }
22- return NO_USAGE_STATS ;
32+ return (
33+ < div className = "usage-since" >
34+ since
35+ < span >
36+ { this . props . since ? this . props . since . toDateString ( ) : 'N/A' }
37+ </ span >
38+ </ div >
39+ ) ;
2340 }
2441
2542 /**
@@ -28,18 +45,14 @@ class UsageColumn extends React.Component {
2845 * @returns {React.Component } The usage column.
2946 */
3047 render ( ) {
48+ const usage = _ . isUndefined ( this . props . usage ) ? 'N/A' : this . props . usage ;
3149 return (
3250 < td className = "usage-column" >
3351 < span className = "usage" >
3452 < div className = "quantity" title = { this . tooltip ( ) } >
35- { this . props . usage || 'N/A' }
36- </ div >
37- < div className = "usage-since" >
38- since
39- < span >
40- { this . props . since ? this . props . since . toDateString ( ) : 'N/A' }
41- </ span >
53+ { usage }
4254 </ div >
55+ { this . renderSince ( ) }
4356 </ span >
4457 </ td >
4558 ) ;
Original file line number Diff line number Diff line change @@ -182,6 +182,32 @@ describe('Compass #spectron', function() {
182182 . eventually
183183 . include ( '_id_' ) ;
184184 } ) ;
185+ it ( 'shows a number in the usage column' , function ( ) {
186+ return client
187+ . getText ( 'span.usage div.quantity' )
188+ . should
189+ . eventually
190+ . match ( / \d + / ) ;
191+ } ) ;
192+ it ( 'open create index' , function ( ) {
193+ return client . selectCreateIndex ( )
194+ . getText ( 'h4.modal-title' )
195+ . should
196+ . eventually
197+ . include ( 'Create Index' ) ;
198+ } ) ;
199+ it ( 'try empty create index' , function ( ) {
200+ return client . submitCreateIndexForm ( )
201+ . getText ( '.modal-status-error-message' )
202+ . should
203+ . eventually
204+ . include ( 'You must select a field name and type' ) ;
205+ } ) ;
206+ // @KeyboardTsundoku it would be great to have test that creates an
207+ // index here
208+ it ( 'close create index' , function ( ) {
209+ return client . cancelCreateIndexForm ( ) ; // test required here
210+ } ) ;
185211 } ) ;
186212 } ) ;
187213 } ) ;
Original file line number Diff line number Diff line change @@ -225,6 +225,19 @@ function addCommands(client) {
225225 . waitForVisible ( '#statusbar' , ms )
226226 . waitForVisible ( '#statusbar' , ms , true ) ;
227227 } ) ;
228+
229+ client . addCommand ( 'selectCreateIndex' , function ( ) {
230+ return this . click ( '.create-index-btn button' ) . waitForVisible ( 'h4.modal-title' , 15000 ) ;
231+ } ) ;
232+
233+ client . addCommand ( 'submitCreateIndexForm' , function ( ) {
234+ this . click ( '#field-name-select-dropdown' ) ;
235+ return this . submitForm ( '.modal-body form' ) ;
236+ } ) ;
237+
238+ client . addCommand ( 'cancelCreateIndexForm' , function ( ) {
239+ return this . click ( '.create-index-confirm-buttons-cancel' ) ;
240+ } ) ;
228241}
229242
230243/**
You can’t perform that action at this time.
0 commit comments