@@ -4,6 +4,7 @@ import { ThemeProvider } from '@mui/material/styles';
4
4
import { Provider } from 'react-redux' ;
5
5
import React from 'react' ;
6
6
import createMockStore from 'redux-mock-store' ;
7
+ import { ManagedGroupMembershipEntry } from 'src/models/group' ;
7
8
import history from '../../modules/hist' ;
8
9
import globalTheme from '../../modules/theme' ;
9
10
import SnapshotAccess from './SnapshotAccess' ;
@@ -37,21 +38,34 @@ const initialState = {
37
38
} ,
38
39
} ;
39
40
41
+ const mountSnapshotAccess = ( userGroups : Array < ManagedGroupMembershipEntry > ) => {
42
+ const state = {
43
+ ...initialState ,
44
+ user : {
45
+ userGroups,
46
+ } ,
47
+ } ;
48
+
49
+ const mockStore = createMockStore ( [ ] ) ;
50
+ const store = mockStore ( state ) ;
51
+
52
+ cy . intercept ( 'GET' , 'https://sam.dsde-dev.broadinstitute.org/api/groups/v1' ) . as ( 'getUserGroups' ) ;
53
+
54
+ mount (
55
+ < Router history = { history } >
56
+ < Provider store = { store } >
57
+ < ThemeProvider theme = { globalTheme } >
58
+ < SnapshotAccess />
59
+ </ ThemeProvider >
60
+ </ Provider >
61
+ </ Router > ,
62
+ ) ;
63
+ } ;
64
+
40
65
describe ( 'Snapshot access info' , ( ) => {
41
- beforeEach ( ( ) => {
42
- const mockStore = createMockStore ( [ ] ) ;
43
- const store = mockStore ( initialState ) ;
44
- mount (
45
- < Router history = { history } >
46
- < Provider store = { store } >
47
- < ThemeProvider theme = { globalTheme } >
48
- < SnapshotAccess />
49
- </ ThemeProvider >
50
- </ Provider >
51
- </ Router > ,
52
- ) ;
53
- } ) ;
54
66
it ( 'Displays snapshot policies and emails' , ( ) => {
67
+ mountSnapshotAccess ( [ ] ) ;
68
+
55
69
cy . get ( '[data-cy="snapshot-stewards"]' )
56
70
. should ( 'contain.text' , 'Stewards' )
57
71
. within ( ( ) => {
@@ -81,4 +95,46 @@ describe('Snapshot access info', () => {
81
95
} ) ;
82
96
} ) ;
83
97
} ) ;
98
+
99
+ it ( 'Displays authorization domain section' , ( ) => {
100
+ mountSnapshotAccess ( [ ] ) ;
101
+
102
+ cy . get ( 'label[for="authorization-domain"]' )
103
+ . should ( 'contain.text' , 'Authorization Domain' )
104
+ . should ( 'contain.text' , '(optional)' ) ;
105
+ } ) ;
106
+
107
+ it ( 'Shows authorization domain dropdown with options when user groups exist' , ( ) => {
108
+ const userGroups = [
109
+ { groupEmail : 'email1' , groupName : 'group1' , role : 'READER' } ,
110
+ { groupEmail : 'email2' , groupName : 'group2' , role : 'READER' } ,
111
+ ] ;
112
+ mountSnapshotAccess ( userGroups ) ;
113
+
114
+ cy . get ( '#authorization-domain-select' )
115
+ . should ( 'exist' )
116
+ . should ( 'not.be.disabled' )
117
+ . should ( 'have.value' , '' ) ;
118
+
119
+ cy . get ( '#authorization-domain-select' ) . parent ( ) . click ( ) ;
120
+ cy . get ( '[data-cy^=menuItem]' ) . should ( 'have.length' , userGroups . length ) ;
121
+ } ) ;
122
+
123
+ it ( 'Select an authorization domain when user groups exist' , ( ) => {
124
+ const userGroups = [
125
+ { groupEmail : 'email1' , groupName : 'group1' , role : 'READER' } ,
126
+ { groupEmail : 'email2' , groupName : 'group2' , role : 'READER' } ,
127
+ ] ;
128
+ mountSnapshotAccess ( userGroups ) ;
129
+
130
+ cy . get ( '#authorization-domain-select' ) . parent ( ) . click ( ) ;
131
+ cy . get ( '[data-cy=menuItem-group2]' ) . click ( ) ;
132
+ cy . get ( '#authorization-domain-select' ) . should ( 'have.value' , 'group2' ) ;
133
+ } ) ;
134
+
135
+ it ( 'Disables authorization domain dropdown when insufficient user groups' , ( ) => {
136
+ const userGroups = [ { groupEmail : 'default' , groupName : 'default' , role : 'READER' } ] ;
137
+ mountSnapshotAccess ( userGroups ) ;
138
+ cy . get ( '#authorization-domain-select' ) . should ( 'be.disabled' ) ;
139
+ } ) ;
84
140
} ) ;
0 commit comments