@@ -6,31 +6,38 @@ import {
6
6
WorkspacesServiceProvider ,
7
7
type WorkspacesService ,
8
8
} from '@mongodb-js/compass-workspaces/provider' ;
9
- import CollectionHeaderActions from '../collection-header-actions' ;
9
+ import type { PreferencesAccess } from 'compass-preferences-model' ;
10
+ import { createSandboxFromDefaultPreferences } from 'compass-preferences-model' ;
11
+ import { PreferencesProvider } from 'compass-preferences-model/provider' ;
10
12
11
- function renderCollectionHeaderActions (
12
- props : Partial < ComponentProps < typeof CollectionHeaderActions > > = { } ,
13
- workspaceService : Partial < WorkspacesService > = { }
14
- ) {
15
- return render (
16
- < WorkspacesServiceProvider value = { workspaceService as WorkspacesService } >
17
- < CollectionHeaderActions
18
- namespace = "test.test"
19
- isReadonly = { false }
20
- { ...props }
21
- />
22
- </ WorkspacesServiceProvider >
23
- ) ;
24
- }
13
+ import CollectionHeaderActions from '../collection-header-actions' ;
25
14
26
15
describe ( 'CollectionHeaderActions [Component]' , function ( ) {
27
- let sandbox : sinon . SinonSandbox ;
28
- beforeEach ( function ( ) {
29
- sandbox = sinon . createSandbox ( ) ;
16
+ let preferences : PreferencesAccess ;
17
+ beforeEach ( async function ( ) {
18
+ preferences = await createSandboxFromDefaultPreferences ( ) ;
30
19
} ) ;
31
- this . afterEach ( function ( ) {
32
- sandbox . restore ( ) ;
20
+ afterEach ( function ( ) {
21
+ sinon . restore ( ) ;
33
22
} ) ;
23
+
24
+ const renderCollectionHeaderActions = (
25
+ props : Partial < ComponentProps < typeof CollectionHeaderActions > > = { } ,
26
+ workspaceService : Partial < WorkspacesService > = { }
27
+ ) => {
28
+ return render (
29
+ < WorkspacesServiceProvider value = { workspaceService as WorkspacesService } >
30
+ < PreferencesProvider value = { preferences } >
31
+ < CollectionHeaderActions
32
+ namespace = "test.test"
33
+ isReadonly = { false }
34
+ { ...props }
35
+ />
36
+ </ PreferencesProvider >
37
+ </ WorkspacesServiceProvider >
38
+ ) ;
39
+ } ;
40
+
34
41
context ( 'when the collection is not readonly' , function ( ) {
35
42
beforeEach ( function ( ) {
36
43
renderCollectionHeaderActions ( {
@@ -52,10 +59,43 @@ describe('CollectionHeaderActions [Component]', function () {
52
59
} ) ;
53
60
} ) ;
54
61
62
+ context ( 'Compass readonly mode' , function ( ) {
63
+ it ( 'does not render edit view buttons when in readonly mode' , async function ( ) {
64
+ await preferences . savePreferences ( { readOnly : true } ) ;
65
+
66
+ renderCollectionHeaderActions ( {
67
+ isReadonly : true ,
68
+ namespace : 'db.coll2' ,
69
+ sourceName : 'db.someSource' ,
70
+ sourcePipeline : [ { $match : { a : 1 } } ] ,
71
+ } ) ;
72
+
73
+ expect (
74
+ screen . queryByTestId ( 'collection-header-actions-edit-button' )
75
+ ) . to . not . exist ;
76
+ expect (
77
+ screen . queryByTestId ( 'collection-header-actions-return-to-view-button' )
78
+ ) . to . not . exist ;
79
+ } ) ;
80
+
81
+ it ( 'renders edit view buttons when not in readonly mode' , function ( ) {
82
+ renderCollectionHeaderActions ( {
83
+ isReadonly : true ,
84
+ namespace : 'db.coll2' ,
85
+ sourceName : 'db.someSource' ,
86
+ sourcePipeline : [ { $match : { a : 1 } } ] ,
87
+ } ) ;
88
+
89
+ expect (
90
+ screen . getByTestId ( 'collection-header-actions-edit-button' )
91
+ ) . to . be . visible ;
92
+ } ) ;
93
+ } ) ;
94
+
55
95
context ( 'when the collection is a view' , function ( ) {
56
96
let openEditViewWorkspaceStub : sinon . SinonStub ;
57
97
beforeEach ( function ( ) {
58
- openEditViewWorkspaceStub = sandbox . stub ( ) ;
98
+ openEditViewWorkspaceStub = sinon . stub ( ) ;
59
99
renderCollectionHeaderActions (
60
100
{
61
101
isReadonly : true ,
@@ -96,7 +136,7 @@ describe('CollectionHeaderActions [Component]', function () {
96
136
context ( 'when the collection is editing a view' , function ( ) {
97
137
let openCollectionWorkspaceStub : sinon . SinonStub ;
98
138
beforeEach ( function ( ) {
99
- openCollectionWorkspaceStub = sandbox . stub ( ) ;
139
+ openCollectionWorkspaceStub = sinon . stub ( ) ;
100
140
renderCollectionHeaderActions (
101
141
{
102
142
isReadonly : false ,
0 commit comments