@@ -11,6 +11,7 @@ import userEvent from '@testing-library/user-event';
11
11
import { expect } from 'chai' ;
12
12
import Sinon from 'sinon' ;
13
13
import { DatabasesNavigationTree } from './databases-navigation-tree' ;
14
+ import preferencesAccess from 'compass-preferences-model' ;
14
15
15
16
const databases = [
16
17
{
@@ -42,6 +43,60 @@ const TEST_VIRTUAL_PROPS = {
42
43
describe ( 'DatabasesNavigationTree' , function ( ) {
43
44
afterEach ( cleanup ) ;
44
45
46
+ context ( 'when the rename collection feature flag is enabled' , ( ) => {
47
+ const sandbox = Sinon . createSandbox ( ) ;
48
+ before ( ( ) => {
49
+ sandbox . stub ( preferencesAccess , 'getPreferences' ) . returns ( {
50
+ enableRenameCollectionModal : true ,
51
+ } as any ) ;
52
+ } ) ;
53
+
54
+ after ( ( ) => sandbox . restore ( ) ) ;
55
+
56
+ it ( 'shows the Rename Collection action' , function ( ) {
57
+ render (
58
+ < DatabasesNavigationTree
59
+ databases = { databases }
60
+ expanded = { { bar : true } }
61
+ activeNamespace = "bar.meow"
62
+ onDatabaseExpand = { ( ) => { } }
63
+ onNamespaceAction = { ( ) => { } }
64
+ { ...TEST_VIRTUAL_PROPS }
65
+ > </ DatabasesNavigationTree >
66
+ ) ;
67
+
68
+ const collection = screen . getByTestId ( 'sidebar-collection-bar.meow' ) ;
69
+ const showActionsButton = within ( collection ) . getByTitle ( 'Show actions' ) ;
70
+
71
+ expect ( within ( collection ) . getByTitle ( 'Show actions' ) ) . to . exist ;
72
+
73
+ userEvent . click ( showActionsButton ) ;
74
+
75
+ expect ( screen . getByText ( 'Rename collection' ) ) . to . exist ;
76
+ } ) ;
77
+
78
+ it ( 'should activate callback with `rename-collection` when corresponding action is clicked' , function ( ) {
79
+ const spy = Sinon . spy ( ) ;
80
+ render (
81
+ < DatabasesNavigationTree
82
+ databases = { databases }
83
+ expanded = { { bar : true } }
84
+ activeNamespace = "bar.meow"
85
+ onNamespaceAction = { spy }
86
+ onDatabaseExpand = { ( ) => { } }
87
+ { ...TEST_VIRTUAL_PROPS }
88
+ > </ DatabasesNavigationTree >
89
+ ) ;
90
+
91
+ const collection = screen . getByTestId ( 'sidebar-collection-bar.meow' ) ;
92
+
93
+ userEvent . click ( within ( collection ) . getByTitle ( 'Show actions' ) ) ;
94
+ userEvent . click ( screen . getByText ( 'Rename collection' ) ) ;
95
+
96
+ expect ( spy ) . to . be . calledOnceWithExactly ( 'bar.meow' , 'rename-collection' ) ;
97
+ } ) ;
98
+ } ) ;
99
+
45
100
it ( 'should render databases' , function ( ) {
46
101
render (
47
102
< DatabasesNavigationTree
@@ -166,6 +221,7 @@ describe('DatabasesNavigationTree', function () {
166
221
userEvent . click ( showActionsButton ) ;
167
222
168
223
expect ( screen . getByText ( 'Open in new tab' ) ) . to . exist ;
224
+ expect ( ( ) => screen . getByText ( 'Rename collection' ) ) . to . throw ;
169
225
expect ( screen . getByText ( 'Drop collection' ) ) . to . exist ;
170
226
} ) ;
171
227
@@ -192,6 +248,9 @@ describe('DatabasesNavigationTree', function () {
192
248
expect ( screen . getByText ( 'Drop view' ) ) . to . exist ;
193
249
expect ( screen . getByText ( 'Duplicate view' ) ) . to . exist ;
194
250
expect ( screen . getByText ( 'Modify view' ) ) . to . exist ;
251
+
252
+ // views cannot be renamed
253
+ expect ( ( ) => screen . getByText ( 'Rename collection' ) ) . to . throw ;
195
254
} ) ;
196
255
} ) ;
197
256
0 commit comments